Blackjack

com.amoebacode.blackjack.core
Class Hand

java.lang.Object
  |
  +--com.amoebacode.blackjack.core.GameObject
        |
        +--com.amoebacode.blackjack.core.CardCollection
              |
              +--com.amoebacode.blackjack.core.Hand
All Implemented Interfaces:
ICardCollection, IGameObject, IHand
Direct Known Subclasses:
DealerHand, PlayerHand

abstract class Hand
extends CardCollection
implements IHand

Hand is the base class for all hands (PlayerHand and DealerHand).

Version:
0.9
Author:
Jason Gurney

Field Summary
private static int MAXIMUM_HARD_CARD_SCORE
          The maximum hard score for a single card
private static int MAXIMUM_NUMBER_OF_CARDS
          The maximum number of cards per hand
protected static int MAXIMUM_SCORE
          The maximum non-bust score for a hand
 
Fields inherited from class com.amoebacode.blackjack.core.CardCollection
cards
 
Fields inherited from class com.amoebacode.blackjack.core.GameObject
listeners, parent
 
Constructor Summary
protected Hand(IParticipant participant)
          Default public constructor.
 
Method Summary
 void addCard(ICard card)
          Adds the specified card to this collection and notifies the GUI listeners.
 void clear()
          Removes this hand from the table and notifies the GUI listeners.
 int getBestTotal()
          Returns the best score for this hand (the highest non-busting score).
 int getBestTotal(int cardIndex)
          Returns the best score for this hand (the highest non-busting score), not including cards beyond the specified index.
 java.lang.String getCurrentScore(int cardIndex)
          Returns a displayable current score (or "busted" if this hand has busted), not including cards beyond the specified index.
protected  HandEventListenerCollection getHandEventListenerCollection()
          Returns the event listener collection for this hand.
 int getHardTotal()
          Returns the hard score for this hand (the sum of all card hard scores).
protected  int getHardTotal(int cardIndex)
          Returns the hard score for this hand (the sum of all card hard scores), not including cards beyond the specified index.
protected  IHouseRules getHouseRules()
          Returns the casino options manager.
private static int getMaximumSafeHitScore()
          Returns the maximum hand score that is safe to hit.
protected  IRound getRound()
          Returns the current round this hand belongs to.
 int getSoftTotal()
          Returns the soft score for this hand (the sum of all card soft scores).
protected  int getSoftTotal(int cardIndex)
          Returns the soft score for this hand (the sum of all card soft scores), not including cards beyond the specified index.
protected abstract  java.lang.String getTotalLabel()
          Returns the prefix for the current score label (for example, "Score:").
 boolean hasBlackjack()
          Indicates whether this hand has blackjack.
 boolean hasBusted()
          Indicates whether this hand has busted.
protected  boolean hasMaximumNumberOfCards()
          Indicates whether this hand has the maximum number of cards.
protected  boolean hasMaximumScore()
          Indicates whether this hand has the maximum score.
 boolean hasPair()
          Indicates whether this hand contains a pair of matching scores.
 boolean hasSoftTotal()
          Indicates whether this hand has a soft total
 void hit()
          Adds a card from the deck to this hand and begins its animation.
private  boolean shouldUseMixedTotal(int cardIndex)
          Indicates whether the optimal score involves mixing soft and hard scores.
 
Methods inherited from class com.amoebacode.blackjack.core.CardCollection
getCardAt, getNextCard, getNumberOfCards, setCards
 
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.ICardCollection
getCardAt, getNextCard, getNumberOfCards, setCards
 
Methods inherited from interface com.amoebacode.blackjack.core.IGameObject
addEventListener, getGame, getParent
 

Field Detail

MAXIMUM_NUMBER_OF_CARDS

private static final int MAXIMUM_NUMBER_OF_CARDS
The maximum number of cards per hand

MAXIMUM_SCORE

protected static final int MAXIMUM_SCORE
The maximum non-bust score for a hand

MAXIMUM_HARD_CARD_SCORE

private static final int MAXIMUM_HARD_CARD_SCORE
The maximum hard score for a single card
Constructor Detail

Hand

protected Hand(IParticipant participant)
Default public constructor.
Parameters:
participant - the participant that owns this hand
Method Detail

getHandEventListenerCollection

protected HandEventListenerCollection getHandEventListenerCollection()
Returns the event listener collection for this hand.
Returns:
this object's HandEventListenerCollection

