Skip to content

darshyadav12/Snake-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Snake Game (PyGame Version)

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.

Demo

2025-12-0522-05-17-ezgif com-video-to-gif-converter

Features

  • 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

How It Works

  • 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).

Installation

Install PyGame:

  pip install pygame

Make sure a file named hiscore.txt exists in the same folder (Put 0 inside it initially)

Deployment

Run the python file:

  python snake.py

Replace snake.py with your actual filename. The game will open in a new window with a welcome screen

Tech Stack

  • Python 3
  • PyGame
  • Basic file handling (hiscore.txt)
  • Basic game loop & event handling

Lessons Learned

  • 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

Future Improvements

  • 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

Credits

This project was created with the help of the YouTube channel: CodeWithHarry, and then customized by me.

About

This is a classic Snake Game I made in my 7th class using Python and the PyGame library.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages