ASDV-Cpp/Assignments/MP5_CalebFontenot/Die.cpp

37 lines
867 B
C++

//
// Created by caleb on 4/19/24.
//
#include <ctime>
#include <cstdlib>
#include "Die.h"
Die::Die(int numSides) { // Constructor
unsigned seed = std::time(0);
std::srand(seed);
sides = numSides;
roll();
}
void Die::roll() { // Rolls the die
const int MIN_VALUE = 1;
value = (rand() % (sides - MIN_VALUE + 1)) + MIN_VALUE;
}
int Die::getSides() const { // Returns the number of die sides
return sides;
}
int Die::getValue() const { // Returns the die's value
return value;
}
int Die::compareTo(Die other) {
if (this->getValue() > other.getValue()) {
return -1;
} else
if (this->getValue() == other.getValue()) {
return 0;
} else
if (this->getValue() < other.getValue()) {
return 1;
}
// code should never reach here
return -69420;
}