getTotalLabel

protected abstract java.lang.String getTotalLabel()
Returns the prefix for the current score label (for example, "Score:").
Returns:
the String prefix for the current score label

getSoftTotal

public int getSoftTotal()
Description copied from interface: IHand
Returns the soft score for this hand (the sum of all card soft scores).
Specified by:
getSoftTotal in interface IHand
See Also:
IHand.getSoftTotal()

getSoftTotal

protected int getSoftTotal(int cardIndex)
Returns the soft score for this hand (the sum of all card soft scores), not including cards beyond the specified index.
Parameters:
cardIndex - the last card in this hand to include in the soft score
Returns:
the soft total

getHardTotal

public int getHardTotal()
Description copied from interface: IHand
Returns the hard score for this hand (the sum of all card hard scores).
Specified by:
getHardTotal in interface IHand
See Also:
IHand.getHardTotal()

getHardTotal

protected int getHardTotal(int cardIndex)
Returns the hard score for this hand (the sum of all card hard scores), not including cards beyond the specified index.
Parameters:
cardIndex - the last card in this hand to include in the hard score
Returns:
the hard total

getBestTotal

public int getBestTotal()
Description copied from interface: IHand
Returns the best score for this hand (the highest non-busting score).
Specified by:
getBestTotal in interface IHand
See Also:
IHand.getBestTotal()

getBestTotal

public int getBestTotal(int cardIndex)
Description copied from interface: IHand
Returns the best score for this hand (the highest non-busting score), not including cards beyond the specified index.
Specified by:
getBestTotal in interface IHand
See Also:
IHand.getBestTotal(int)

shouldUseMixedTotal

private boolean shouldUseMixedTotal(int cardIndex)
Indicates whether the optimal score involves mixing soft and hard scores.
Returns:
true if the optimal score mixes soft and hard scores

getCurrentScore

public java.lang.String getCurrentScore(int cardIndex)
Description copied from interface: IHand
Returns a displayable current score (or "busted" if this hand has busted), not including cards beyond the specified index.
Specified by:
getCurrentScore in interface IHand
See Also:
IHand.getCurrentScore(int)

hasBusted

public boolean hasBusted()
Description copied from interface: IHand
Indicates whether this hand has busted.
Specified by:
hasBusted in interface IHand
See Also:
IHand.hasBusted()

hasMaximumNumberOfCards

protected boolean hasMaximumNumberOfCards()
Indicates whether this hand has the maximum number of cards.
Returns:
true if this hand has the maximum number of cards

hasMaximumScore

protected boolean hasMaximumScore()
Indicates whether this hand has the maximum score.
Returns:
true if this hand has the maximum score

hit

public void hit()
Description copied from interface: IHand
Adds a card from the deck to this hand and begins its animation.
Specified by:
hit in interface IHand
See Also:
IHand.hit()

addCard

public void addCard(ICard card)
Description copied from interface: ICardCollection
Adds the specified card to this collection and notifies the GUI listeners.
Specified by:
addCard in interface ICardCollection
Overrides:
addCard in class CardCollection
See Also:
ICardCollection.addCard(ICard)

hasBlackjack

public boolean hasBlackjack()
Description copied from interface: IHand
Indicates whether this hand has blackjack.
Specified by:
hasBlackjack in interface IHand
See Also:
IHand.hasBlackjack()

hasPair

public boolean hasPair()
Description copied from interface: IHand
Indicates whether this hand contains a pair of matching scores.
Specified by:
hasPair in interface IHand
See Also:
IHand.hasPair()

getMaximumSafeHitScore

private static int getMaximumSafeHitScore()
Returns the maximum hand score that is safe to hit.
Returns:
the maximum safe hit score

hasSoftTotal

public boolean hasSoftTotal()
Description copied from interface: IHand
Indicates whether this hand has a soft total
Specified by:
hasSoftTotal in interface IHand
See Also:
IHand.hasSoftTotal()

clear

public void clear()
Description copied from interface: IHand
Removes this hand from the table and notifies the GUI listeners.
Specified by:
clear in interface IHand
See Also:
IHand.clear()

getRound

protected IRound getRound()
Returns the current round this hand belongs to.
Returns:
the current IRound

getHouseRules

protected IHouseRules getHouseRules()
Returns the casino options manager.
Returns:
the HouseRules object

Blackjack

Copyright © 2002 amoebacode.com.