Python: The Game

  • Python 3.8.6
  • PyGame 1.9.6
  • MySQL 8.0.22
  • mysql-connector-python 8.0.22

The classic Snake game, made in Python with a few extra features and game modes.

There are 4 game modes:

  1. Singleplayer Easy: The classic Snake game! The screen wraps around, allowing the player to reach the fruit faster. The speed of the snake stays constant.
  2. Singleplayer Hard: The classic Snake game, but harder! The screen doesn’t wrap around anymore and hitting the edge of the screen means game over. The speed of the snake gets progressively faster as the snake grows longer.
  3. Multiplayer Co-Op: The classic Snake game, with a friend! Two snakes compete against each other to get the fruit. The game ends when either of the snakes collide with each other or themselves. When the game ends, the snake with the highest number of points wins.
  4. Multiplayer Computer: The classic Snake game, with the computer! You go head-to-head with a rudimentary algorithm named Edward. Edward compares the location coordinates of the head of his snake and the fruit and keeps moving the snake until the location of both becomes the same. This makes the algorithm really fast at catching fruits, but it is unable to identify when it is about to run into a game over. Edward also doesn’t recognize that the screen is wrapped around, so you could use it to your advantage to get to the fruit faster.

Besides the game modes, I’ve also integrated mySQL functionality in this game. After the game ends, you will be prompted to enter the username and password of your mySQL account. A database is created to save the player results. This is how the Leaderboard is implemented.

If you don’t have mySQL set up, the game still functions, but will error out and close when it tries to access mySQL after the game over screen.

This game marks my first time using classes and multiple functions in a program. As such, the code is messy and unorganized.

This is a project that’s very dear to me. It’s the first project I ever completed in its entirety, and it’s also the project that taught me what I believe is the most crucial skill any programmer could have: debugging.

I apologize for the low-res screenshots (I should also mention, the game isn’t in black-and-white; the WordPress theme I’m using converts all uploaded images to grayscale. Until I figure out how to change that, I’m stuck with gray tones):