Blackjack banner

Blackjack

9 devlogs
10h 3m 11s

This is my first C++ project, and I built this because I wanted to understand how OOP works and how to write efficient OOP code.

I wanted it to be more than just a regular Blackjack game, so at the end of each game, I analyse the playing styles…

This is my first C++ project, and I built this because I wanted to understand how OOP works and how to write efficient OOP code.

I wanted it to be more than just a regular Blackjack game, so at the end of each game, I analyse the playing styles of the user and generate a blackjack personality type.

This project uses AI

Used ChatGPT for debugging and code review

Demo Repository

Loading README...

Vulcan

Shipped this project!

Hours: 10.05
Cookies: 🍪 53
Multiplier: 5.27 cookies/hr

This is my first C++ project, and I built this because I wanted to understand how OOP works and how to write efficient OOP code.

I had lots of fun with this as I got to learn about classes, header files, and more OOP concepts while building a fun game that I got many of my friends to play.

I wanted it to be more than just a regular Blackjack game, so at the end of each game, I analyse the playing styles of the user and generate a blackjack personality type.

Thanks for reading, and I’d love any C++ critique.

Vulcan

This is the last devlog and I spent most of this time working on generating an executable for Mac and Windows even though I don’t have a Windows.

After creating one, and testing on both, I realised that I can’t see the card emojis in the Windows executable, although I can in the Mac one, so I managed to make UTF 8 work on Windows and Mac.

After that, I created the README and fixed some final things before creating the release on GitHub!

Attachment
0
Vulcan

Second last devlog (probably)

I wanted the code to be as good as possible, so I:

  • removed the case sensitivity from hit + stand
  • added saving and getting highscore from a text file
  • added the Deck and Card classes to deck.h and deck.cpp, and added Hand, Player and Game to game.h and game.cpp

Now the code looks much nicer. Thanks to the 2 people who reviewed my code.

Anyone have any more feedback, let me know, and I’ll implement it!

Attachment
0
Vulcan

Personality Types

To make this more interesting and different from other blackjack games, after you finish playing (either hit 0, or decided to stop with the money you have), your whole game is analysed and is assigned a personality type (there are 8).
The highest one is WINNER so people might want to keep trying until they get this.

Attachment
0
Vulcan
  • To make it more object oriented, I added the user’s hand to player to make the code more abstract.
  • Then I found a bug which meant that you could bet negative money, so I fixed that bug
  • I added methods like add_card to Player, and made Player.hand private, which meant that the code is better encapsulated.
  • I also added a more efficient card shuffling algorithm using std::shuffle
  • Then I spent 1 hour playing the game with the friends so that they could test it out and give me feedback
Attachment
0
Vulcan

Adding a Player class

This time I decided to work on the player betting money.
For this, I created a Player class which handled storing the user’s money, then the user gaining and losing it through the gain_money and lose_money methods.
I then worked on the main() function which handles the main game and added a loop which continues running the game until the user stops betting money.

Attachment
0
Vulcan

Making my code object oriented

I set on a mission to turn my current code into fully object oriented code. I ended up:

  • creating a Deck class which contains a vector of Card objects, has a shuffle method, and a deal method
  • creating a Hand class, which these methods: total, add, show_cards, is_bust, is_blackjack
  • in the main function, I implemented the main code game using the classes I had defined before
Attachment
0
Vulcan

I realised that the reason I decided to learn C++ was because I wanted to learn object-oriented programming, but the code I was writing wasn’t very object-oriented at all. So I decided to start refactoring my code to make it more object-oriented.

What I learnt:

I learnt about:

  • enum, and created a suit and rank enum
  • creating a Card class with private attributes and public methods
  • using member functions to convert enums to strings
  • constructors, including a default constructor and a parameterised constructor
  • switch statements for handling multiple cases
  • the use of static_cast<int> to get the numeric value of an enum

Next steps:

  • I want to create a Deck class that contains a vector of Card objects
  • Implement shuffling and dealing methods for the deck
  • Start building simple game logic, like blackjack, using these classes

This refactor made me realise how object-oriented design can make the code more readable, reusable, and easier to expand.

Attachment
0
Vulcan

Blackjack Game

In the last hour, I’ve implemented a basic BlackJack game where:

  • you start off with 2 cards
  • you hit until you’re busted or stand
  • if you’re busted you lose
  • else the dealer hits until they cross 17
  • if the dealer busts they lose
  • else the higher total (between the user and the dealer) determines who the winner is
Attachment
0
Vulcan

First devlog: Card Shuffling

This is the first devlog of this project, which is intended to be a console based blackjack game.
This is my first C++ project, so I hope to learn the syntax and how it works through building this.

The first thing I implemented was a card shuffling algorithm, and this was by converting an algorithm I had in Python, into C++. Through this, I learnt a lot about vector and random number generation.

Attachment
0