-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
227 lines (196 loc) · 6.8 KB
/
Functions.cpp
File metadata and controls
227 lines (196 loc) · 6.8 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "Dice.h"
#include "Creature.h"
#include "Reptile.h"
#include "BlueM.h"
#include "Barbarian.h"
#include "Goblin.h"
#include "Shadow.h"
#include<iostream>
#include<string>
#include<vector>
/****************************************************************************
* void statistics(std::string player, std::vector<int> &oneWin, std::vector<int> & twoWin)
*
* Purpose: Keeps track of who wins each match and performs an equation to give the
* percentage of times each player wins
* Entry: A string for the player and a vector for each possible winner
* Exit: Returns vectors by reference
* ***********************************************************************/
void statistics(std::string player, std::vector<int> &oneWin, std::vector<int> &twoWin)
{
double total = 0;
if(player == "one")
oneWin.push_back(1);
if(player == "two")
twoWin.push_back(1);
total = oneWin.size() + twoWin.size();
if(oneWin.size() == 0)
std::cout << "\nPlayer Two wins 100 percent of the time." << std::endl;
if(twoWin.size() == 0)
std::cout << "\nPlayer One wins 100 percent of the time." << std::endl;
else{
std::cout << "\nPlayer One wins: " << (oneWin.size() / total) * 100 << " percent of the time." << std::endl;
std::cout << "Player Two wins: " << (twoWin.size() / total) * 100 << " percent of the time." << std::endl;}
}
/****************************************************************************
* void fight(Creature* one, Creature* two, std::vector<int> &oneWin, std::vector<int> & twoWin, int &game)
*
* Purpose: Performs the fight sequence between classes. Changes who is fighting based off both turns and
* game number.
* Entry: Two contestants, two vectors for tracking who wins, and the game number
* Exit: Returns vectors by reference to the statistic function, and game amount by reference
* ***********************************************************************/
void fight(Creature* one, Creature* two, std::vector<int> &oneWin, std::vector<int> &twoWin, int &game)
{
int val;
int turn = 0;
// int returned;
bool over = false;
bool flagTwo = false;
bool flag = false;
std::string player;
if(game % 2 == 0){
do{
if(turn % 2 == 0){
player = "one";
std::cout << "\n";
std::cout << one->getType() << " " << player << " is attacking" << std::endl;
if(one->getType() == "Goblin" && two->getType() != "Goblin")
one->attack(flag);
else
one->attack();
two->defense();
// test for a hit and set damage
if(one->getAttVal() <= two->getDefVal()){
std::cout << "The attack is a miss!" << std::endl;
one->setDmg(0);}
else{
std::cout << "The attack is successful!" << std::endl;
if(flagTwo == false)
val = one->getAttVal() - two->getDefVal();
else
val = (one->getAttVal() / 2) - two->getDefVal();
two->setDmg(val);
if(two->getDmg() == 0)
std::cout << "Armor absorbed the attack!" << std::endl;
else
std::cout << two->getDmg() << " points of damage!" << std::endl;
two->setSP();
if(two->getSP() <= 0 )
std::cout << "GAME OVER!" << std::endl;
else
std::cout << "Only " << two->getSP() << " Strength Points left!" << std::endl;}
// Check for end game
if(one->getSP() <= 0 || two->getSP() <= 0){
over = true;
statistics(player, oneWin, twoWin);}
turn++;}
else{
player = "two";
std::cout << "\n";
std::cout << two->getType() << " " << player << " is attacking" << std::endl;
if(two->getType() == "Goblin" && one->getType() != "Goblin")
two->attack(flagTwo);
else
two->attack();
one->defense();
// test for a hit and set damage
if(two->getAttVal() <= one->getDefVal()){
std::cout << "The attack is a miss!" << std::endl;
two->setDmg(0);}
else{
std::cout << "The attack is successful!" << std::endl;
if(flag == false)
val = two->getAttVal() - one->getDefVal();
else
val = (two->getAttVal() / 2) - one->getDefVal();
one->setDmg(val);
if(one->getDmg() == 0)
std::cout << "Armor absorbed the attack!" << std::endl;
else
std::cout << one->getDmg() << " points of damage!" << std::endl;
one->setSP();
if(one->getSP() <= 0 )
std::cout << "GAME OVER!" << std::endl;
else
std::cout << "Only " << one->getSP() << " Strength Points left!" << std::endl;}
// Check for end game
if(one->getSP() <= 0 || two->getSP() <= 0){
over = true;
statistics(player, oneWin, twoWin);}
turn++;}
}while(over == false);
game++;}
else{
do{
if(turn % 2 == 0){
player = "two";
std::cout << "\n";
std::cout << two->getType() << " " << player << " is attacking" << std::endl;
if(two->getType() == "Goblin" && one->getType() != "Goblin")
two->attack(flagTwo);
else
two->attack();
one->defense();
// test for a hit and set damage
if(two->getAttVal() <= one->getDefVal()){
std::cout << "The attack is a miss!" << std::endl;
two->setDmg(0);}
else{
std::cout << "The attack is successful!" << std::endl;
if(flag == false)
val = two->getAttVal() - one->getDefVal();
else
val = (two->getAttVal() / 2) - one->getDefVal();
one->setDmg(val);
if(one->getDmg() == 0)
std::cout << "Armor absorbed the attack!" << std::endl;
else
std::cout << one->getDmg() << " points of damage!" << std::endl;
one->setSP();
if(one->getSP() <= 0 )
std::cout << "GAME OVER!" << std::endl;
else
std::cout << "Only " << one->getSP() << " Strength Points left!" << std::endl;}
// Check for end game
if(one->getSP() <= 0 || two->getSP() <= 0){
over = true;
statistics(player, oneWin, twoWin);}
turn++;}
else{
player = "one";
std::cout << "\n";
std::cout << one->getType() << " " << player << " is attacking" << std::endl;
if(one->getType() == "Goblin" && two->getType() != "Goblin")
one->attack(flag);
else
one->attack();
two->defense();
// test for a hit and set damage
if(one->getAttVal() <= two->getDefVal()){
std::cout << "The attack is a miss!" << std::endl;
one->setDmg(0);}
else{
std::cout << "The attack is successful!" << std::endl;
if(flagTwo == false)
val = one->getAttVal() - two->getDefVal();
else
val = (one->getAttVal() / 2) - two->getDefVal();
two->setDmg(val);
if(two->getDmg() == 0)
std::cout << "Armor absorbed the attack!" << std::endl;
else
std::cout << two->getDmg() << " points of damage!" << std::endl;
two->setSP();
if(two->getSP() <= 0 )
std::cout << "GAME OVER!" << std::endl;
else
std::cout << "Only " << two->getSP() << " Strength Points left!" << std::endl;}
// Check for end game
if(one->getSP() <= 0 || two->getSP() <= 0){
over = true;
statistics(player, oneWin, twoWin);}
turn++;}
}while(over == false);
game++;}
}