Activity Stream
93,161 MEMBERS
104 ONLINE
Snake Game Broken Snake Game Broken Snake Game Broken Snake Game Broken Snake Game Broken
Results 1 to 2 of 2
  1.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #1
    Programmar
    Xcode's Avatar

    New Snake Game Broken

    Snake game, appears to be broken since addition of random module related things.


    Source Code : 
        #! /usr/bin/env python
         
        
    import pygamerandom
         
        width 
    640
        height 
    400
        color 
    = (00255)
        
    color1 = (25500)
        
    screen pygame.display.set_mode((widthheight))
        
    clock pygame.time.Clock()
        
    running True
        running1 
    True
        keyset 
    = ['pygame.K_UP''pygame.K_DOWN''pygame.K_LEFT''pygame.K_RIGHT']
        
    keyset1 = ['pygame.K_w''pygame.K_s''pygame.K_a''pygame.K_d']
         
        class 
    Worm:
        
    """ A worm. """
         
        
    def __init__(selfsurfacexylengthcolorkeyset):
        
    self.surface surface
        self
    .x
        self
    .y
        self
    .length length
        self
    .dir_x 0
        self
    .dir_y = -1
        self
    .body = []
        
    self.crashed False
        self
    .color color
        self
    .keyset keyset
         
        def key_event
    (selfevent):
        
    """ Handle key events that affect the worm. """
        
    if event.key == eval(self.keyset[0]):
        
    self.dir_x 0
        self
    .dir_y = -1
        elif event
    .key == eval(self.keyset[1]):
        
    self.dir_x 0
        self
    .dir_y 1
        elif event
    .key == eval(self.keyset[2]):
        
    self.dir_x = -1
        self
    .dir_y 0
        elif event
    .key == eval(self.keyset[3]):
        
    self.dir_x 1
        self
    .dir_y 0
         
        def move
    (self):
        
    """ Move the mouse. """
        
    self.+= self.dir_x
        self
    .+= self.dir_y
         
        r
    gbself.surface.get_at((self.xself.y))
        if (
    rgb) != (000):
        
    self.crashed True
         
        self
    .body.insert(0, (self.xself.y))
         
        if 
    len(self.body) > self.length:
        
    self.body.pop()
         
        
    def draw(self):
        for 
    xy in self.body:
        
    self.surface.set_at((xy), self.color)
         
         
        
    randlsx = []
        
    randlsy = []
        
    ralmx 0
        ralmy 
    0
        
    while ralmx 50:
        
    obx random.randint(0width-1)
        
    randlsx.append(obx)
        
    ralmx 1
         
        
    while ralmy 50:
        
    oby random.randint(0height-1)
        
    randlsy.append(oby)
        
    ralmy 1
         
        
    print len(randlsx)
        
    # The Worm
         
        
    Worm(screenwidth/2height/2200colorkeyset)
        
    w1 Worm(screenwidth/2height/2200color1keyset1)

    [Login or Register to remove this advertisement]

         
        while 
    running or running1:
        
    screen.fill((000))
         
        for 
    i in range(50):
        
    screen.set_at((randlsx[i], randlsy[i]), (255255255))
         
        
    w.draw()
        
    w1.draw()
        
    w.move()
        
    w1.move()
         
        for 
    q in range(20):
        
    screen.set_at((obsxobsy), (255255255))
         
        if 
    w.crashed or w.<= or w.>= width-or w.>= height-1:
        
    Worm(screenwidth/2height/20, (000), keyset)
        
    running False
         
        
    if w1.crashed or w1.>= width-or w1.<= or w1.>= height-1:
        
    w1 Worm(screenwidth/2height/20, (000), keyset1)
        
    running1 False
         
        
    for event in pygame.event.get():
        if 
    event.type == pygame.QUIT:
        
    running False
        elif event
    .type == pygame.KEYDOWN:
        
    w.key_event(event)
        
    w1.key_event(event)
         
        
    pygame.display.flip()
        
    clock.tick(200)
         
        
    pygame.quit() 
    Xcode Reviewed by Xcode on . Snake Game Broken Snake game, appears to be broken since addition of random module related things. #! /usr/bin/env python import pygame, random width = 640 height = 400 color = (0, 0, 255) Rating: 5

  2. The Following 1 Users Say Thank You to Xcode For This Useful Post:
    [ Click to Expand ]

    Rebel (10th March 2012)

  3.   Advertisements

  4.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #2
    for me you have not declared a random function, as it should be.
    that gives you the error if you leave it like that?
    If you remove random thing happens.

Thread Information

Users Browsing this Thread

There Are Currently 1 Users Browsing This Thread. (0 Members and 1 Guests)

Similar Threads

  1. Did you know you can actually beat Snake game ?
    By whateverfor in forum Fun Stuff
    Replies: 0
    Last Post: 8th August 2013, 09:26 PM
  2. Classic Snake Game with HTML5 Canvas
    By Mobile_Guru in forum CSS
    Replies: 3
    Last Post: 19th July 2012, 01:04 AM
  3. Replies: 0
    Last Post: 24th November 2011, 06:45 PM
  4. Snake war - i
    By Xcode in forum C/C++
    Replies: 0
    Last Post: 24th November 2011, 06:37 PM
  5. Snake And Ladder
    By Xcode in forum C/C++
    Replies: 0
    Last Post: 24th November 2011, 06:28 PM

Tags for this Thread

BE SOCIAL
Snake Game Broken Snake Game Broken Snake Game Broken Snake Game Broken Snake Game Broken