< Previous | Contents | Next >
The last part of my planning is to map out the basic flow of one round of the game. I wrote some pseudocode for the Game class’ Play() member function. Here’s what I came up with:
Deal players and the house two initial cards Hide the house’s first card
Display players’ and house’s hands Deal additional cards to players
Introducing the Blackjack Game 361
Reveal house’s first card
Deal additional cards to house If house is busted
Everyone who is not busted wins Otherwise
For each player
If player isn’t busted
If player’s total is greater than the house’s total Player wins
Otherwise if player’s total is less than house’s total Player loses
Otherwise Player pushes
Remove everyone’s cards
At this point you know a lot about the Blackjack program and you haven’t even seen a single line of code yet! But that’s a good thing. Planning can be as important as coding (if not more so). Because I’ve spent so much time describing the classes, I won’t describe every part of the code. I’ll just point out significant or new ideas. You can download the code for this program from the Course Technology website (www.courseptr.com/downloads). The program is in the Chapter 10 folder; the filename is blackjack.cpp.
Hin t
The blackjack.cpp file contains seven classes. In C++ programming, it’s common to break up files like this into multiple files, based on individual classes. However, the topic of writing a single program using multiple files is beyond the scope of this book.