com.gbayer.basicblackjack
Class Player

java.lang.Object
  extended by com.gbayer.basicblackjack.Player
Direct Known Subclasses:
ComputerDealer, HumanPlayer

public abstract class Player
extends java.lang.Object

A Player has a name assigned, holds a Hand of Cards, and is capable of taking actions.


Nested Class Summary
static class Player.Action
          Action a player can take (or be forced to take).
 
Constructor Summary
Player(java.lang.String name)
          Instantiates a new player.
 
Method Summary
 void dealCard(Card card)
          Deal card to player.
 Hand getHand()
          Gets the player's hand.
 java.lang.String getName()
          Gets the player's assigned name.
 void newHand()
          Clear all cards in hand.
abstract  Player.Action takeAction(UI ui)
          Player takes one or more permitted actions.
 java.lang.String toString()
          Generates a string containing player's assigned name concatenated with a string representing the player's hand.
 java.lang.String toStringShowingTopCardOnly()
          Generates a string containing player's assigned name concatenated with a string representing the player's hand with all but the first card face-down.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Player

public Player(java.lang.String name)
Instantiates a new player.

Parameters:
name - the name
Method Detail

newHand

public void newHand()
Clear all cards in hand. Hand will be empty. Underlying data structure is reused.


dealCard

public void dealCard(Card card)
Deal card to player. Card is placed in hand.

Parameters:
card - the card

getName

public java.lang.String getName()
Gets the player's assigned name.

Returns:
the name

getHand

public Hand getHand()
Gets the player's hand.

Returns:
the hand

toString

public java.lang.String toString()
Generates a string containing player's assigned name concatenated with a string representing the player's hand.

Overrides:
toString in class java.lang.Object
Returns:
the string

toStringShowingTopCardOnly

public java.lang.String toStringShowingTopCardOnly()
Generates a string containing player's assigned name concatenated with a string representing the player's hand with all but the first card face-down.

Returns:
the string

takeAction

public abstract Player.Action takeAction(UI ui)
Player takes one or more permitted actions.

Parameters:
ui - the user interface
Returns:
Action action taken by player