Please send questions to st10@humboldt.edu .
//--------------------------------------------------
// implement a class Dice, representing a
//    dice that can be randomly rolled as
//    desired.
//
// adapted from Astrachan, "A Computer Science Tapestry", 
//    2nd edition,
//    McGraw Hill, pp. 214, 217
//
// adapted by: Sharon M. Tuttle 
// last modified: 10-15-03
//******************************************************

//#include <cmath>
#include "Dice.h"
#include "randgen.h"
using namespace std;

// constructors
Dice::Dice(int nSides)
{
    numSides = nSides;
    numRolls = 0;
}

// if NO number of sides is given --- assume a
//    6-sided die is desired.
Dice::Dice()
{
    numSides = STD_NUM_SIDES;
    numRolls = 0;
}

// accessor functions
int Dice::get_numSides() const
{
    return numSides;
}
        
int Dice::get_numRolls() const
{
    return numRolls;
}

// mutator functions
void Dice::set_numSides(int newNumSides)
{
    numSides = newNumSides;
}

// additional public member functions

//---------------------------------------------
// Contract: roll : void -> int
// Purpose: returns a pseudo-random roll
//          of this numSides-sided dice
//          instance, returning a value
//          between 1 and numSides (or,
//          in the interval [1, numSides] )
//
// Examples: (OK, being random, this is tricky!)
//          for a Dice instance:
//             Dice myDie(3);
//          myDie.roll() will return 1, 2, or 3
//----------------------------------------------
int Dice::roll()
{
    RandGen gen; // random number generator

    numRolls++;              // update # of times die rolled
    return gen.RandInt(1, numSides); // in range (1..mySides)
}