summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-10-31 22:12:02 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-10-31 22:12:02 +0100
commitaa38f15005bb2390edd08613dc68f373fb3447ca (patch)
treee66f50a52b6ff170466f1ba4982b92c3d30b2bcb
parentcee495b6007f369ef9f384e2b7c073e5f6a9743e (diff)
Minor changes
-rwxr-xr-xsnake/snake.py8
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: