A classic implementation of the Snake game built from scratch using Python and the built-in turtle module.
This project is written using object-oriented programming (OOP), splitting the game's logic into separate classes for the Snake, the Food, and the Scorecard.
- Classic Gameplay: Control the snake to eat the food and grow longer.
- OOP Design: The code is cleanly organized into four classes:
Snake: Manages the snake's body, movement, and controls.Food: Manages the food's appearance and random placement.Scorecard: Manages score tracking and displays the "Game Over" message.main: Handles the main game loop, screen setup, and collision detection.
- Collision Detection: The game ends if the snake hits a wall or its own tail.
- Responsive Controls: The controls are designed to prevent the snake from turning 180 degrees back onto itself in a single move.
- Clean UI: Features a simple, dark-themed background.
- Language: Python
- Core Libraries:
turtle(for graphics),random(for food),time(for game speed)
If you have Python installed on your computer and want to run the code yourself:
- Clone the repository:
git clone [https://github.com/Spargerx/Snake_Game.git](https://github.com/Spargerx/Snake_Game.git)
- Navigate to the project directory:
cd Snake_Game - Run the game!
(Note: You may need to use
python main.py
python3 main.pyon macOS or Linux)
- Up:
Up Arrow - Down:
Down Arrow - Left:
Left Arrow - Right:
Right Arrow
- main.py: Handles the main game loop, screen setup, and collision detection.
- snake.py: Defines the
Snakeclass (movement, body, controls). - food.py: Defines the
Foodclass (placement). - scorecard.py: Defines the
Scorecardclass (tracking score, game over).