diff options
| -rwxr-xr-x | snake/snake.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/snake/snake.py b/snake/snake.py index 851c55a..14b0ea0 100755 --- a/snake/snake.py +++ b/snake/snake.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import sys, pygame +import sys, pygame, random class Snake: @@ -18,6 +18,12 @@ class Snake: rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y, self.grid_pts, self.grid_pts) pygame.draw.rect(self.screen,color,rect, 0) + + def new_apple(self): + self.apple=(random.randint(0,grid_width),random.randint(0,grid_height)) + while self.apple in self.snake: + self.apple=(random.randint(0,grid_width),random.randint(0,grid_height)) + def move(self): # Update tail if len(self.snake)>1: |
