Executes one step through the game.
(self)
| 72 | self.snake.direction = Direction.DOWN |
| 73 | |
| 74 | def play_step(self): |
| 75 | """Executes one step through the game.""" |
| 76 | self.get_user_input() |
| 77 | self.snake.move(self.snake.direction) |
| 78 | if self.snake.head == self.food: |
| 79 | self.score += 1 |
| 80 | self.place_food() |
| 81 | else: |
| 82 | self.snake.blocks.pop() |
| 83 | # Update UI and Clock |
| 84 | self.display.update_ui(self.snake, self.food, self.score, self.high_score) |
| 85 | self.display.clock.tick(GameSettings.SPEED) |
| 86 | game_over = self.is_collision() |
| 87 | return game_over, self.score |
| 88 | |
| 89 | def place_food(self): |
| 90 | """Randomly places the food on the screen.""" |