From 65280331d3b2b3d32375df783ab89f30706e17da Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 2 Nov 2022 10:29:11 +0100 Subject: Minor changes --- snake.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'snake.py') diff --git a/snake.py b/snake.py index a37fdf6..7526731 100755 --- a/snake.py +++ b/snake.py @@ -18,6 +18,7 @@ class Snake: self.fps=fps self.startat=startat self.last_score=-1 + self.score=0 # Setup pygame pygame.init() self.font=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2)) @@ -35,6 +36,7 @@ class Snake: self.snake=[self.startat]*self.default_length self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left) self.new_apple() + self.last_score=self.score self.score=0 self.attempt+=1 @@ -134,7 +136,11 @@ class Snake: Play using wall clock directions (12=up, 3=right, 6=down and 9=left) """ # Play - self.direction=direction + if (self.direction==12 and direction!=6) or\ + (self.direction==6 and direction!=12) or\ + (self.direction==3 and direction!=9) or\ + (self.direction==9 and direction!=3): + self.direction=direction self.move() # Return code code=0 @@ -144,7 +150,6 @@ class Snake: self.score+=1 code=1 elif self.has_loose(): - self.last_score=self.score self.new_game() code=-1 # Refresh screen -- cgit v1.2.3