diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-11-01 15:09:08 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-11-01 15:09:08 +0100 |
| commit | 4f113282d7a709790854f8194b6c9c77f2f164b3 (patch) | |
| tree | a2b3723e5304a396aa399290a9abd90d7fd6b10e /snake.py | |
| parent | a417a3054c1ce54a5ff2866848797c1610f2202d (diff) | |
Minor changes
Diffstat (limited to 'snake.py')
| -rwxr-xr-x | snake.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -124,6 +124,7 @@ class Snake: clock = pygame.time.Clock() ignore_has_loose=True self.new_game() + event=0 # 0 is nothing, 1 is eat an apple and -1 loose while True: self.screen.fill((0,0,0)) self.draw_snake() @@ -131,6 +132,7 @@ class Snake: self.draw_infos() # Check for loose if not(ignore_has_loose) and self.has_loose(): + event_handler(self,-1) break else: ignore_has_loose=False @@ -154,14 +156,26 @@ class Snake: break # Check if an event handler is available if event_handler!=None: - event_handler(self) + event_handler(self,event) + event=0 self.move() # Check for eating apple if self.apple==self.snake[0]: self.snake.append(self.snake[len(self.snake)-1]) self.new_apple() self.score+=1 + event=1 pygame.display.flip() clock.tick(self.fps) return(self.score) + +game=Snake() + +def event_handler(game): + if game.snake[0][0]==10: + game.direction=6 + +for i in range(0,10): + score=game.run() + print("Game ended with "+str(score))
\ No newline at end of file |
