Yahtzee Design

public class Yahtzee extends WindowController

Instance Variables

// Instance variables for the 5 dice
private Die die1;
private Die die2;
private Die die3;
private Die die4;
private Die die5;

// Instance variables associated with dragging of the dice
private boolean pressedOn = false;
private Location lastPoint;
private Die selectedDie;

// Instance variables associated with the buttons
private FramedRect rerollButton;
private FramedRect doneButton;

// Instance variable to count the number of dice rolls
private int rollCount;

Part A

Method Name

Type of value returned

Parameters and (types)

Description

begin

none

none

Method called at the start of the program to initialize the
5 dice and buttons.


Part B

Method Name

Type of value returned

Parameters and (types)

Description

onMouseClick

none

point (Location)

Method called when the mouse is clicked. It checks to see if the click occurred within a button, so appropriate actions can be performed.

roll

none

none

Randomly changes the die value to a new value between 1 and 6

getRoll

int

none

Returns the current die value


Part C

Method Name

Type of value returned

Parameters (and their types)

Description

onMousePress

none

point (Location)

Method called when the mouse button is pressed. If the mouse button is pressed on a die, remember that it was selected (and its location) so that it can be dragged correctly.

onMouseDrag

none

point (Location)

Method called periodly as the mouse is being dragged. If a die was selected, move it to the new mouse location.

onMouseRelease

none

point (Location)

Method called when the mouse button is released. It "unsets" the flag (pressedOn instance variable) that indicates if the mouse was pressed.