A simple, classic Snake game implemented in Python using the Pygame library.
- Move the snake in four directions (up, down, left, right) using arrow keys.
- Eat the red food block to increase the snake's length and score.
- The game ends if the snake hits the screen boundaries or collides with itself.
- Display the player's score in real-time.
- Restart the game by pressing
P
after losing.
- Python 3.x
- Pygame library
You can install Pygame using pip:
pip install pygame
- Save the game script (
snake.py
) to your local system. - Open a terminal or command prompt in the directory where the script is saved.
- Run the script using Python:
python snake.py
- Arrow Keys: Control the snake's movement
- Left Arrow: Move left
- Right Arrow: Move right
- Up Arrow: Move up
- Down Arrow: Move down
- P: Restart the game after losing
- Q: Quit the game
- Every time the snake eats a food block, the score increases by 1.
- The current score is displayed at the top-left corner of the screen.
You can customize the game by modifying the following variables in the code:
- Screen dimensions:
dis_width
anddis_height
- Snake speed:
snake_speed
- Snake block size:
snake_block
When you start the game:
- The snake starts in the center of the screen.
- Move the snake to eat the food (red block).
- Avoid colliding with the screen boundaries or the snake's own body.
Ensure you have the following dependency installed:
This project is for educational purposes. Feel free to modify and use it as you like.
Enjoy the game! 🐍🎮