A classic Snake game built with Python and Pygame.
- Python 3.8 or higher
- uv package manager
If you don't have uv installed, install it using one of these methods:
macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | shWindows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Using pip:
pip install uvUse uv to automatically create a virtual environment and install dependencies:
uv run snake_game.pyThis command will:
- Create a virtual environment (if needed)
- Install all dependencies from
requirements.txt - Run the game
-
Create a virtual environment and install dependencies:
uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -r requirements.txt
-
Run the game:
python snake_game.py
If you want to manage this as a proper project:
-
Initialize a project (creates pyproject.toml):
uv init --name snake-game
-
Add dependencies:
uv add pygame
-
Run the game:
uv run snake_game.py
-
Movement Controls:
- Arrow keys or WASD to move the snake
- UP/W: Move up
- DOWN/S: Move down
- LEFT/A: Move left
- RIGHT/D: Move right
-
Objective: Eat the red food items to grow your snake and increase your score
-
Game Over: The game ends if you hit a wall or run into yourself
-
After Game Over:
- Press 'R' to restart
- Press 'Q' to quit
- Score tracking
- High score persistence (saved to
highscore.txt) - Increasing difficulty (speed increases as snake grows)
- Collision detection for walls and self
- Clean, grid-based movement
Issue: pygame not found
uv pip install pygame --break-system-packagesIssue: Display not working on Linux
You may need to install SDL dependencies:
sudo apt-get install python3-pygame
# or
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-devIssue: uv command not found
Make sure uv is in your PATH. After installation, you may need to restart your terminal or run:
source ~/.cargo/env # On macOS/Linux.
├── snake_game.py # Main game file
├── requirements.txt # Python dependencies
├── highscore.txt # High score storage (created on first run)
├── LICENSE # MIT License
└── README.md # This file
This project is licensed under the MIT License - see the LICENSE file for details.
Author: Gourav Shah, School of Devops