Blackjack

com.amoebacode.blackjack.core
Class Game

java.lang.Object
  |
  +--com.amoebacode.blackjack.core.GameObject
        |
        +--com.amoebacode.blackjack.core.Game
All Implemented Interfaces:
IGame, IGameObject

public class Game
extends GameObject
implements IGame

Game manages the blackjack game, including the deck, round, house rules, basic strategy, and preferences.

Version:
0.9
Author:
Jason Gurney

Field Summary
private  IBasicStrategy basicStrategy
          The basic strategy tutor
private  double currentBalance
          The user's current balance
private  IDeck deck
          The set of cards to be dealt
private  IHouseRules houseRules
          The set of casino options
private  int initialBet
          The user's initial bet for the current round
private  IPreferences preferences
          The set of game preferences
private  IRound round
          The current round of play
private  boolean roundActive
          Indicates whether the current round is active
 
Fields inherited from class com.amoebacode.blackjack.core.GameObject
listeners, parent
 
Constructor Summary
Game()
          Default public constructor.
 
Method Summary
 boolean canDeal()
          Indicates whether the next round can be dealt.
 boolean canLowerBet()
          Indicates whether the user can lower the initial bet.
 boolean canRaiseBet()
          Indicates whether the user can raise the initial bet.
private  void changeInitialBet(int betChange)
          Modifies the initial bet according to the specified change and notifies the GUI listeners.
 void checkAction(IPlayerHand playerHand, java.lang.String action, int dealerScore)
          Checks whether the specified user action is the proper basic strategy play based on the specified dealer score.
 void deal()
          Clears the current round and starts the next one (called when the deal button is clicked).
 void executeCommand(ICommand command)
          Executes the specified game command, updates the available commands, finishes the round (when necessary).
 void finishRound()
          Displays the game buttons, updates the current balance, and lowers the initial bet (if necessary).
 double getCurrentBalance()
          Returns the user's current balance.
 IDeck getDeck()
          Returns the set of cards to be dealt.
private  GameEventListenerCollection getGameEventListenerCollection()
          Returns the event listener collection for this game.
 IHouseRules getHouseRules()
          Returns the casino options manager.
 int getInitialBet()
          Returns the user's initial bet for the current round.
protected  int getNumberOfDecks()
          Returns the number of decks that are currently being dealt per shoe (as specified in the casino options).
 IRound getRound()
          Returns the current round of play.
 void lowerBet()
          Lowers the initial bet by the default bet interval.
 void raiseBet()
          Raises the initial bet by the default bet interval.
 void saveOptions()
          Saves the user-selected casino options.
private  void setupBasicStrategy()
          Sets up the basic strategy tutor and notifies the GUI listeners.
private  void setupDeck()
          Sets up the deck and notifies the GUI listeners.
private  void setupHouseRules()
          Sets up the casino options and notifies the GUI listeners.
private  void setupPreferences()
          Sets up the user preferences and notifies the GUI listeners.
private  void setupRound()
          Sets up the current round and notifies the GUI listeners.
 void shuffleDeck()
          Shuffles the deck of cards to be dealt.
 void startGame()
          Sets up the game, including the current round, the casino options, the user preferences, basic strategy, and the shoe.
private  void startNextRound()
          Starts the next round (shuffling if necessary) and hides the game buttons.
private  void updateAvailableCommands()
          Updates the sets of available game and player hand commands for each GUI listener.
private  void updateAvailableGameCommands()
          Updates the set of available game commands for each GUI listener.
private  void updateCurrentBalance()
          Increases the current balance by the specified amount and notifies the GUI listeners.
 
Methods inherited from class com.amoebacode.blackjack.core.GameObject
addEventListener, getEventListenerCollection, getGame, getParent, hasParent, setEventListenerCollection
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface com.amoebacode.blackjack.core.IGameObject
addEventListener, getGame, getParent
 

Field Detail

round

private IRound round
The current round of play

deck

private IDeck deck
The set of cards to be dealt

preferences

private IPreferences preferences
The set of game preferences

houseRules

private IHouseRules houseRules
The set of casino options

basicStrategy

private IBasicStrategy basicStrategy
The basic strategy tutor

initialBet

private int initialBet
The user's initial bet for the current round

currentBalance

private double currentBalance
The user's current balance

roundActive

private boolean roundActive
Indicates whether the current round is active
Constructor Detail

Game

public Game()
Default public constructor.
Method Detail

startGame

public void startGame()
Description copied from interface: IGame
Sets up the game, including the current round, the casino options, the user preferences, basic strategy, and the shoe.
Specified by:
startGame in interface IGame
See Also:
IGame.startGame()

setupRound

private void setupRound()
Sets up the current round and notifies the GUI listeners.

setupHouseRules

private void setupHouseRules()
Sets up the casino options and notifies the GUI listeners.

