diff --git a/snake.py b/snake.py index 14fd8c97..e59fb666 100644 --- a/snake.py +++ b/snake.py @@ -7,11 +7,9 @@ width = 500 height = 500 - cols = 25 rows = 20 - class cube(): rows = 20 w = 500 @@ -21,6 +19,7 @@ def __init__(self, start, dirnx=1, dirny=0, color=(255,0,0)): self.dirny = dirny # "L", "R", "U", "D" self.color = color + def move(self, dirnx, dirny): self.dirnx = dirnx self.dirny = dirny @@ -42,11 +41,11 @@ def draw(self, surface, eyes=False): pygame.draw.circle(surface, (0,0,0), circleMiddle2, radius) - class snake(): body = [] turns = {} + def __init__(self, color, pos): #pos is given as coordinates on the grid ex (1,5) self.color = color @@ -55,6 +54,7 @@ def __init__(self, color, pos): self.dirnx = 0 self.dirny = 1 + def move(self): for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -98,6 +98,7 @@ def reset(self,pos): self.dirnx = 0 self.dirny = 1 + def addCube(self): tail = self.body[-1] dx, dy = tail.dirnx, tail.dirny @@ -114,6 +115,7 @@ def addCube(self): self.body[-1].dirnx = dx self.body[-1].dirny = dy + def draw(self, surface): for i,c in enumerate(self.body): if i == 0: @@ -133,7 +135,6 @@ def redrawWindow(): pass - def drawGrid(w, rows, surface): sizeBtwn = w // rows @@ -147,7 +148,6 @@ def drawGrid(w, rows, surface): pygame.draw.line(surface, (255,255,255), (0, y),(w,y)) - def randomSnack(rows, item): positions = item.body @@ -192,7 +192,8 @@ def main(): redrawWindow() -main() +if __name__=='__main__': + main()