Skip to content

sghoshm/Snake_Game_with_Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Advanced Snake Game

A feature-rich Python snake game built with Pygame, featuring multiple difficulty levels, persistent high scores, pause functionality, and modern UI.

Features

๐ŸŽฎ Gameplay Features

  • 4 Difficulty Levels: Easy, Medium, Hard, and Extreme modes with increasing speeds
  • Pause/Resume: Press P to 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)

๐ŸŽจ Visual Enhancements

  • 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

โŒจ๏ธ Controls

Main Menu:

  • S - Start Game
  • Q - Quit

Difficulty Selection:

  • 1 - Easy Mode
  • 2 - Medium Mode (Default)
  • 3 - Hard Mode
  • 4 - Extreme Mode
  • Q - Back to Menu

During Gameplay:

  • โ†‘ - Move Up
  • โ†“ - Move Down
  • โ† - Move Left
  • โ†’ - Move Right
  • P - Pause/Resume
  • Q - Quit to Menu

Game Over Screen:

  • ENTER - Replay (go to difficulty selection)
  • M - Return to Main Menu
  • Q - Quit Game

Installation

Requirements

  • Python 3.7+
  • Pygame

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/Snake_Game_with_Python.git
cd Snake_Game_with_Python
  1. Install dependencies:
pip install pygame
  1. Run the game:
python main.py

Game Mechanics

Scoring System

  • Each food item collected = 10 points
  • Score increases with each level
  • High scores are automatically saved and persisted

Difficulty Levels

Difficulty Speed Description
Easy 4 FPS Perfect for beginners
Medium 8 FPS Balanced gameplay
Hard 12 FPS Challenging
Extreme 16 FPS For experienced players

Progressive Difficulty

  • Starting speed depends on selected difficulty
  • Speed increases by 1 FPS every 5 points collected
  • Maximum speed capped at 20 FPS

Architecture

Key Components

Game States

- MENU: Main menu screen
- DIFFICULTY: Difficulty selection screen
- PLAYING: Active gameplay
- PAUSED: Game paused state
- GAME_OVER: End game screen

Classes

HighScoreManager

  • 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

File Structure

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

Code Quality

Features Implemented

  • 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

Future Enhancements

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

Gameplay Tips

  1. Plan Ahead: Try to anticipate the snake's movement
  2. Avoid Walls: Getting too close to edges is risky
  3. Don't Trap Yourself: Avoid creating enclosed spaces
  4. Practice Easy Mode: Master the mechanics before trying higher difficulties
  5. Use Pause: Take a moment to plan your next moves

Performance

  • Optimized rendering for smooth gameplay
  • Efficient collision detection
  • Low memory footprint
  • Runs smoothly on most systems

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

Author

Created with โค๏ธ using Python and Pygame

Support

If you encounter any issues:

  1. Ensure Pygame is properly installed: pip install pygame --upgrade
  2. Verify Python version is 3.7 or higher: python --version
  3. Check that main.py is in the correct directory
  4. Review the error messages for specific guidance

Enjoy the game! ๐ŸŽฎ

About

Game made with PyCharm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages