-
Notifications
You must be signed in to change notification settings - Fork 0
/
die.cc
51 lines (43 loc) · 839 Bytes
/
die.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "die.h"
using namespace std;
//Constructors
Die::Die(){ //default 6 sides
numSides = 6;
srand(time(NULL));
faceValue = rand() % numSides + 1;
}
Die::Die(int newNumSides){
if (newNumSides > 1) {
numSides = newNumSides;
}
else {
numSides = 6;
}
srand(time(NULL));
faceValue = rand() % numSides + 1;
}
//setters
void Die::setNumSides(int newNumSides){
if (newNumSides > 1) {
numSides = newNumSides;
}
}
//getters
int Die::getFaceValue(){
return faceValue;
}
int Die::getNumSides(){
return numSides;
}
//helper functions
int Die::roll(){
faceValue = rand() % numSides + 1;
return faceValue;
}
ostream& operator <<(ostream &out, const Die &d){
out << d.faceValue;
return out;
}