Code a classic card game in Python
OUR EXPERT
Calvin Robinson is a former assistant principal and computer science teacher with and a degree in computer games design and programming.
Over our series of tutorials for games programming in Python, we’ve created a Lunar Lander-style module game, a side-scrolling platformer, Pac-Man, Pong, Game of Life and a shooter. This issue we’re going to recreate another classic, Snap!
Traditionally a card game, the game presents a number of images and the player has to react with haste in order to win. Since we’re developing an electronic version of Snap, we’ll use emoji images instead of playing cards, but you could also adapt this to suit your personal preference.
First, we’ll need to make sure that we’ve got Python downloaded and installed. On a Debian-based distro it’s a simple sudo apt-get update followed by sudo apt-get install python3 . To code in Python we can either use the IDLE or any text-based editor. Type touch snap. py in Terminal to create an empty Python file for this project that we can use as soon as we’ve got everything else set up.
With Python installed and set up, we’ll also need to download , a module from by manually downloading the Zip file, or use git clone https://lawsie.github.io/guizero . Either way, you’ll need to save the guizero folder in the same parent directory as your .py Python file. For instance, snap.py would be saved in Docs, as well as guizero being copied into Docs. is built on , but is even more accessible. As with any programming, we don’t want to re-invent the wheel; if someone has put together a package to make our lives easier then it makes sense to take full advantage of it.
You’re reading a preview, subscribe to read more.
Start your free 30 days