A feature-rich Python snake game built with Pygame, featuring multiple difficulty levels, persistent high scores, pause functionality, and modern UI.
- 4 Difficulty Levels: Easy, Medium, Hard, and Extreme modes with increasing speeds
- Pause/Resume: Press
Pto pause and resume the game anytime - High Score Tracking: Persistent high scores saved to
highscore.json - Dynamic Difficulty: Speed increases every 5 points collected
- Collision Detection: Both wall collision and self-collision detection
- State Management: Complete game state system (Menu, Difficulty Selection, Playing, Paused, Game Over)
- Larger Window: 800x600 resolution for better visibility
- Color-Coded Difficulty: Each difficulty level has a unique color
- Easy: Green
- Medium: Yellow
- Hard: Red
- Extreme: Magenta
- Modern UI: Professional menu screens and game over screens
- Visual Feedback: Borders around snake segments and food for better clarity
Main Menu:
S- Start GameQ- Quit
Difficulty Selection:
1- Easy Mode2- Medium Mode (Default)3- Hard Mode4- Extreme ModeQ- Back to Menu
During Gameplay:
โ- Move Upโ- Move Downโ- Move Leftโ- Move RightP- Pause/ResumeQ- Quit to Menu
Game Over Screen:
ENTER- Replay (go to difficulty selection)M- Return to Main MenuQ- Quit Game
- Python 3.7+
- Pygame
- Clone the repository:
git clone https://github.com/yourusername/Snake_Game_with_Python.git
cd Snake_Game_with_Python- Install dependencies:
pip install pygame- Run the game:
python main.py- Each food item collected = 10 points
- Score increases with each level
- High scores are automatically saved and persisted
| Difficulty | Speed | Description |
|---|---|---|
| Easy | 4 FPS | Perfect for beginners |
| Medium | 8 FPS | Balanced gameplay |
| Hard | 12 FPS | Challenging |
| Extreme | 16 FPS | For experienced players |
- Starting speed depends on selected difficulty
- Speed increases by 1 FPS every 5 points collected
- Maximum speed capped at 20 FPS
- MENU: Main menu screen
- DIFFICULTY: Difficulty selection screen
- PLAYING: Active gameplay
- PAUSED: Game paused state
- GAME_OVER: End game screenHighScoreManager
- Manages loading and saving high scores
- Stores data in JSON format for persistence
GameState (Enum)
- Defines all possible game states
Difficulty (Enum)
- Defines difficulty levels with associated settings
Snake_Game_with_Python/
โโโ main.py # Main game file
โโโ highscore.json # High score persistence (auto-generated)
โโโ README.md # This file
โโโ requirements.txt # Python dependencies
โโโ LICENSE # MIT License
- Object-Oriented Design: Uses classes for game components
- State Pattern: Proper game state management
- Separation of Concerns: Rendering, game logic, and data persistence are separate
- Documentation: Comprehensive docstrings for all functions and classes
- Error Handling: Graceful error handling in high score management
Potential features for future versions:
- Sound effects and background music
- Power-ups (speed boost, temporary invincibility)
- Obstacles/barriers on the map
- Multiplayer support
- Leaderboard system
- Customizable snake colors
- Different food types with different point values
- Game statistics (games played, average score)
- Achievements/Badges system
- Plan Ahead: Try to anticipate the snake's movement
- Avoid Walls: Getting too close to edges is risky
- Don't Trap Yourself: Avoid creating enclosed spaces
- Practice Easy Mode: Master the mechanics before trying higher difficulties
- Use Pause: Take a moment to plan your next moves
- Optimized rendering for smooth gameplay
- Efficient collision detection
- Low memory footprint
- Runs smoothly on most systems
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
Created with โค๏ธ using Python and Pygame
If you encounter any issues:
- Ensure Pygame is properly installed:
pip install pygame --upgrade - Verify Python version is 3.7 or higher:
python --version - Check that
main.pyis in the correct directory - Review the error messages for specific guidance
Enjoy the game! ๐ฎ