Skip to content

A simple yet engaging implementation of the classic Snake game, built using Python and the Pygame library. Guide the snake to eat food, grow longer, and avoid collisions with the walls or its own body!

Notifications You must be signed in to change notification settings

Atamyrat2005/snake-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Classic Snake Game in Pygame

snake3-500x500

A simple yet engaging implementation of the classic Snake game, built using Python and the Pygame library. Guide the snake to eat food, grow longer, and avoid collisions with the walls or its own body!

✨ Features

  • Classic Gameplay: The timeless snake mechanics you know and love.
  • Score Tracking: Keep track of your score as you consume food.
  • Increasing Difficulty: The snake grows longer, making navigation more challenging.
  • Simple Controls: Easy-to-learn controls using arrow keys.
  • Game Over Detection: The game ends upon collision with boundaries or the snake's own tail.

🛠️ Prerequisites

Before you begin, ensure you have the following installed:

  • Python 3: (Preferably Python 3.7 or newer)
  • Pygame: The core library for graphics and game logic.
    • Install it via pip:
      pip install pygame

🚀 Getting Started

  1. Clone the Repository:

    git clone https://github.com/Atamyrat2005/snake-game.git
    cd snake-game
  2. Install Dependencies (if you create a requirements.txt): While Pygame is the primary dependency, if you add more, list them in a requirements.txt file. For now, Pygame is the main one.

    # requirements.txt
    pygame
    

    Then users could run:

    pip install -r requirements.txt

    (For this project, pip install pygame as mentioned in Prerequisites is sufficient if Pygame is the only dependency).

  3. Run the Game: Execute the main Python script:

    python snake_game.py

🎮 How to Play

  • Use the Arrow Keys (Up, Down, Left, Right) to control the direction of the snake.
  • The objective is to eat the red food blocks that appear randomly on the screen.
  • Each piece of food consumed increases your score and the length of the snake.
  • Avoid colliding with the edges of the game window or the snake's own body.
  • The game ends if a collision occurs, and your final score will be displayed.

📂 File Structure

snake-game/
├── .gitignore         # Specifies intentionally untracked files that Git should ignore
├── LICENSE            # The MIT License file for the project
├── README.md          # This readme file
└── snake_game.py      # The main Python script containing all the game logic

🔧 Code Overview (snake_game.py)

  • Initialization: Sets up the Pygame window, colors, game speed, and initial snake/food positions.
  • Game Objects:
    • snake_position, snake_body: Manage the snake's coordinates and segments.
    • food_pos, food_spawn: Handle food placement and respawning.
  • Core Game Logic:
    • Event handling for keyboard inputs (arrow keys).
    • Updating snake's direction and position.
    • Checking for food consumption and growing the snake.
    • Collision detection (with walls and self).
  • Display Functions:
    • show_score(): Renders the current score on the screen.
    • game_over(): Displays the game over message and final score.
  • Main Game Loop: Continuously processes events, updates game state, and redraws the screen.

💡 Potential Future Enhancements

  • Add different difficulty levels (e.g., affecting snake speed).
  • Implement a high score saving/loading system.
  • Add sound effects for eating food or game over.
  • Introduce power-ups or obstacles.
  • Improve visual aesthetics (e.g., custom sprites for snake and food).

🤝 Contributing

Contributions are welcome! If you have ideas for improvements or bug fixes, feel free to:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

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


Made by Atamyrat2005. Enjoy the game!


**Key things I added/emphasized:**

1.  **Catchy Title and Placeholder for Visuals:** A GIF or screenshot is crucial for a game.
2.  **Features Section:** Highlights what the game offers.
3.  **Prerequisites:** Clear instructions on what's needed.
4.  **Getting Started:** Step-by-step setup and run instructions.
5.  **How to Play:** Essential for any game.
6.  **File Structure:** Helps others understand the project layout.
7.  **Code Overview:** A brief explanation of how `snake_game.py` is structured. This is helpful for anyone looking to understand or modify the code.
8.  **Potential Future Enhancements:** Shows vision and encourages contributions.
9.  **Contributing Section:** Standard for open-source projects.
10. **License Section:** Points to your existing `LICENSE` file.
11. **Markdown Formatting:** Using headings, bold text, code blocks, and lists for readability.
12. **Emojis:** Add a bit of visual flair.

**To make this even better, you should:**

1.  **Add a GIF or Screenshot:** This is the most important visual improvement. Replace `https://via.placeholder.com/600x400.png?text=Add+a+GIF+or+Screenshot+of+your+Game+Here!` with an actual image or GIF.
2.  **(Optional) Create `requirements.txt`:** If you plan to add more Python dependencies later, it's good practice. For now, it's simple enough without it.

Copy and paste this content into your `README.md` file in the repository!

About

A simple yet engaging implementation of the classic Snake game, built using Python and the Pygame library. Guide the snake to eat food, grow longer, and avoid collisions with the walls or its own body!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages