forked from ChicoState/GameDie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameDie.cpp
More file actions
46 lines (40 loc) · 961 Bytes
/
GameDie.cpp
File metadata and controls
46 lines (40 loc) · 961 Bytes
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
#include "GameDie.h"
#include <vector>
#include <cstdlib>
#include <ctime>
//class constructor that seeds the random number generator
GameDie::GameDie()
{
srand(time(NULL));
roll_counter.resize(FACES);
for(int i=0; i<FACES; i++)
roll_counter[i] = 0;
}
//overloaded constructor
GameDie::GameDie(unsigned int num)
{
if( num == 0 )
{
roll_counter.resize(FACES);
}
else{
roll_counter.resize(num);
}
for(int i=0; i<FACES; i++)
{
roll_counter[i] = 0;
}
}
//generate a random number between 1-n where n is the counter size
// (inclusive) and return it
int GameDie::roll()
{
int roll = rand() % roll_counter.size();
roll_counter[roll]++;
return roll + 1;
}
// return the count of how many times each face has been rolled, as a vector
// where each face's count is at index face-1 (i.e. Face 1 is at index 0)
vector <int> GameDie::get_distribution(){
return roll_counter;
}