By Dr. Angela Yu
Day 20, 21 of 100: GUI, Animation, Coordinates, Inheritance, List Slicing, Instances, State, High Order Functions
Using Turtle Screen capabilities, program the classic Snake game where a user guides a snake to food and each time the snake eats the food, it gets longer.
The game ends if the snake collides with itself or a wall.
This application is written with Python 3.11.
This game application features a constantly moving snake that follows a path and is guided to randomly placed food on the screen.
The current score and the high score is tracked at the top of the screen.
This project uses three classes and one data file:
- Snake
- Food
- Scoreboard
- data.txt
The user guides the snake head by pressing the up
, down
, left
and right
arrow keys.
When the snake eats the food, it adds length to its tail and scores a point.
If the snake head collides with either a wall or its tail, the game resets.
Once a game ends, if the score is the highest score the user has achieved, it writes that score to a text file for use in future games.
All of the commands below should be typed into the Python terminal of your IDE (I use PyCharm for my Python Development).
First, clone the repository from Github and switch to the new directory:
$ git clone git@github.com:shelbyblanton/snake-game.git
Then open the project in PyCharm.
Setup is complete!
Click Run in PyCharm to see the app in action.
Programmed by M. Shelby Blanton under the instructional guidance of Dr. Angela Yu via Udemy.com.