Class DiceGame

java.lang.Object
  extended by DiceGame

public class DiceGame
extends java.lang.Object


Constructor Summary
DiceGame(Player human, Player cpu)
          Constructs a new DiceGame between two given players.
 
Method Summary
 boolean gameOver()
          Returns true if the game is over.
 void playTurn()
          Plays a single turn.
 void printInfo()
          Prints information about the state of the game, as a string of one of the following forms: It is turn 0.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiceGame

public DiceGame(Player human,
                Player cpu)
Constructs a new DiceGame between two given players.

Parameters:
human - a Player representing the human player
cpu - a Player representing the computer player
Method Detail

printInfo

public void printInfo()
Prints information about the state of the game, as a string of one of the following forms:


playTurn

public void playTurn()
Plays a single turn. If the game is over (as indicated by gameOver()), this shall have no effect. Otherwise, it will:
  1. Print the state of the game, using printInfo()
  2. Prompt the human player for a bet amount (which must be less than or equal to both the human player's purse and the computer player's purse.) Assume that the bet amount is a valid integer value.
  3. Roll three dice for the computer player up to five times until a scoring combination is reached, printing the results of each roll on a separate line as a string of one of the following forms:
    • ** PLAYER NAME rolled a 1 4 5 on try 1. This is not a scoring combination!
    • ** PLAYER NAME rolled a 2 2 2 on try 4. This is worth 8 points.

    If the computer player does not reach a scoring combination in five tries, print *** Tries up for PLAYER NAME!
  4. Roll three dice for the human player up to five times until a scoring combination is reached, printing information as above.
  5. If one player wins, transfer money from the losing Player to the winning Player and print a string of the form * PLAYER NAME wins $15 on turn 42.
  6. If there is a tie, print a message of the following form: * This turn resulted in a tie.
  7. Increment the turn count.


gameOver

public boolean gameOver()
Returns true if the game is over. The game is over when either player is out of money.

Returns:
true if the game is over (i.e. one player is out of money) or false otherwise