-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.cpp
More file actions
285 lines (257 loc) · 9.31 KB
/
Copy pathassignment.cpp
File metadata and controls
285 lines (257 loc) · 9.31 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/***************************************************************************************
* Author: Tara Massey
* Date: 2/28/2015
* File Name: assignment.cpp
*
* Program: The program's purpose is to create a tournament. The tournament has two
* equal teams, size selected by the user. Each user can select what class of fighter
* will fight. The program then fights the first fighter from the two lineups. The loser
* is sent to a losing lineup. The fights continue in rotating order until one team has
* no fighters left. Points are awarded for each win. The program will tell the user
* which team still had fighters left at the end, which team had more points, and which
* three fighters won the most rounds. The tournament can be repeated, if the user chooses,
* with new fighters.
*
* Input: User inputs the team amount, the class for each fighter, the name of each fighter.
* The user can select to fight another tournament, or to end the game.
*
* Output: Program prints team that still had members standing, team with the most points,
* and the top three scoring fighters. During the fights, prints who is attacking and
* defending, dice roll amount, and damage amount (if any).
*
* Please Note: Bubble Sort was used. Example for sort was taken from the text, C++ Early
* Objects, page 618.
* *************************************************************************************/
#include "Dice.h"
#include "Creature.h"
#include "Barbarian.h"
#include "Shadow.h"
#include "Goblin.h"
#include "BlueM.h"
#include "Reptile.h"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
int createTeams(std::vector<Creature*>&v, std::vector<Creature*>&v2);
void fight(Creature* one, Creature* two, std::vector<Creature*> &oneWin, std::vector<Creature*> &twoWin, std::vector<Creature*> &losers, int &game);
int main()
{
Creature* fighter;
Creature* fighter2;
Creature* temp;
std::vector<Creature*> losers;
std::vector<Creature*>v;
std::vector<Creature*>v2;
std::string pause;
char playAgain = 'Y';
int amount;
int game;
int oneTotal = 0;
int twoTotal = 0;
bool match = false;
bool swap;
game = 0;
while(playAgain == 'Y')
{
std::cout << "\n" << std::endl;
amount = createTeams(v, v2);
while(v.size() != 0 && v2.size() != 0){
fighter = v[0];
fighter2 = v2[0];
std::cout << "Battle beginning!" << std::endl;
std::cout << "Fighter one is " << fighter->getType() << std::endl;
std::cout << "Fighter two is " << fighter2->getType() << std::endl;
fight(fighter, fighter2, v, v2, losers, game);
std::cout << "\nPlease hit ENTER to continue to the next round" << std::endl;
std::getline(std::cin, pause);}
//put all in same pile to determine winner
if(v.size() != 0){
std::cout << "\nTeam One is the last standing!" << std::endl;
for(int i = 0; i < v.size(); i++)
losers.push_back(v[i]);}
if(v2.size() != 0){
std::cout << "\nTeam Two is the last standing!" << std::endl;
for(int i = 0; i < v2.size(); i++)
losers.push_back(v2[i]);}
//determine which team scored more points
for(int i = 0; i < losers.size(); i++){
fighter2 = losers[i];
if(fighter2->getTeam() == 1)
oneTotal = fighter2->getWins() + oneTotal;
if(fighter2->getTeam() == 2)
twoTotal = fighter2->getWins() + twoTotal;}
std::cout << "\nTeam One had " << oneTotal << " points." << std::endl;
std::cout << "Team Two had " << twoTotal << " points." << std::endl;
if(oneTotal > twoTotal)
std::cout << "Team One is the winner based off points!" << std::endl;
if(twoTotal > oneTotal)
std::cout << "Team Two is the winner based off points!" << std::endl;
if(twoTotal == oneTotal)
std::cout << "Tie!" << std::endl;
//sort based off wins
do{
swap = false;
for(int k =0; k < (losers.size() -1); k++){
if(losers[k]->getWins() > losers[k+1]->getWins()){
temp = losers[k];
losers[k] = losers[k+1];
losers[k+1] = temp;
swap = true;}}
}while(swap);
//announce winners
std::reverse(losers.begin(), losers.end());
std::cout << "\nFinal Rankings: " << std::endl;
if(losers.size() < 3){
for(int i = 0; i < losers.size(); i++){
fighter = losers[i];
std::cout << fighter->getType() << " " << fighter->getName() << " with " << fighter->getWins()<< " points " << std::endl;}}
else{
for(int i = 0; i < 3; i++){
fighter = losers[i];
std::cout << fighter->getType() << " " << fighter->getName() << " with " << fighter->getWins() << " points " << std::endl;}}
v.clear();
v2.clear();
losers.clear();
oneTotal = 0;
twoTotal = 0;
std::cout << "Play Again?" << std::endl;
std::getline(std::cin, pause);
while(pause != "Y" && pause != "y" && pause != "n" && pause != "N"){
std::cout << "Please enter Y or N: ";
std::getline(std::cin, pause);}
if(pause == "N" || pause == "n"){
playAgain = 'n';}
}
delete fighter;
delete fighter2;
return 0;
}
/*******************************************************************
* int createTeams()
*
* Purpose: Displays the available fighters the user can select
* from and prompts for fighter amount and fighter choices. Allows
* the user to name the fighters.
*
* Entry: Takes in two empty vectors, one for each time, and fills them
* with the creatures of the user's selection.
*
* Exit: Returns the amount of of fighters the two teams will have
* *****************************************************************/
int createTeams(std::vector<Creature*>&v, std::vector<Creature*>&v2)
{
int choice;
std::string name;
std::string option;
Creature* fighter;
Creature* fighter2;
// get team amount and check for valid input
std::cout << "\n" << std::endl;
std::cout << "Please enter the number of fighters on each team in the tournament: " << std::endl;
std::getline(std::cin, option);
for(int i = 0; i < option.length(); i++){
while(!(isdigit(option.at(i)))){
std::cout << "Invalid. Please enter a number: ";
std::getline(std::cin, option);}}
choice = atoi(option.c_str());
while(choice == 0){
std::cout << "Invalid. Please enter a positive number: ";
std::getline(std::cin, option);
for(int i = 0; i < option.length(); i++){
while(!(isdigit(option.at(i)))){
std::cout << "Invalid. Please enter a number: ";
std::getline(std::cin, option);}}
choice = atoi(option.c_str());}
// player one team
std::cout << "\nPlayer One, you have the following fighter options: " << std::endl;
std::cout << "Barbarian" << std::endl;
std::cout << "Shadow" << std::endl;
std::cout << "Reptile Man " << std::endl;
std::cout << "Blue Men" << std::endl;
std::cout << "Goblin" << std::endl;
for(int i = 0; i < choice; i++){
std::cout << "\nPlease enter the fighter type for Fighter " << i+1 << ": ";
std::getline(std::cin, option);
if(option == "Barbarian"){
fighter = new Barbarian;
fighter->setTeam(1);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter->setName(name);
v.push_back(fighter);}
if(option == "Shadow"){
fighter = new Shadow;
fighter->setTeam(1);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter->setName(name);
v.push_back(fighter);}
if(option == "Reptile Man"){
fighter = new Reptile;
fighter->setTeam(1);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter->setName(name);
v.push_back(fighter);}
if(option == "Blue Men"){
fighter = new BlueM;
fighter->setTeam(1);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter->setName(name);
v.push_back(fighter);}
if(option == "Goblin"){
fighter = new Goblin;
fighter->setTeam(1);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter->setName(name);
v.push_back(fighter);}}
// player two team
std::cout << "\nPlayer Two, you have the following fighter options: " << std::endl;
std::cout << "Barbarian" << std::endl;
std::cout << "Shadow" << std::endl;
std::cout << "Reptile Man " << std::endl;
std::cout << "Blue Men" << std::endl;
std::cout << "Goblin" << std::endl;
for(int i = 0; i < choice; i++){
std::cout << "\nPlease enter the fighter type for Fighter " << i+1 << ": ";
std::getline(std::cin, option);
if(option == "Barbarian"){
fighter2 = new Barbarian;
fighter2->setTeam(2);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter2->setName(name);
v2.push_back(fighter2);}
if(option == "Shadow"){
fighter2 = new Shadow;
fighter2->setTeam(2);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter2->setName(name);
v2.push_back(fighter2);}
if(option == "Reptile Man"){
fighter2 = new Reptile;
fighter2->setTeam(2);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter2->setName(name);
v2.push_back(fighter2);}
if(option == "Blue Men"){
fighter2 = new BlueM;
fighter2->setTeam(2);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter2->setName(name);
v2.push_back(fighter2);}
if(option == "Goblin"){
fighter2 = new Goblin;
fighter2->setTeam(2);
std::cout << "Please give this fighter a name: ";
std::getline(std::cin, name);
fighter2->setName(name);
v2.push_back(fighter2);}}
return choice;
}