MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / play_step

Method play_step

projects/Snake Game/src/game.py:74–87  ·  view source on GitHub ↗

Executes one step through the game.

(self)

Source from the content-addressed store, hash-verified

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."""

Callers 2

game_loopMethod · 0.95
test_play_stepMethod · 0.80

Calls 6

get_user_inputMethod · 0.95
place_foodMethod · 0.95
is_collisionMethod · 0.95
update_uiMethod · 0.80
moveMethod · 0.45
tickMethod · 0.45

Tested by 1

test_play_stepMethod · 0.64