A classic Snake Game implemented in Python using the Turtle library.
This project is a simple implementation of the Snake Game using Python's Turtle library. The game involves controlling a snake to eat food pellets, growing longer with each pellet eaten, while avoiding collisions with the walls or itself.
- Classic Snake gameplay experience.
- Score tracking and display along with high score.
- Simple controls using arrow keys.
- Python 3.x
- Turtle library (Usually comes pre-installed with Python)
- Clone the repository to your local machine:
- Use the arrow keys to control the direction of the snake.
- The snake will continuously move in the current direction.
- Eat food pellets to grow longer and increase your score.
- Avoid collisions with the walls or the snake's own body.
- The game ends when the snake collides with a wall or itself.
This document provides an overview of the methods available in the Python files food.py
, scoreboard.py
, and snake.py
, which are used in the Snake game.
- Initializes a new instance of the
Food
class. - Sets up attributes such as shape, color, size, and initial position of the food.
- Generates random coordinates within the screen boundaries and moves the food to that position.
ALIGN
: Center alignment for text display.FONT
: Font specifications for text display.
- Initializes a new instance of the
Scoreboard
class. - Sets up attributes such as current score, font, color, and initial position of the scoreboard.
- Displays "GAME OVER" message at the center of the screen.
- Updates the displayed score on the scoreboard.
- Increments the score by 1 and updates the scoreboard display.
MOVE_DIST
: Distance the snake moves in one step.UP
,DOWN
,LEFT
,RIGHT
: Directional constants for snake movement.STARTING_POSITIONS
: Initial positions for the segments of the snake.
- Initializes a new instance of the
Snake
class. - Sets up attributes such as segments list and the snake's head.
- Creates initial segments of the snake at predefined positions.
- Adds a new segment to the snake at the specified position.
- Extends the length of the snake by adding a new segment to its tail.
- Moves the snake forward by updating the positions of its segments.
- Change the direction of the snake's head based on user input.