/**
    A GameDie object represents a single game die.

    It has a set number of sides, each numbered from 1
        to the number of sides, and it can be rolled,
        which results in a number between 1 and the number
        of sides.

    Adapted from Astrachan's "A Computer Science Tapestry"
        2nd edition, pp. 214, 217.

    Compile using:
        javac GameDie.java
    (but cannot execute by "itself" - no main method!)

    @author Owen Astrachan
    @author adapted by: Sharon Tuttle
    @version 2021-08-28
 */

public class GameDie
{
    // data fields

    private int numSides;
    private int currTop;

    private static final int DEFAULT_NUM_SIDES = 6;

    /**
     * construct a new die with the default number of sides, 6,
     *    and an initial top value of 1
     */

    public GameDie()
    {
        numSides = DEFAULT_NUM_SIDES;
        currTop = 1;
    }

    /**
     * construct a new die with the user-specified number of sides
     *    and an initial top value of 1
     *
     * @param desiredNumSides number of sides for this die
     */

    public GameDie(int desiredNumSides)
    {
        numSides = desiredNumSides;
        currTop = 1;
    }

    /**
     * return the calling die's number of sides
     *
     * @return number of sides of calling die
     */

    public int getNumSides()
    {
        return numSides;
    }

    /**
     * return the die's current top value
     *
     * @return current top value of the calling die
     */

    public int getCurrTop()
    {
        return currTop;
    }

    /**
        expects nothing, computes a pseudo-random int in
            [1, num_sides], changes currTop of the calling GameDie
            to that computed value, and also returns that computed
            value as the result of this call to roll

        @return the value of this roll of the calling die
     */

    public int roll()
    {
        currTop = (int) ((Math.random() * numSides) + 1.0);
        return currTop;
    }
}