1. Specification
Write a GUI for a system that plays one or more games of Blackjack; use the rules given in Appendix A. The basic operation of the GUI is described here, and snapshots are given in Appendix B. A complete executable version of the code is not provided to run, but 90% of the code is given.
1.1 Model code
The model code is located in the model package in the BlueJ project. It is the solution from assignment 1, adapted to use the GUI. There is no Dealer class: the dealer is an object of type Player. All console IO has been removed. The model code is complete, except for calls to update() that you have to add as needed.
1.2 GUI behaviour
The system asks for the number of players (not including the dealer) and their names, as in Appendix 1, but uses pop-up dialogue boxes. It then shows the game GUI.
The game GUI is one window with p + 1 panels: a panels for each player and one at the bottom for the dealer. These panels are all objects of the same class. A player panel has two parts: a status panel at left and an action panel at right. The status panel has two parts: bet data at the top and cards at the bottom. The bet data consists of the player name, stake, bet, and last action. A player is identified with a number and name, but the dealer is just called "Dealer". The hand panel shows the cards in a player's hand, from left to right as they are dealt.
The action panel for a normal player has three buttons labelled "Buy", "Draw", and "Sit"; these do the obvious things. The action panel for the dealer has three buttons labelled "Draw", "Sit", and "Again". The system deals one card to each person, shows these cards in the hand panels, and then waits. The user (you) then gets a second card for each person by clicking on an action; a player has the choice to buy or draw, but the dealer can only draw a second card. When a player buys a card, the system asks for the buy amount with a pop-up dialogue box, subtracts the amount from the player's stake, and adds the amount to the player's bet. All amounts are shown with two decimal places. The action is shown at far right in the status panel, directly to the left of the action panel, in the form "Action: XXX". The action button in the action panel is cleared after each choice.
If the dealer has BlackJack, the game ends and the dealer collects all the bets. The bet amounts are set to zero, and the player and dealer stakes are updated. If the dealer does not have BlackJack, then control returns to the first player, who (you) can choose to buy, draw, or sit.
A player continues until s/he decides to sit, or busts. If the player busts,
• that player's bet is given to the dealer,
• the bet amount is set to zero,
• the action changes to "Busted!" shown in red, and
• the player can do no more actions in that game.
Each player in turn plays, until all players have sat or busted.
If all players have busted, the dealer sits and the game ends; otherwise, the dealer plays. The dealer draws cards until s/he decides to sit, or busts. If the dealer busts, all remaining players are paid. If the dealer sits, then the winners and losers are handled by the system. If a player wins, then
• s/he gets the appropriate amount of money (including special hands),
• the dealer and player stakes are updated,
• the action of "Winner!" is shown, and
• the bet panel turns green.
If a player loses, then the dealer gets that bet. At the end of the game, all bets are shown as zero, and the stakes are updated. The user (you) can then start a new game by clicking "Again" in the dealer panel.
1.3 Simplifying assumptions
To make it easier
• assume that all inputs are correct and valid; do not validate the input
• don't run out of money; choose the bet values so this never occurs
• don't run out of cards; stop playing before the deck is all used
• nobody ever splits
2. Your tasks
You have to
• build the status panel
• code the action listener for the action panel
• code the update methods in the panel classes
• add the calls to update() in the model classes
The panels never talk to each other. All updating is done via update() methods using the MVC pattern. The missing code you need to add is about 60 lines of code.