Class YahtzeeDisplay

java.lang.Object
  |
  +--YahtzeeDisplay

public class YahtzeeDisplay

The YahtzeeDisplay class provides the methods you need to control the display. You should look at the descriptions of all the methods in this documentation and familiarize yourself with their operation.


Constructor Summary
YahtzeeDisplay(GCanvas gc, String[] playerNames)
Creates a new YahtzeeDisplay object that adds its objects to the GCanvas specified by gc.
 
Method Summary
void displayDice(int[] dice)
Draws the pictures of the dice on the screen.
boolean isDieSelected(int index)
Checks to see whether the die specified by index is selected.
void printMessage(String message)
Prints a message on the bottom of the Yahtzee scorepad.
void updateScorecard(int category, int player, int score)
Updates a value on the Yahtzee scorecard.
void waitForPlayerToClickRoll(int player)
Waits for the player to click the "Roll Dice" button to start the first dice roll.
int waitForPlayerToSelectCategory()
Allows the user to select a category in which to place the score for this roll.
void waitForPlayerToSelectDice()
Allows the player to select which dice to reroll by clicking on the dice with the mouse.
 

Constructor Detail

public YahtzeeDisplay(GCanvas gc, String[] playerNames)

Creates a new YahtzeeDisplay object that adds its objects to the GCanvas specified by gc. The playerNames parameter is an array consisting of the names of the players.

 
Usage: YahtzeeDisplay display = new YahtzeeDisplay(gc, playerNames); 
Parameters: 
gc  The GCanvas on which the board is displayed
playerNames  An array of strings containing the player names
 
Method Detail

public void displayDice(int[] dice)

Draws the pictures of the dice on the screen. You pass one parameter, a zero-based integer array with N_DICE entries, that contains the values to draw on the dice. Each value in the array must be a valid die roll between 1 and 6; if not, displayDice will throw an ErrorException. You will need to call this method after each roll or reroll of the dice to display the new random values.

 
Usage: display.displayDice(dice); 
Parameter: 
dice  An array of dice values, whose indices range from 0 to N_DICE - 1
 

public boolean isDieSelected(int index)

Checks to see whether the die specified by index is selected. You call this method before each reroll to determine whether this die needs to be updated.

 
Usage: if (display.isDieSelected(index)) . . . 
Parameter: 
index  The index number of the die, which ranges from 0 to N_DICE - 1
Returns: true if the die is selected, and false otherwise
 

public void printMessage(String message)

Prints a message on the bottom of the Yahtzee scorepad. The old message is cleared whenever any YahtzeeDisplay method is called.

 
Usage: display.printMessage(message); 
Parameter: 
message  The message string to display
 

public void updateScorecard(int category, int player, int score)

Updates a value on the Yahtzee scorecard. You must call this method once each turn after the player has finished rolling and has chosen the category in which to score the result. The parameters to the method are the index of the category (which will be one of the constants defined in YahtzeeConstants), the player number, and the score to be displayed in that cell of the scorecard.

 
Usage: display.updateScorecard(category, player, score); 
Parameters: 
category  The category number to update
player  The player number (between 1 and nPlayers)
score  The score to display in that box
 

public void waitForPlayerToClickRoll(int player)

Waits for the player to click the "Roll Dice" button to start the first dice roll. You will call this method once at the beginning of each player's turn. The parameter is the index number of the player, which ranges from 1 to nPlayers, where nPlayers is the number of players in the game. The method highlights the player's name in the scorecard, erases any dice displayed from previous rolls, draws the "Roll Dice" button, and then waits for the player to click the button. This method returns when the button is pressed. At that point, it is your job to randomly roll the dice and call the displayDice method.

 
Usage: display.waitForPlayerToClickRoll(player); 
Parameter: 
player  The index of the player, ranging from 1 to nPlayers
 

public int waitForPlayerToSelectCategory()

Allows the user to select a category in which to place the score for this roll. You will call this method once each turn after the player finishes rolling the dice. As its name suggests, the method waits for the player to click on one of the categories and returns the index of the category, which will be one of the constants defined in YahtzeeConstants.

Note that this method does not check to see whether the category is valid for the dice values or whether this category has already been used by this player. Thus, you will need to include some error-checking in your program to test the result of waitForPlayerToSelectCategory before you try to update the scorecard.


 
Usage: int category = display.waitForPlayerToSelectCategory(); 
Returns: The category number selected by the player
 

public void waitForPlayerToSelectDice()

Allows the player to select which dice to reroll by clicking on the dice with the mouse. You will call this method twice each player turn, giving them two additional chances to improve their roll. This method draws the "Roll Again" button, and waits for the player to click on the dice to select and deselect which ones they would like to reroll. The method returns only after the player has made a selection and clicks the "Roll Again" button. Once the method returns, you can use the isDieSelected method to determine whether the die should be rerolled.

 
Usage: display.waitForPlayerToSelectDice();