forked from AlexCampbell/Risk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Battle.cpp
185 lines (145 loc) · 4.02 KB
/
Battle.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <iostream>
#include <vector>
#include <algorithm>
#include "battle.h"
#include "DiceRoll.h"
#include "get_int.h"
using namespace std;
Battle::Battle() {
}
DiceRoll myDiceroll;
int CheckResults(int i){
if (i == 1)
std::cout << "Two lost on Denfense" << std::endl;
if (i == 2)
std::cout << "One lost on Both Sides" << std::endl;
if (i == 3)
std::cout << "Two lost on Attack" << std::endl;
if (i == 4)
std::cout << "One lost on Defense" << std::endl;
if (i == 5)
std::cout << "One lost on Attack" << std::endl;
if (i == 0)
std::cout << "Something Asploded" << std::endl;
return i;
}
int CheckArmies(int A, int D){
int AtkRoll = myDiceroll.GetAtkArmies(A);
int DefRoll = myDiceroll.GetDefArmies(D);
int i = myDiceroll.Roll(AtkRoll, DefRoll);
int v = CheckResults(i);
return v;
}
int GetTotalA(){
int attack;
do {
std::cout << "How many units are in the attakers country: ";
attack = get_int();
if(attack == INT_MIN) {
std::cout << "You did not input a number. Try again." << std::endl;
}
} while (attack == INT_MIN);
}
int GetTotalD(){
int defense;
do {
std::cout << "How many units are in the defenders country: ";
defense = get_int;
if(defense == INT_MIN) {
std::cout << "You did not input a number. Try again." << std::endl;
}
} while (attack == INT_MIN);
return defense;
}
int Battle::Results(std::vector<int>& Atkroll, std::vector<int>& Defroll) {
if (Atkroll.size() == 3) {
if (Defroll.size() == 2) {
if (Atkroll[2] > Defroll[1]) {
if (Atkroll[1] > Defroll[0])
return 1;
else
return 2;
} else if (Atkroll[2] <= Defroll[1]) {
if (Atkroll[1] <= Defroll[0])
return 3;
else
return 2;
}
} else if (Defroll.size() == 1) {
if (Atkroll[2] > Defroll[0])
return 4;
else
return 5;
}
}
if (Atkroll.size() == 2) {
if (Defroll.size() == 2)
if (Atkroll[1] > Defroll[1]) {
if (Atkroll[0] > Defroll[0])
return 1;
else
return 2;
} else if (Atkroll[1] <= Defroll[1]) {
if (Atkroll[0] <= Defroll[0])
return 3;
else
return 2;
} else if (Defroll.size() == 1) {
if (Atkroll[1] > Defroll[0])
return 4;
else
return 5;
}
}
if (Atkroll.size() == 1) {
if (Defroll.size() == 2)
if (Atkroll[0] > Defroll[1])
return 4;
else
return 5;
else if (Defroll.size() == 1) {
if (Atkroll[0] > Defroll[0])
return 4;
else
return 5;
}
}
return 0;
}
int BattleControl(){
restart:
int A = GetTotalA();
int D = GetTotalD();
reroll:
int v = CheckArmies(A, D);
if (v == 1){
D -= 2;}
if (v == 2){
A -= 1;
D -= 1;}
if (v == 3){
A -= 2;}
if (v == 4){
D -= 1;}
if (v == 5){
A -= 1;}
std::cout << " Total Remaining Units for Attack: " << A << std::endl;
std::cout << " Total Remaining Unites for Defense: " << D << std::endl;
if (A == 1){
std::cout << "Attackers are out of Units" << std::endl;}
if (D == 0){
std::cout << "Attackers Win!" << std::endl;
}
reanw:
int anw;
std::cout << " Do You Want to Play Again?" << std::endl;
anw = get_int();
if ((anw == 1) && (A != 1) && (D != 0)){
goto reroll;}
if (anw == (1) && ((A == 1) || (D == 0))){
std::cout << "Can't Reroll. Please quit or restart." << std::endl;
goto reanw;}
if (anw == 0){
goto restart;}
return 0;
};