Black Jack - Chippy Edition
Black jack chippy edition is a C++ application that I had made for my final university assignment to end my first year at university.
Feature log - A 3 minute video displaying the key features of the program
Inspiration
When I was first given the assignment, a design brief was specified that the application must be a card game which include specified key features such as design an algorithm that will allow the program to shuffle and deal from the deck whilst keeping track of each players hand. This key specification is what gave me the idea to create blackjack for multiple of reasons.
- Keeping track of players hands is a key feature in black jack, croupiers at casinos help players keep track of their hand by counting the cards for them.
- Black Jack is an iconic due to it easy to understand rules compared to other card games such as poker or solitaire.
- Black jack is a simple game on paper but has a lot of element/features to test my skills as an new game developer
Creation process
Starting the project was intimidating because I knew I had a few challenges ahead of me to make a fully functioning project the was aesthetically pleasing to the player to see whilst being fun to play. At the start of the assignment we were given a basic tutorial documentation that gave us a basic structure that we could build upon to make our own card game, the tutorial documentation created a program that deal players five cards along side a shuffle button.
(Body of Code following tutorial documentation)
(Results of following tutorial documentation)
The Results were a good start but good start but didn't match the functionality of the blackjack game I wanted to make. Being new to python I spent the first four days of my assignment studying the code and how everything was displayed to the screen, this involved learning how dictionary's, tuples and sets worked within python and I had learnt that within the for loop the card suit and value was being initialized to a dictionary called 'card_images' with the rank suit being the key and the card to display as the value.
Which was later used to display cards on the screen using the .blitz() function provided by the pygame library.
Once learning how all the mechanics for the basic structure worked I decided to start learning the basics of pygame which involved making collisions and displaying different elements to the screen. with this new found knowledge I had decided to scrap the tutorials version of the button and followed a tutorial by a YouTube creator called 'Coding with Russ' (Link to video) which I had altered slightly so the buttons had visual a interaction response when a player hovered over a button.
(Code for button)
Using this new class I had created a new button along side a new function that draws cards onto the screen.
(Please note screenshots and gifs from this point on are from the finished build as documentation was not recorded during the testing of buttons and function)
The if statement checks to see if the button has been pressed and if returned true then the code lock will be executed.
Once I had the cards displaying to the window once the hit button had been pressed I wanted the hit button to display cards on the correct side of the field depending on which player was currently active.
When the hit button is pressed it would call a custom made function named 'draw_card' which took a single parameter for the offset the cards will be displayed onto the screen. The function looks at the current active player and chose a random key from the cards dictionary and blitz it onto the screen in the location specified. Once the card has been dealt it is then deleted from the deck using the .pop() function. The same set of code is used for the second player (AI) but allocated different X & Y dimensions so the cards are placed at the top screen instead of located in the same X & Y as the player.

When that task was completed my next task was to track the card score between each player, This was the next important step because I needed to compare the players cards to the dealers to set a win condition. Python 3.10 or higher introduced match statements which is the pythons version of switch statements. I had the idea of using the random key value that is generated when a player draws a card to pass that value into it own function as a parameter and compare the key value to a list of match cases and depending on the score and player it will add the assigned score to the player.


Each card has its own case and given values that will add points to the active player if the card were to be drawn. I will go into more detail at the end of the blog but through out production of the application this style of checking score did bother me because I didn't know if there was a more efficient way of checking the players score but I knew it took a lot of lines of code, this is a topic I would like to research more detail in future projects to find a more efficient solution, with that being said the match cases worked and the players score were being added to their respected variables when a card had been drawn.

Once the active players scores were being counted accuracy I started working on the stand/stick mechanic which would allow the player to stick with their hand then the game would transition to the AI turn, this was actually really easy to implement since the code for the AI to draw cards was already implemented when I created the draw function for the player, all I had to do was add a button the player could press which would swap the 'currentPlayer' variable from 1 to 2 which is the AI.
Finally I added different win and lose conditions if the player get higher or lower than the dealer, if the player and dealer have the same score by the end of the round it will end in a draw.
UX
The tutorial
For user experience I wanted to add a visual tutorial that will show the players how to play the game rather than them have to read a list of instruction/rules as I figured this would make the user experience more engaging as the dealer/AI will guide the player through the application showing them the rule on how to play blackjack.
To create this I had to make new class which created speech bubbles and drawn them onto the screen at a specified X and Y co-ordinates. To make this class was actually rather simple to make also as I took inspiration from how the buttons were created in the tutorial template at the start of the assignment.
I first initialized the font using pygames font function, then I got the size of the text using the get.rect function and placed its pivot point to the midright of the rectangle. This allows the speech bubbles to be generated from the right hand side. This is important because depending on the size of the text the text for example if the pivot point was set to the center, when the text is created the text would expand in either direction on the X axies which would lead to inconsistency depending on the text size, but with the pivot point to the middle right the text will generate from right to left.
Finally I made a function which activated once the tutorial button is pressed activating a group of speech bubbles.
The second UX feature I added was the ATM/Stats feature.
When starting the game the players starts with a balance of 0 this is to teach the player about the atm system they can use to withdraw or deposit chip, which is then displayed in their stat bar during game play. I implemented this feature to represent a 'High score system' so the player can earn the highest amount of chips to put in their bank before exiting the game.
Similar to the stick/stand button this feature was made creating buttons and assigning/changing variable values when the button is pressed.
The reason Implemented the chip/currency system is to keep to the tradition black rule which give the player a reason to actually play the game. A round of black jack cannot start until the player has placed chips of the table, if a player tries to play a round without placing chip no cards shall be dealt.
Extra elements
- UI is designed in a pixel art theme for a retro nostalgic feel (Note art was no created by me, I used art and altered them to fit the pixel art theme I was trying to create).
- 4 8 bit/lofi background soundtracks to calm the player whilst playing the game.
- The dealer has different emotions and speeches depending on the win condition.
- Double button will double the players betting amount but can only draw one additional card.
There are sounds for every intractable element within the game, genre pixel/ retro game sound to fit with the theme.
Reflection
This assignment was a very fun assignment for me, I really enjoyed learning and truly understanding how the basic code from the tutorial documentation displayed the cards onto the screen. When learning the technical details such as for-loops, tuples, lists, sets, dictionary's and how they are implemented to display the cards onto the screen, it made me all the more excited to use the knowledge I had learnt and make my own blackjack game and I am very happy with the outcome of the game, it was real test on how much knowledge I had learn during my first year at university. Even though I am happy with how the game turned out, there is one game breaking bug that i am devastated I wasn't able to fix before the deadline. When the tutorial is playing, if the player clicks multiple times the game crashes but due to the nature of the crash it does not show in the debug console what is causing the crash. I spent hours upon days looking at different solutions online but none of the solutions I found online worked and the crash keeps happening. I know it has something to do with the tutorial because it doesn't crash when playing the actual game or ATM but sadly I wasn't able to fix it before deadline. What I learnt from this assignment even though some aspects of programming can come naturally to a person it take a lot of knowledge and practice to truly understand how to problem solve when a problem such as a crash occurs, because not all problems are going to be a simple and easy fix. Going forward I am going to learn C++ and thoroughly study the language, practicing problem solving challenges that will hopefully increase my knowledge on the different types of errors and crashes that may occur throughout my programming journey and different method of over coming those problems. Even though my code for this project isn't perfect It has raised my confidence of becoming a programmer as I had multiple challenges as I had to face and overcome. I learnt multiple new ways of programming code, refactoring and problem solving.
Comments
Post a Comment