diff options
Diffstat (limited to 'snake.py')
| -rwxr-xr-x | snake.py | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 |
