Author: Sergey Klibanov
| || 24 ||Oct
|| 30 ||Oct
|| 1-2 ||Nov
|| 8-9 ||Nov
|| 10 ||Nov
Implementing a card game is a very good way to learn operations with stacks, as well as the general semantics of writing a windowed program. In this lab, you will use the foundation you put together in Lab 7 to create a game of BlackJack.
By the end of this lab, you should
- Be much more experienced with the Design stage of programming.
- Know how to effectively create a button using a mouse listener.
- Further your understanding of inheritance.
- Be a better BlackJack player.
- If you need the class files from Lab 7, they
- Read over this entire document before you start.
- There are three sample solutions. One without splitting and one with splitting.
And here is another without
The class-sponsored design is available only for the former.
- If you need help, please ask.
- You will not be getting a .zip file with this lab -- you already have
everything you need.
Problem Description: BlackJack
You must implement a BlackJack game. The rules are as follows:
- There are two players, a Player controlled by the user and a Dealer controlled by the computer.
- Play starts with the following events:
- The dealer creates a shoe of 4 decks.
- The dealer shuffles the shoe
- The dealer discards the top card on the shoe. This is called "Burning" the top card.
- The dealer takes two cards, the first face down and the second face up
- The player receives two cards from the dealer, both face up.
- The player then has the following options:
- The player can "Hit" or request another card
- The player can "Stand" or refuse any more cards
- On any two-card hand, the player can "Double" or double his bet and take exactly one more card. The effect is the same as doubling the bet, hitting, and standing all carried out in the same move.
- On a hand with two cards of the same rank, the player can "Split" or create two hands from his one. This is done by taking the second card from the original hand and creating a new hand with it. The original hand is given a new card from the deck, and play resumes on the second hand. The bet on the second hand is the same as was on the first hand. The new hand is then treated like a hand all its own -- that is it can be re-split, doubled on, etc.
- After the player's choice is acted on, it is the dealer's turn.
- The dealer has no options. He must Hit on any point value 16 or under and stand on any value 17 or higher.
- After the dealer is finished, if the player's hands are still in play (ie the player has not stood, doubled, or busted), it is the player's turn again. This continues until the player can no longer make a play. After that, the dealer (if necessary) brings his total up to 17 or above and the winner is determined.
- The player's goal is to beat the dealer's score. Scores are calculated as follows:
- A hand's point value is the sum of the point values of all the cards it contains.
- Cards 2-10 are face value, Jacks, Queens and Kings are 10 points, and an Ace is 1 or 11 points, as desired.
- A hand valued over 21 is a losing hand and is called "Busted"
- If a player's two dealt cards total 21, that is called "BlackJack".
- The winner is determined as follows:
- If neither the player or the dealer bust and their scores are not the same, whoever has the higher score wins. BlackJack beats 21.
- If both have the same score, or both busted, or both have BlackJack, there is no winner; there is a Standoff.
- If the dealer busts, the player wins and if the player busts, the dealer wins.
- Cash winnings are determined as follows:
- If there is no BlackJack or doubling involved, if the player wins the amount of his bet is added to his cash amount; if the player loses, the amount of his bet is deducted from his cash amount
- If the player got BlackJack, the payoff is 150% of the bet. If the dealer got BlackJack, the amount of the player's bet is deducted from his cash amount.
- If the player Doubled and won, twice his bet is added to his cash total; otherwise twice his bet is subtracted.
- If the player opted to split and is playing two hands, the totals for the hands are calculated separately.
- Implementing the Splitting of hands is optional and extra credit. Adding an Emote to represent the dealer's face is optional and extra credit. Everything else is required.
- Your design must be based on what you have already developed in
Lab 7. Use those classes so that you do not have
to invent new classes unless necessary.
- Think of the BlackJack game as a conversation between a Dealer and a Player. The wrong way to approach this lab is to consider one big BlackJack class that controls all play. The correct way is to initialize the dealer and player, and tell one of them to start the game. Then they would call each other's methods indicating whose turn it was, what card who is supposed to take, et cetera.
- One major consideration is how you will accept input from the user.
You should probably conceive of a construct that behaves like a regular button that can be clicked to trigger an event.
Take a look at our sample solution.
The buttons in the sample solution are comprised of a
Rect with a sublass of
listening for a mouse release event.
On top of that is a
StringComponent displaying the name of the button. Once you have a working button class, you should proceed to articulating the interaction between the player and dealer.
For inspiration on how to subclass
take a look at the
You are encouraged to follow your own design; however,
look at the very detailed class-sponsored design for inspiration if you need it. You are not constrained to using the class-sponsored design. This design does not incorporate the splitting of a hand into the program, but can be easily adjusted to do so.
What to turn in:
- Complete a design cover sheet for
the design portion of this lab.
- Complete a code cover sheet for
the code portion of this lab.
- Provide a printout of any files you have created or modified.
- Provide a the transcript of one session of play. If you chose to add splitting as one of the possibilities, the transcript must show a successful split. You may find it convenient to stack the deck a little bit to demonstrate splitting.
Last modified 14:22:25 CST 06 November 2000
by Ron K. Cytron