We will develop a C++ program that implements a simple blackjack card game. Students may be asked to complete aspects of the design or implementation of such a game and the instructor may provide refinements to the design/implementation of the as we go through the semester and introduce more object-oriented programming concepts.
A blackjack game has a player and a dealer. A player is provided with a certain sum of money with which to play. A player can place a bet between 0 and the amount of money the player has. A player is dealt cards (called a hand), each of which has a point value. The objective of the game is to get as close to 21 points as possible without going over. A player that goes over is out of the game.
The dealer deals cards to itself and a player. The dealer must play by slightly different rules than the player. The dealer does not place bets.
A player is dealt two cards face up. If the point total is exactly 21 the player immediately wins. If the total is not 21, the dealer is dealt two cards, one face up and one face down. A player then determines whether to ask the dealer for another card (called a "hit") or to "stay" with his/her current cards. A player may ask for several "hits". When the player decides to "stay" the dealer begins to play. If the dealer has 21 it immediately wins the game. Otherwise, the dealer must take a "hit" until the total points in its hand is 17 or over, at which point the dealer must "stay". If the dealer goes over 21 while taking "hits", the game is over and the player wins. If the dealer's points total 21, the dealer wins immediately. When the dealer and player have finished playing their hands the one with the highest point total is the winner. Play is repeated until a player enters a $0 bet.
Points are calculated as follows:
An ace may be valued as 1 point or 11 points by the owner of the hand (i.e., the player or the dealer). The owner of the hand may change the value of an ace at any time during their turn at play.
A card will be valued from 1-10.
Ace will be treated as a 1 by default, since it shouldn’t be a responsibility of the Card class to know anything about the state of the game---determining whether to value an ace as ‘1’ or ‘11’ will be done by some other class.
The show() method will simply return card information as a string, e.g., “3-hearts”
The calcValue() method could be made private, since it will only be called by constructors
A deck will be modeled as a collection of Card objects. Could use an array, vector, or some other mechanism to hold cards.
The next attribute is the index of the next card to be dealt.
The nextCard() method returns the card dealt. This method should also be responsible for determining what is done when the deck becomes empty --- one possibility is to create a new deck when a deck becomes empty…giving the appearance of an infinite deck
The empty() method returns true if the deck is empty.
The shuffle() method shuffles the deck. There are many ways this could be done. This will require using a random number generator
A hand will be modeled as a collection of Card objects.
The addCard() method adds a card to the hand, and calls the calcValue() method to determine the card’s point value.
The calcValue() method returns the point value of the card that was most recently added to the hand. It needs to have a decision rule built in to determine whether an ace should be valued as 1 point or 11 points. Note that this method could be made private assuming no other object needs to call it.