One of the reasons Python is such a great programming language for beginners is the extensive community of experienced users who have developed numerous tools and libraries to make this language easy to use. One such library, which you may recognize from the Pytris project, is Pygame.
Pygame is a set of python tools that were designed for writing video games in Python. This guide will show you how to implement several features that you may find helpful when developing your own Python game. To accompany this guide, we have provided complete Pygame implentations for two games: Frogger and Tic Tac Toe. Understanding the code for each game should help you understand how to implement certain features of games using Pygame. Some of the features can be found in both Frogger and Tic Tac Toe, while others may only be applicable to one game. This guide will not walk you through how to implement every part of a game, nor are the implentations seen in this guide the only way to implement Tic Tac Toe or Frogger. What this guide will do is provide you with a complete walkthroughs on one way of implementing certain features for a game. To understand the entirety of the code, you will have to read through the game code yourself and read the comments
While this guide does have some useful information, it barely scratches the surface on what Pygame can do. If you are interested in learning more about Pygame, visit the pygame website to see more examples, or the documentation page to learn more about the features.
A final reminder before you start looking through this guide: If you are doing a realtively simple project, Pygame may not be necessary! This is especially true for games like tic tac toe, checkers, battleship, or any other game that does not have a lot of graphical movement. Although tic tac toe is implemented in Pygame for this guide, it could have easily been done with a simpler library like turtle graphics. If you dont know whether or not you should use pygame, consult with a TA or staff member during lab or office hours!
Here are the starter files for tic tac toe and frogger. If you have not installed Pygame yet, please refer to the Pytris spec for installation instructions