From 4f113282d7a709790854f8194b6c9c77f2f164b3 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 1 Nov 2022 15:09:08 +0100 Subject: Minor changes --- snake.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'snake.py') diff --git a/snake.py b/snake.py index e5db997..0597808 100755 --- a/snake.py +++ b/snake.py @@ -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 -- cgit v1.2.3