A classic 2D Snake game implemented in Python using the Pygame library, designed with domain-driven principles for readability and maintainability.
- Simple start screen to begin the game
- Snake moves continuously in four cardinal directions (Up, Down, Left, Right)
- Single food item appears randomly on the grid-based board
- Snake grows by one segment when food is consumed
- Real-time display of the player's current score
- Responsive UI adapts to different screen sizes (desktop and mobile)
- Arrow keys for direction control
- Game ends if the snake's head hits the board boundaries or its own body
- "Game Over" screen displays final score and restart option
- Python 3.12 or higher
- Pygame
Install dependencies:
pip install -r requirements.txtTo start the game, use the provided batch script:
run.batTo run all unit tests:
test.batdomain.py— Core domain logic (snake, food, grid, etc.)game.py— Game loop and state managementdrawing.py— Rendering and UIinput.py— Input handlingmain.py— Entry pointtests/— Unit tests for domain, drawing, and game logicrun.bat— Launches the gametest.bat— Runs all tests
- Arrow keys: Change snake direction
This project is for educational purposes.