summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-11-01 09:23:24 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-11-01 09:23:24 +0100
commit368bf244a8aae9f4b3256ce3515305a344b983c8 (patch)
treea324aed41a28bcb5b728758858b78dd62fcf5ed5
parent73bd3decdc23d734c72e9c4ef3930cb7cbc91404 (diff)
Minor changes
-rwxr-xr-xsnake/snake.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/snake/snake.py b/snake/snake.py
index b8c5619..00cc261 100755
--- a/snake/snake.py
+++ b/snake/snake.py
@@ -9,16 +9,21 @@ class Snake:
self.grid_height=grid_height
self.grid_pts=grid_pts
self.margin=margin
- self.fps=fps
- self.snake=[(0,0)]*length
- self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
- self.new_apple()
+ self.default_length=length
self.attempt=0
+ self.fps=fps
pygame.init()
self.font=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2))
self.font_small=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2.5))
self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts+margin))
+ def new_game(self):
+ self.snake=[(0,0)]*self.default_length
+ self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
+ self.new_apple()
+ self.score=0
+ self.attempt+=1
+
def draw_pts(self,x,y,color=(255,255,255)):
rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y+self.margin, self.grid_pts, self.grid_pts)
pygame.draw.rect(self.screen,color,rect, 0)
@@ -73,10 +78,8 @@ class Snake:
def run(self):
clock = pygame.time.Clock()
- self.direction=6
ignore_has_loose=True
- self.score=0
- self.attempt+=1
+ self.new_game()
while True:
self.screen.fill((0,0,0))
self.draw_snake()
@@ -116,4 +119,5 @@ class Snake:
game=Snake()
-game.run()
+for i in range(0,10):
+ game.run() \ No newline at end of file