This is a classic Snake Game I made in my 7th class using Python and the PyGame library. The player controls the snake using arrow keys, eats food to grow, and tries to avoid collisions. I also added a small cheat feature — pressing the Q key increases the score by 10.
I learned the basics of Python game development through a YouTube tutorial by CodeWithHarry, and then built this version myself.
- Classic snake movement (Up, Down, Left, Right)
- Random food spawning
- Score and High Score system
- Game Over screen with restart option
- Cheat key: Press Q to add +10 to score
- Welcome screen
- Simple animations using PyGame
- When the game starts, the snake is a small block controlled by arrow keys.
- Food appears at random locations on the screen.
- When the snake touches the food, the score increases and the snake grows longer.
- If the snake touches the wall or its own body, the game ends.
- The game saves the highest score in a file called hiscore.txt.
- Pressing Q adds 10 points without eating food (a small cheat code I added).
Install PyGame:
pip install pygameMake sure a file named hiscore.txt exists in the same folder (Put 0 inside it initially)
Run the python file:
python snake.pyReplace snake.py with your actual filename. The game will open in a new window with a welcome screen
- Python 3
- PyGame
- Basic file handling (hiscore.txt)
- Basic game loop & event handling
- How PyGame handles graphics and game windows
- How to detect keyboard events
- How to create a game loop
- How to manage snake movement and growth
- Basic collision detection
- Saving high scores using file handling
- Random number generation for food placement
- Adding sound effects
- Adding a background image
- Increasing difficulty over time
- Adding a main menu with buttons
- Showing the snake's path more smoothly
- Adding different levels or obstacles
This project was created with the help of the YouTube channel: CodeWithHarry, and then customized by me.
