java.lang.Object | +--Player
Represents a player in this simplified version of the "21" card game.
| Field Summary | |
(package private) Game |
game
The Game object. |
(package private) java.lang.String |
name
The name of the player (used for printing purposes). |
boolean |
passed
Set to true when the player passes. |
int |
sumOfVisibleCards
The sum of the player's cards, not counting the hidden card. |
| Constructor Summary | |
Player(java.lang.String name,
Game game)
Constructs a player with the given name, in the given game. |
|
| Method Summary | |
(package private) int |
getScore()
Return this player's score (the total of all this player's cards). |
(package private) void |
play()
Decides whether to ask the Dealer for another card or to pass. |
(package private) void |
takeCard(int card,
boolean hidden)
Takes a card and puts it in this player's hand. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
Game game
java.lang.String name
public boolean passed
public int sumOfVisibleCards
| Constructor Detail |
public Player(java.lang.String name,
Game game)
name - the name to be given to this player.game - a reference to the Game that the player is involved in.| Method Detail |
int getScore()
Note: The way this program is organized, there is nothing to prevent another player from calling this routine to "cheat." Please don't do so. There are various ways to prevent cheating, but they all add complexity that we don't need in a program this small.
void play()
passed to true.)
In making the decision, this player may examine his own hidden
and visible cards, the visible cards of other players, and which
players have already passed.
Note: All Players use the same decision algorithm, as
given in this method.
void takeCard(int card,
boolean hidden)
card - the card received from the dealer.hidden - true if the card is dealt face down.