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
73 lines (66 loc) · 1.3 KB
/
GameDie.cpp
File metadata and controls
73 lines (66 loc) · 1.3 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "GameDie.h"
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
using namespace std;
// class constructor that seeds the random number generator
GameDie::GameDie()
{
srand(time(NULL));
<<<<<<< HEAD
for (int i = 0; i < SIDES; i++)
counter[i] = 0;
=======
for(int i=0; i<FACES; i++)
counter[i] = 0;
>>>>>>> 6874c1fb4404664abbf2f823d682d3829168f9d4
}
GameDie::GameDie(unsigned int val)
{
if (val > 0)
{
for (int i = 0; i < val; i++)
{
counter[i] = 0;
}
}
else
{
if (val == 0)
{
for (int i = 0; i < 6; i++)
{
counter[i] = 0;
}
}
else
{
cout << "Enter a positive number of sides!!!" << endl;
}
}
}
// generate a random number between 1-6 (inclusive) and return it
int GameDie::roll()
{
int roll = rand() % FACES;
counter[roll]++;
return roll + 1;
}
vector<int> GameDie::get_distribution()
{
vector<int> roll_sides_v;
int roll_value = roll();
for (int i = 0; i < 6; i++)
{
if (i == roll_value - 1)
{
roll_sides_v.push_back(1);
}
else
{
roll_sides_v.push_back(0);
}
}
return roll_sides_v;
}