Class Player

java.lang.Object
  |
  +--Player

public class Player
extends java.lang.Object

Represents a player in this simplified version of the "21" card game.

Version:
0
Author:
David Matuszek, (Students: replace this with your name)

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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

game

Game game
The Game object.

name

java.lang.String name
The name of the player (used for printing purposes).

passed

public boolean passed
Set to true when the player passes.

sumOfVisibleCards

public int sumOfVisibleCards
The sum of the player's cards, not counting the hidden card.
Constructor Detail

Player

public Player(java.lang.String name,
              Game game)
Constructs a player with the given name, in the given game. The Game object is passed in and saved in an instance variable because the player needs to access game information.
Parameters:
name - the name to be given to this player.
game - a reference to the Game that the player is involved in.
Method Detail

getScore

int getScore()
Return this player's score (the total of all this player's cards).

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.

Returns:
the total of the cards in this player's hand.

play

void play()
Decides whether to ask the Dealer for another card or to pass. (Passing is accomplished by setting the public variable 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.

takeCard

void takeCard(int card,
              boolean hidden)
Takes a card and puts it in this player's hand. The card may be either the "hidden" card or one of the visible cards.
Parameters:
card - the card received from the dealer.
hidden - true if the card is dealt face down.


Generated by BlueJ