setupPreferences

private void setupPreferences()
Sets up the user preferences and notifies the GUI listeners.

setupBasicStrategy

private void setupBasicStrategy()
Sets up the basic strategy tutor and notifies the GUI listeners.

setupDeck

private void setupDeck()
Sets up the deck and notifies the GUI listeners.

getHouseRules

public IHouseRules getHouseRules()
Description copied from interface: IGame
Returns the casino options manager.
Specified by:
getHouseRules in interface IGame
See Also:
IGame.getHouseRules()

raiseBet

public void raiseBet()
Description copied from interface: IGame
Raises the initial bet by the default bet interval.
Specified by:
raiseBet in interface IGame
See Also:
IGame.raiseBet()

lowerBet

public void lowerBet()
Description copied from interface: IGame
Lowers the initial bet by the default bet interval.
Specified by:
lowerBet in interface IGame
See Also:
IGame.lowerBet()

changeInitialBet

private void changeInitialBet(int betChange)
Modifies the initial bet according to the specified change and notifies the GUI listeners.
Parameters:
betChange - the change to the initial bet

canLowerBet

public boolean canLowerBet()
Description copied from interface: IGame
Indicates whether the user can lower the initial bet.
Specified by:
canLowerBet in interface IGame
See Also:
IGame.canLowerBet()

canRaiseBet

public boolean canRaiseBet()
Description copied from interface: IGame
Indicates whether the user can raise the initial bet.
Specified by:
canRaiseBet in interface IGame
See Also:
IGame.canRaiseBet()

canDeal

public boolean canDeal()
Description copied from interface: IGame
Indicates whether the next round can be dealt.
Specified by:
canDeal in interface IGame
See Also:
IGame.canDeal()

finishRound

public void finishRound()
Description copied from interface: IGame
Displays the game buttons, updates the current balance, and lowers the initial bet (if necessary).
Specified by:
finishRound in interface IGame
See Also:
IGame.finishRound()

shuffleDeck

public void shuffleDeck()
Description copied from interface: IGame
Shuffles the deck of cards to be dealt.
Specified by:
shuffleDeck in interface IGame
See Also:
IGame.shuffleDeck()

deal

public void deal()
Description copied from interface: IGame
Clears the current round and starts the next one (called when the deal button is clicked).
Specified by:
deal in interface IGame
See Also:
IGame.deal()

startNextRound

private void startNextRound()
Starts the next round (shuffling if necessary) and hides the game buttons.

updateCurrentBalance

private void updateCurrentBalance()
Increases the current balance by the specified amount and notifies the GUI listeners.
Parameters:
netChange - the amount by which to increase/decrease the current balance

getDeck

public IDeck getDeck()
Description copied from interface: IGame
Returns the set of cards to be dealt.
Specified by:
getDeck in interface IGame
See Also:
IGame.getDeck()

saveOptions

public void saveOptions()
Description copied from interface: IGame
Saves the user-selected casino options.
Specified by:
saveOptions in interface IGame
See Also:
IGame.saveOptions()

checkAction

public void checkAction(IPlayerHand playerHand,
                        java.lang.String action,
                        int dealerScore)
Description copied from interface: IGame
Checks whether the specified user action is the proper basic strategy play based on the specified dealer score.
Specified by:
checkAction in interface IGame
See Also:
IGame.checkAction(IPlayerHand, String, int)

getNumberOfDecks

protected int getNumberOfDecks()
Returns the number of decks that are currently being dealt per shoe (as specified in the casino options).
Returns:
the number of decks

getCurrentBalance

public double getCurrentBalance()
Description copied from interface: IGame
Returns the user's current balance.
Specified by:
getCurrentBalance in interface IGame
See Also:
IGame.getCurrentBalance()

getInitialBet

public int getInitialBet()
Description copied from interface: IGame
Returns the user's initial bet for the current round.
Specified by:
getInitialBet in interface IGame
See Also:
IGame.getInitialBet()

executeCommand

public void executeCommand(ICommand command)
Description copied from interface: IGame
Executes the specified game command, updates the available commands, finishes the round (when necessary).
Specified by:
executeCommand in interface IGame
See Also:
IGame.executeCommand(ICommand)

updateAvailableCommands

private void updateAvailableCommands()
Updates the sets of available game and player hand commands for each GUI listener.

updateAvailableGameCommands

private void updateAvailableGameCommands()
Updates the set of available game commands for each GUI listener.

getRound

public IRound getRound()
Description copied from interface: IGame
Returns the current round of play.
Specified by:
getRound in interface IGame
See Also:
IGame.getRound()

getGameEventListenerCollection

private GameEventListenerCollection getGameEventListenerCollection()
Returns the event listener collection for this game.
Returns:
this object's GameEventListenerCollection

Blackjack

Copyright © 2002 amoebacode.com.