/**
* Die.java
*
* This class represents a single six-sided die, possibly for
* use in game programs such as Yahtzee, craps, etc.
*
* Modification history:
* 1/15/02 (Jeff Ondich) Started
* 1/16/02 (JO) Added drawing routines and javadoc comments.
* 9/27/05 (JO) Updated to use Canvas class
*
* @author Jeff Ondich
*/
import java.awt.*;
class Die
{
private int nSides;
private int value;
private int edgeLength;
private Color edgeColor;
private Color dotColor;
/**
* This default constructor sets up reasonable starting values. Note
* in particular that the six-sidedness of the die is enforced
* here.
*/
public Die()
{
nSides = 6;
value = 1;
edgeLength = 100;
edgeColor = Color.green;
dotColor = Color.black;
}
/**
* This constructor allows you to initialize the value and the
* lengths of the edges of the square that is drawn by the
* draw
method. Note that nSides is set to 6.
*
* @param val The numerical value displayed on the die.
* @param edge The length, in pixels, of each of the sides of the die.
* @param eColor The color of the edges of the die.
* @param dColor The color of the dots on the face of the die.
*/
public Die( int val, int edge, Color eColor, Color dColor )
{
nSides = 6;
if( val >= 1 && val <= nSides )
value = val;
else
value = 1;
if( edge > 0 )
edgeLength = edge;
else
edgeLength = 100;
edgeColor = eColor;
dotColor = dColor;
}
/**
* Returns the current value of the die.
*/
public int getValue()
{
return value;
}
/**
* Sets the current value of the die if newValue
is legal.
*/
public void setValue( int newValue )
{
if( newValue >= 1 && newValue <= nSides )
value = newValue;
}
/**
* Sets the color of the square drawn by the draw
method.
*/
public void setEdgeColor( Color newEdgeColor )
{
System.out.println( "Die.setColor stub" );
}
/**
* Sets the color of the dots drawn by the draw
method.
*/
public void setDotColor( Color newDotColor )
{
System.out.println( "Die.setDotColor stub" );
}
/**
* Sets value
to a random integer between 1 and 6.
*/
public void roll()
{
System.out.println( "Die.roll stub" );
}
/**
* Draws the die on the given Canvas.
* The colors of the die are specified by edgeColor
* and dotColor
.
*
* @param canvas The Canvas object on which to draw the die.
* @param x The x-coordinate of the upper left corner of the die's square.
* @param y The y-coordinate of the upper left corner of the die's square.
*/
public void draw( Canvas canvas, int x, int y )
{
System.out.println( "Die.draw stub" );
}
}