Skip to content

eduardo2580/SnakeInPython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Snake Game

A classic Snake game built with Pygame where you control a snake to eat apples and grow while avoiding collisions with the walls and yourself.

📋 Features

  • Smooth snake movement with arrow key controls
  • Score tracking and high score saving
  • Pause functionality
  • Game over screen with restart option
  • Visual grid system for clear gameplay
  • Colorful graphics with rounded snake segments

🎮 How to Play

  1. Controls:

    • Arrow Keys: Control the snake's direction
    • P: Pause/unpause the game
    • Space: Restart after game over
  2. Objective:

    • Eat the red apples to grow your snake and increase your score
    • Avoid hitting the walls or your own body
    • Try to beat your high score!

🛠️ Requirements

  • Python 3.x
  • Pygame library

⚙️ Installation

  1. Clone this repository or download the source code.
  2. Make sure you have Python installed on your system.
  3. Install the Pygame library:
    pip install pygame
  4. Run the game:
    python snake_game.py

🏗️ Game Structure

The game is built with the following components:

  • Snake Class: Manages the snake's body, movement, and collision detection
  • Apple Class: Handles the apple's position and rendering
  • Game Loop: Controls the flow of the game, including input handling and state management
  • Score System: Tracks current score and maintains a high score saved to a file

🧩 Code Overview

Snake Class

The Snake class manages the player-controlled snake, including:

  • Updating the snake's position
  • Growing when an apple is eaten
  • Detecting collisions with itself and the game boundaries
  • Rendering the snake on the screen

Apple Class

The Apple class handles:

  • Spawning apples in random positions (never on the snake)
  • Rendering the apple as a red circle

Game State Management

The game includes multiple states:

  • Active gameplay
  • Paused state
  • Game over state with score display

Score System

  • Current score is displayed during gameplay
  • High score is saved to a file and loaded when the game starts
  • New high scores are celebrated with a special message

📝 License

This project is licensed under the MIT License - see the license section below for details.

📄 MIT License

MIT License

Copyright (c) 2024 Eduardo Souza Rodrigues

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues page.

About

A simple snake game in English, written in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages