()
| 167 | |
| 168 | # --- MAIN GAME LOOP --- |
| 169 | def game_loop(): |
| 170 | global game_state |
| 171 | if game_state == "playing": |
| 172 | snake.move() |
| 173 | # Collision with food |
| 174 | if snake.head.distance(food) < 20: |
| 175 | food.refresh(LEFT_WALL, RIGHT_WALL, BOTTOM_WALL, TOP_WALL) |
| 176 | snake.extend() |
| 177 | scoreboard.increase_score() |
| 178 | # Collision with wall |
| 179 | if not (LEFT_WALL < snake.head.xcor() < RIGHT_WALL and BOTTOM_WALL < snake.head.ycor() < TOP_WALL): |
| 180 | game_state = "game_over" |
| 181 | scoreboard.game_over() |
| 182 | # Collision with tail |
| 183 | for segment in snake.segments[1:]: |
| 184 | if snake.head.distance(segment) < 10: |
| 185 | game_state = "game_over" |
| 186 | scoreboard.game_over() |
| 187 | manage_buttons() |
| 188 | screen.update() |
| 189 | screen.ontimer(game_loop, MOVE_DELAY_MS) |
| 190 | |
| 191 | # --- INITIALIZE GAME --- |
| 192 | scoreboard.display_start_message() |
no test coverage detected