▶️ Section 09: Final Run & Extension

Full Code Review

This section shows the complete project code so students can compare their final build to the full reference implementation and clear up any misunderstandings.

Review each file carefully and confirm your code structure, method names, and logic order match.

settings.py

Code image: s09-code01

utils.py

Code image: s09-code02

snake.py

Code image: s09-code03

food.py

Code image: s09-code04

game.py

Code image: s09-code05

main.py

Code image: s09-code06

Extensions

To earn full points, copy your final project code into a new file named Mainfile.Ext.py and complete at least one extension.

If no extension is completed, the highest possible score is B (2.5/4).

You may complete one of the options below or propose your own idea. If you create your own, verify it with your teacher first.

  1. Add a Start Screen and Instructions Build a start menu screen before gameplay begins, including controls and a "Press Any Key to Start" prompt.
  2. Add a High Score System Track the highest score during the session, and optionally save/load it from a file so it persists between runs.
  3. Add Difficulty Levels Let players choose Easy/Medium/Hard and adjust SNAKE_TPS (and optionally board size) based on the selected difficulty.
  4. Add Obstacles Place wall blocks on the board and end the game when the snake collides with them.
  5. Add Special Food Types Create bonus food (extra points) or timed food that disappears after a short duration.
  6. Add Visual Polish Improve visuals with a checkerboard background, animated snake head, smoother food style, and improved game-over overlay text.

Core Concepts List

By the end of this project, students should understand and be able to apply:

  • Project organization across multiple modules (settings, utils, snake, food, game, main).
  • OOP fundamentals: classes, objects, encapsulation, composition, and class responsibilities.
  • Shared constants and configuration-driven behavior in settings.py.
  • Utility functions and pure-function design for reusable grid logic.
  • Efficient data structures (deque, set, tuples, dictionaries) for game programming.
  • Direction vectors and grid-based movement rules.
  • Growth, wall collision, and self-collision logic in the Snake class.
  • Food spawn/respawn rules that avoid occupied cells.
  • Event-driven programming with Pygame (QUIT, KEYDOWN, custom timer events).
  • State machine flow: playing, paused, and gameover.
  • Ordered gameplay logic in step_snake (move -> lose checks -> eat checks).
  • Rendering flow and helper methods for drawing grid, snake, food, UI, and overlays.
  • Clean entry-point design using main() and if __name__ == "__main__":.
  • Incremental development and verification through section-based testing.