-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
324 lines (299 loc) · 10.6 KB
/
Copy pathmain.cpp
File metadata and controls
324 lines (299 loc) · 10.6 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//
// Created by Bobby Paletta on 9/8/24.
//
#include "Trainer.h"
#include <fstream>
#include <iostream>
#include <chrono>
void createPokedex(vector<Pokemon>& pokedex) {
ifstream fileIn;
fileIn.open("../pokemonNew2.csv");
if (fileIn) {
cout << "File opened" << endl;
string header;
getline(fileIn, header);
// declare variables
int id = 0;
string name = "Pokemon";
string typeOne = "Poke";
string typeTwo = "Mon";
int total = 100;
int hp = 100;
int attack = 50;
int defense = 50;
int spAttack = 55;
int spDefense = 55;
int speed = 10;
int generation = 0;
int legendary = 0;
string percentage_male = "1.0";
double capture_rate = 0;
string classification = "Mon";
char comma = ',';
string newLine;
string negative;
char quote = '"';
string numInt;
while (fileIn.peek() != EOF) {
//read number
fileIn >> id;
fileIn >> comma;
// read name
getline(fileIn, name, comma);
// read typeOne
getline(fileIn, typeOne, comma);
// read typeTwo
getline(fileIn, typeTwo, comma);
// read total
fileIn >> total;
fileIn >> comma;
// read hp
fileIn >> hp;
fileIn >> comma;
// read attack
fileIn >> attack;
fileIn >> comma;
// read the defense
fileIn >> defense;
fileIn >> comma;
// read spAttack
fileIn >> spAttack;
fileIn >> comma;
//read spDefense
fileIn >> spDefense;
fileIn >> comma;
//read speed
fileIn >> speed;
fileIn >> comma;
//read generation
fileIn >> generation;
fileIn >> comma;
//read legendary
fileIn >> legendary;
fileIn >> comma;
//read percent male
getline(fileIn, percentage_male, comma);
//read capture rate
fileIn >> capture_rate;
fileIn >> comma;
//read classification
getline(fileIn, classification, '\r');
pokedex.push_back(Pokemon(id, name, typeOne, typeTwo, total, hp,
attack, defense, spAttack, spDefense,
speed, generation, legendary, percentage_male,
capture_rate, classification));
}
} else {
cout << "Error opening file" << endl;
}
fileIn.close();
};
string getStat(string input){
if (input == "A"){
return "Total";
}
else if (input == "B"){
return "HP";
}
else if (input == "C"){
return "Attack";
}
else if (input == "D"){
return "Defense";
}
else if (input == "E"){
return "Special Attack";
}
else if (input == "F"){
return "Special Defense";
}
else if (input == "G"){
return "Speed";
}
else if (input == "H"){
return "Generation";
}
}
int main() {
//create the pokedex using the getDataFromFile method in the pokemon class
vector<Pokemon> pokedex;
createPokedex(pokedex);
bool check = false;
string input;
string fName;
string lName;
cout << "Welcome to the World of Pokemon! Let's begin your journey in this magical new world "
"by learning something about you new trainer!" << endl;
//Prompt for the user to enter their first name
while (!check) {
check = true;
//string input;
// bool check = true;
cout << "Enter your first name: ";
getline(std::cin, input);
for (char c: input) {
if (isspace(c)) {
check = false;
}
}
if (input.empty()) {
cout << "No input. ";
check = false;
}
if (check) {
fName = input;
} else {
cout << "Invalid." << endl;
}
}
//Prompt for the user to enter their last name
check = false;
while (!check) {
check = true;
//string input;
// bool check = true;
cout << "Enter your last name: ";
getline(std::cin, input);
for (char c: input) {
if (isspace(c)) {
check = false;
}
}
if (input.empty()) {
cout << "No input. ";
check = false;
}
if (check) {
lName = input;
} else {
cout << "Invalid." << endl;
}
}
//Create a trainer object with the inputted first and last name and add pokemon to the trainers team
Trainer newTrainer = Trainer(fName, lName);
cout << "Welcome to this new world " << newTrainer.getfName() << " " << newTrainer.getlName() << "!" << endl;
cout << "Now it is time to assemble your team of Pokemon!" << endl;
//while invalid input and the size of the team is less than 6, reprompt until it is correct
bool choice = true;
while (choice && newTrainer.getSize() < 6) {
check = false;
cout << "Choose Pokemon #" << newTrainer.getSize() + 1 << endl;
while (!check) {
getline(std::cin, input);
for (int i = 0; i < input.size(); i++) {
input[i] = tolower(input[i]);
}
input[0] = toupper(input[0]);
if (!checkName(pokedex, input)) {
cout << "That is not a valid Pokemon. Please try again!" << endl;
} else if (checkName(pokedex, input)) {
check = true;
newTrainer.addPokemon(getPokemon(pokedex, input));
}
}
cout << "Great choice! " << getPokemon(pokedex, input).getName() << " is the "
<< getPokemon(pokedex, input).getClassifictaion() << endl;
if (newTrainer.getSize() < 6) {
cout << "Would you like to add another Pokemon to your team? (Y/N)" << endl;
check = false;
while (!check) {
getline(std::cin, input);
if (input == "N") {
choice = false;
check = true;
} else if (input == "Y") {
check = true;
} else {
cout << "Invalid option. Try again." << endl;
}
}
}
}
string selectionOne, selectionTwo;
bool relationCheck = false;
cout << "Now it is time to compare your teams stats! You have the option to compare their "
"base totals(a), hp(b), attack(c), defense(d), special attack(e), special defense(f),"
"speed(g) and generation(h). " << endl;
//loop through until the user makes a valid selection
while (!relationCheck) {
cout << "Please select one of the previous options. " << endl;
getline(std::cin, selectionOne);
std::transform(selectionOne.begin(), selectionOne.end(), selectionOne.begin(), ::toupper);
if (selectionOne == "A" || selectionOne == "B" || selectionOne == "C" || selectionOne == "D" ||
selectionOne == "E" || selectionOne == "F" ||
selectionOne == "G" || selectionOne == "H") {
relationCheck = true;
} else {
cout << "Invalid option" << endl;
}
}
//reset the loop until it gets another valid selection
relationCheck = false;
while (!relationCheck) {
cout << "Please select a second statistic. " << endl;
getline(std::cin, selectionTwo);
std::transform(selectionTwo.begin(), selectionTwo.end(), selectionTwo.begin(), ::toupper);
if (selectionTwo == "A" || selectionTwo == "B" || selectionTwo == "C" || selectionTwo == "D" ||
selectionTwo == "E" || selectionTwo == "F" ||
selectionTwo == "G" || selectionTwo == "H") {
relationCheck = true;
} else {
cout << "Invalid option" << endl;
}
}
/*for every pokemon that the trainer has chosen, check which selections were
* chosen and write to the file that specified pokemons first chosen statistic
* value, the second chosen statistic value, the name of the pokemon, and both
* statistic names.
* */
int count = 0;
std::ofstream outFile;
outFile.open("/Users/bobbypaletta/CLionProjects/M3OEP-rpaletta/project4_outfile.csv");
for (int i = 0; i < newTrainer.getSize(); i++) {
if (selectionOne == "A") {
outFile << newTrainer.getPokemon(i).getTotal() << ",";
} else if (selectionOne == "B") {
outFile << newTrainer.getPokemon(i).getHP() << ",";
} else if (selectionOne == "C") {
outFile << newTrainer.getPokemon(i).getAttack() << ",";
} else if (selectionOne == "D") {
outFile << newTrainer.getPokemon(i).getDefense() << ",";
} else if (selectionOne == "E") {
outFile << newTrainer.getPokemon(i).getSpAttack() << ",";
} else if (selectionOne == "F") {
outFile << newTrainer.getPokemon(i).getSpDefense() << ",";
} else if (selectionOne == "G") {
outFile << newTrainer.getPokemon(i).getSpeed() << ",";
} else if (selectionOne == "H") {
outFile << newTrainer.getPokemon(i).getGeneration() << ",";
}
if (selectionTwo == "A") {
outFile << newTrainer.getPokemon(i).getTotal() << ",";
} else if (selectionTwo == "B") {
outFile << newTrainer.getPokemon(i).getHP() << ",";
} else if (selectionTwo == "C") {
outFile << newTrainer.getPokemon(i).getAttack() << ",";
} else if (selectionTwo == "D") {
outFile << newTrainer.getPokemon(i).getDefense() << ",";
} else if (selectionTwo == "E") {
outFile << newTrainer.getPokemon(i).getSpAttack() << ",";
} else if (selectionTwo == "F") {
outFile << newTrainer.getPokemon(i).getSpDefense() << ",";
} else if (selectionTwo == "G") {
outFile << newTrainer.getPokemon(i).getSpeed() << ",";
} else if (selectionTwo == "H") {
outFile << newTrainer.getPokemon(i).getGeneration() << ",";
}
outFile << newTrainer.getPokemon(i).getName() << ",";
if (count < 1) {
outFile << getStat(selectionOne) << ",";
outFile << getStat(selectionTwo) << endl;
count++;
}
else{
outFile << endl;
}
}
outFile.close();
return 0;
};