Introduction
If you've ever sat at a bar in a casino, chances are you've seen the glowing screen of a video poker or blackjack machine embedded in the counter. These games have become a staple of casino culture, quietly tempting players with a simple hand or two while they enjoy a drink. Even if you haven't spent much time in casinos, you might remember the inexpensive handheld electronic games of the 80s and 90s, like small plastic gadgets that offered blackjack, poker, or solitaire long before smartphones made games a constant companion.
These compact card games were designed for quick interaction, ideal for passing time without needing much commitment. Their design roots trace back even further to the early days of home computing. Simple text-based versions of blackjack and poker appeared in shareware collections or were printed line by line in computer magazines. These early programs were often the first exposure many users had to the thrill of programming and interactive gameplay.
In this post, we’ll build on that legacy by showing how to implement two classics: blackjack and jacks or better. Using Python and Pygame, we’ll recreate the fast-paced feel of bar-top machines and handhelds alike. The goal is simplicity, clarity, and a faithful translation of the games you may have played in one form or another, whether on a glowing screen or in a plastic shell with rubber buttons.
Development
My first real obstacle in building these games was the playing cards themselves. At first, I assumed there might be a Python library out there that could automatically handle the visual representation of playing cards with Pygame. If one exists, I wasn’t able to find it. I wasn’t interested in a simple text label or just a number and suit. I wanted the cards to look and feel like real, familiar playing cards. ChatGPT suggested using an SVG file arranged like a sprite sheet. This would allow me to cut out each card as a separate image and reference it during gameplay. That approach turned out to be the best approach, and I built my card system around it.
As I’ve mentioned in previous posts, I rely heavily on tools like ChatGPT and GitHub Copilot during development. The reason is simple: building the game, debugging it, and writing a detailed article all take time, more than I can realistically spare when trying to publish two posts a week and juggle other responsibilities. To speed things up without sacrificing too much polish, I’ll often let AI handle scaffolding code while I focus on the finishing touches. In addition, I’ll spend some time creating graphics assets or generating small WAV files in Adobe Audition. A quick whoosh or click goes a long way in making the game feel finished, even when development time is tight.
That said, using ChatGPT to generate code often results in solutions that are almost correct but not quite there. For example, it might position elements on the screen in a cluttered or overlapping manner, especially in Pygame where precise spacing is crucial. It also struggles with specific game logic details, such as properly managing the player's bankroll. While these problems do not render ChatGPT unusable, they do require close attention and a willingness to refine and correct the generated output.
One of the most valuable lessons I’ve learned is that thorough planning upfront significantly enhances the effectiveness of these tools. By organizing your directory structure and dividing your code into clean, standalone modules from the start, you can save considerable time and effort. Avoid creating large, unwieldy single-file scripts whenever possible. A well-structured project encourages you to “refactor before writing,” which is essential when working with AI-generated code. Without this preparation, troubleshooting issues can turn into a frustrating process of untangling a chaotic codebase. This is something ChatGPT can’t always resolve effectively.
Another tip: if you're using the “project” feature in ChatGPT, keep your threads focused and relatively short. Long threads get sluggish, both in the user interface and in how accurately ChatGPT can understand the overall progress (it will forget things more easily). If things start to drag, you can ask for a summary or a set of continuation notes to seed into a new thread. This keeps the discussion efficient and more responsive.
There are some pieces I am not distributing with the code itself, either due to copyright or licensing. One is the SVG file of the playing cards, which I’ll link to separately along with instructions for where to place it in the directory structure. Another is the font, which is styled to evoke the video machines found in bars. And finally, there’s an optional MOD music file, used as background music during gameplay. Each of these assets will have a download link and placement guide provided.
For the first time in any of our Pygame articles, I included a PNG image as a background for the main menu screen. It’s a small touch, but it helps the launcher stand apart from the usual plain-color screens and adds polish that players will notice. In addition, you can adjust volume (or reduce to zero) for both music and sound effects to balance these to your liking.
The Directory Structure
Here’s the directory structure, for reference.
barcards/
│
├── assets/
│ ├── fonts/
│ │ └── 8-bit-pusab.ttf # obtained from dafont.com
│ ├── images/
│ │ └── Full-Deck-Of-Ornate-Playing-Cards.svg # https://openclipart.org/
│ │ └── splashbackground.png
│ └── sounds/
│ └── piano-groove.mod # MOD tracker music file (downloadable from modarchive.org)
│ └── carddeal.wav # woosh sound effect for card dealing
│
├── docs/
│
├── games/
│ ├── blackjack.py
│ └── poker.py
│
├── hud.py # HUD module for displaying bankroll
├── launchpad.py # Main game launcher to select between
├── music.py # Music loader/controller
├── shuffler.py # Utility to shuffle decks
├── svg_parser.py # Converts SVG deck into card objects
├── text_ui.py # CLI interface for interaction
│
├── tests/
│ └── test_svg_parser.py
│
├── README.md
└── requirements.txt
Third-Party Downloads
Playing Cards (Required)
The playing cards I used were by creator “GDJ” and is available on OPENCLIPART. (Original content from Pixabay is referenced, though I couldn’t find the material at that site). Download the SVG File (the green button). Be careful to avoid nefarious downloads, as download sites tend to be inundated with crapware downloads.
Note that the face cards are identified using Cyrillic, but it should be fairly easy to translate these face cards to their English equivalents. I could not locate a quality English version that would be usable in this manner.
Font (Required)
The font is 8-bit-pusab.ttf from Seba Perez , and it can be downloaded from DaFont.
Music (Optional)
Download piano-groove.mod (made by Quincy of Amable, per the internal text) from The Mod Archive. Note – the mod file is optional. The code will disable music if it can’t find this file.
If you wish to use a different mod file, you can find this in music.py
MUSIC_PATH = "assets/sounds/piano-groove.mod"
The Code and Running the Game
The code is available under our ongoing Git repository. You can clone, or look under directory barcards for individual files if you want to stay true to the spirit of the old 1980’s computing type-in program listings.
Please see directory structure above to make sure you’re staying consistent with the intended location for assets and python modules.
To start the game:
python launchpad.py
The interface should be fairly intuitive. The commands for Blackjack are keyboard driven (Hit, Stand, etc). Jacks or Better allows you to hold cards via the number keys or using your mouse. The bank is portable between games, but does not save between gameplaying sessions.
Box Art
Continuing to pay homage to 1980s computer game box art, which would often feature an assortment of box shapes and designs, here’s my contribution for “Bar Cards”. And yes, I realize that anyone sitting at a bar playing video poker will likely not be as well dressed as depicted in the art.
Conclusion
Bringing these two games to life was equal parts nostalgia and problem-solving. While the core mechanics of blackjack and jacks or better are simple, making them feel responsive, polished, and visually appealing takes a bit more effort than a basic rules engine. By using Python and Pygame, along with a few carefully chosen assets, it’s possible to recreate the charm of casino bar machines or vintage handhelds in a way that feels satisfyingly retro but still modern enough to share.
If you’re following along to build or customize your own version, I encourage you to experiment. Change the font, swap in different card art, or even design your own scoring system. That’s part of the fun, these games have been remixed for decades, and the tools today make it easier than ever to make them your own.