
Blackjack Game using objects in C++
The Overview
The goal of this lab is to use classes and objects to create a program to play Blackjack (21) in C++. A start of the program is given below, you must continue this program to complete the game. This assignment has been updated to make it easier, take note! If you already started with the older code, and want to continue with that, it is fine.
Here is (the new) start code for the project: https://repl.it/@JimSkon/BlackjackCppStart2
Here is the original start code: https://repl.it/@JimSkon/BlackjackCppStart
The code above includes the following classes:
- Card – This is a single card with a suit and a rank (which is a given card’s “state”). The suit and rank are represented by the integers 0-3 for suits, and 0-12 for rank.
The methods on a card are Card(…) (the constructors) and CardName(…) and CardValue(…) which return the value of the card. - Hand – This is essentially an arbitrary group of playable cards. It contains zero or more Card objects (stored in a vector). The Hand class has the Hand() construct to create the (empty) hand, Add(…) to add a card to that hand, bool Wins() to tell you if the player wins by hitting 21, a GetCardList() to get a list of the card in the hand, and a GetTotal() to get the total value of the hand. Note that there are two hands – one for the house, and one for the player.
- Deck – This is similar to the hand in that it is a set of cards. It is different in that it had (hidden inside) a pool of 52 cards from which it creates a deck which gets played from. As you play from the deck it gets smaller, until it is empty. WHen it is empty you will need to reinitialize the Deck to 52 cards. The deck includes the Deck() constructor and GetCardList() (like the hand’s member functions), the Populate() to remake a new deck of 52 card (from the pool), a Shuffle() to randomize the deck, a Deal to remove the top card from the deck and return it.
Note that as you play the cards in the deck get used up. This is normal. You will need to come up with a better plan on what to do when the deck runs out, and implement it. This may require modifying and even adding new member functions to the existing object classes.
What you must do
Most of the game is already written. You mugst merely complete the following:
- Card and Deck are done!
- In Hand.cpp, you must complete the Wins(), isBusted(), GetCardList(), and tally() methods.
- In main.cpp game() you must show the game state in the main game loop. This means you show the player cards and the current tally.
- In game(), add a house strategy to the main game loop. Usually the house draws on < 17
- In main.cpp game() you must check for all the possible game win, lose or draw cases, and return “win”, “lose”, or “draw” to the main() function.
- In main.cpp main() you must keep track of the win, lose and draws, and display them.
Grading Table
| Requirement | Grading Comments | Points | Score |
|---|---|---|---|
| Game works as specified | 60 | ||
| C++ code includes comments, with project information at top, pre and post conditions for each functions and other comments as needed. | 5 | ||
| The C++ code has good formatting, indentation, and organization. | 5 | ||
| Good variable and function names, appropriate use of constants rather then literal numbers. | 5 | ||
| Class implementation: Logic is correctly implemented in the correct class methods | 15 | ||
| Runs: Runs correctly, Turn in a run with at total of at least 10 hands of play. | 10 | ||
| Total | 100 |
Lab Objective
Use classes and objects to complete the program to play Blackjack (21). Using the code here, you will create a game that:
- Plays the house agains a single player.
- Play a game of Blackjack until someone wins, and then annoucing the winner, and tallying the wins, loses, and ties (pushes)
- Allow the user to continue to play again, drawing from the same (shrinking) deck, until the deck is empty.
- You may offer the user the chance to restart the deck when done.
