This is a classic Snake Game implemented using Python and the Pygame library.
This game allows users to control a snake to eat food, which makes the snake grow longer. The objective is to eat as much food as possible without colliding with the walls or the snake's own body.
- Python 3.x
- Pygame
- Clone the repository:
git clone https://github.com/yourusername/snake-game.git
cd snake-game
- Install the required Python modules: If you haven't installed Pygame, you can do so using pip:
pip install pygame
Pygame is required to run this game as it provides functionalities for graphics, sounds, and user inputs.
- Once you have installed Pygame and navigated to the project directory:
python snake_game.py
- Use the arrow keys (UP, DOWN, LEFT, RIGHT) to control the direction of the snake.
- The game ends if the snake collides with the wall or itself.
- Press
Q
to quit the game orC
to play again when the game is over.
- Score Display: Your current score is displayed on the screen.
- Game Over: When the snake collides with the wall or itself, a "Game Over" message will appear with options to quit or play again.
- Real-time score display.
- Simple and intuitive controls.
The main game logic is implemented in snake_game.py. Here's a brief overview of its components:
- Initialization: Pygame is initialized, colors are defined, and the game window is set up.
- Game Loop (gameLoop function): Manages the game's main loop where snake movement, collision detection, score display, and game over conditions are handled.
- Functions: Includes functions for displaying the score (display_score), drawing the snake (draw_snake), and handling the game over message (game_over_message).
# Place your entire Python script code here, including imports and functions.