forked from AlexCampbell/Risk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiceRoll.cpp
72 lines (57 loc) · 1.51 KB
/
DiceRoll.cpp
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
#include <iostream>
#include <time.h>
#include <vector>
#include "DiceRoll.h"
#include "Sorter.h"
#include "get_int.h"
using namespace std;
Sorter mySorter;
DiceRoll::DiceRoll() {
}
namespace atk {
int roll;
}
namespace def {
double roll;
}
int DiceRoll::GetDefArmies(int D) {
if (D > 1)
def::roll = 2;
else if (D == 1)
def::roll = 1;
return def::roll;
}
int DiceRoll::GetAtkArmies(int A) {
do {
cout << "How Many Units is the Attacker using?: ";
do {
cout << "How Many Units is the Attacker using?: ";
atk::roll = get_int();
if(atk::roll == INT_MIN) {
\cout << "You did not input a number, try again." << endl;
}
else if (atk::roll >= A) {
if ((atk::roll - A) <= 0) {
cout << "Sorry, there needs to be at least one left. Try again." << endl;
continue;
} else {
cout << "Sorry, you do not have enough. Try Again " << endl;
continue;
}
} else
break;
} while (true);
return atk::roll;
}
int DiceRoll::Roll(int atk, int def) {
vector<int> aroll;
vector<int> droll;
srand (time(NULL));
for (size_t i = 0; i < atk; ++i)
aroll.push_back ((rand() % 6)+1);
cout << "Attacker Rolls: " << aroll << endl;
for (size_t i = 0; i < def; ++i)
droll.push_back ((rand() % 6)+1);
cout << "Defenders Rolls: " << droll << endl;
return mySorter.asorter(aroll, droll);
}