< Previous | Contents | Next >

Introducing the Blackjack Game

The final project for this chapter is a simplified version of the casino card game Blackjack (tacky green felt not included). The game works like this: Players are dealt cards with point values. Each player tries to reach a total of 21 without exceeding that amount. Numbered cards count as their face value. An ace counts as either 1 or 11 (whichever is best for the player), and any jack, queen, or king counts as 10.

The computer is the house (the casino) and it competes against one to seven players. At the beginning of the round, all participants (including the house) are dealt two cards. Players can see all of their cards, along with their total. However, one of houses cards is hidden for the time being.

Next, each player gets the chance to take one additional card at a time for as long as he likes. If a players total exceeds 21 (known as busting), the player loses. After all players have had the chance to take additional cards, the house reveals its hidden card. The house must then take additional cards as long as its total is 16 or less. If the house busts, all players who have not busted win. Otherwise, each remaining players total is compared to the houses total. If the players total is greater than the houses, he wins. If the players total is less than the houses, he loses. If the two totals are the same, the player ties the house (also known as pushing). Figure 10.6 shows the game.


 

Designing the ClassesPlanning the Game LogicThe Card ClassThe Hand ClassThe GenericPlayer ClassThe Player ClassThe House ClassThe Deck ClassThe Game ClassThe main() FunctionOverloading the operator<<() Function