-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.cpp
More file actions
361 lines (349 loc) · 15.4 KB
/
UserInterface.cpp
File metadata and controls
361 lines (349 loc) · 15.4 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
//
// Created by Jolie Elins on 12/11/19.
//
#include <iostream>
#include <string>
#include <fstream>
#include "Pokemon.h"
#include "Team.h"
#include "ArrayList.h"
#include "TestLib.h"
#include "PokemonList.h"
#include "FileLibrary.h"
#include "SmartBuilder.h"
int main() {
srand(time(NULL));
PokemonList* pokeList;
pokeList = createPokemonList("Pokemon - Data.csv");
ArrayList<Team*>* teamList;
teamList = createTeamList("team.txt", pokeList);
//teamList = new ArrayList<Team*>(10);
std::string input = "";
//balance team and counter team unde create ne
std::cout <<" 1: Display all pokemon \n 2: Search for a pokemon \n 3: Display pokemon by type \n"
" 4: Display all current teams \n 5: Display type effectiveness of a team \n"
" 6: Create a new team \n 7: Edit a team \n 8: Fill a team with compatible pokemon\n"
"'help' to repeat menu \n 'quit' if done \n -> ";
std::getline(std::cin, input);
while (input != "quit"){
if (input == "help"){
std::cout << " 1: Display all pokemon \n 2: Search for a pokemon \n 3: Display pokemon by type \n"
" 4: Display all current teams \n 5: Display type effectiveness of a team \n"
" 6: Create a new team \n 7: Edit a team \n 8: Fill a team with compatible pokemon\n"
"'help' to repeat menu \n 'quit' if done \n";
}
else if (input == "1"){
for(int i = 0; i < pokeList->itemCount(); i++){
std::cout << pokeList->getValueAt(i)->toString()<<std::endl;
}
}
else if (input == "2"){
std::cout <<"Would you like to search by name or pokedex? \n -> ";
std::string searchInput = "";
getline(std::cin, searchInput);
if (searchInput == "name") {
std::cout <<"What name? \n ->";
std::string nameInput = "";
getline(std::cin, nameInput);
try{
std::cout<<pokeList->getValueAt(pokeList->find(nameInput))->toString() <<std::endl;
}
catch(std::exception& e){
std::cout<<"Invalid Pokemon Name\n";
}
}
else if (searchInput == "pokedex"){
std::cout <<"What pokedex number? \n ->";
std::string dexInput = "";
getline(std::cin, dexInput);
int dex = -1;
try{
dex = stoi(dexInput);
try{
std::cout<<pokeList->getValueAt(pokeList->find(dex))->toString() <<std::endl;
}
catch(std::out_of_range& e){
std::cout<<"No such pokedex\n";
}
}
catch(std::exception&e){
std::cout<<"Input must be a Number\n";
}
}
else {
std::cout << "Invalid search type \n";
}
}
else if (input == "3"){
std::cout<< "Would you like to search for one type, or a combination? ('one' or 'combination') \n -> ";
std::string val = "";
getline(std::cin, val);
if (val == "one"){
std::cout<<"What type would you like to search for? \n -> ";
std::string type = "";
getline(std::cin, type);
ArrayList<Pokemon*>* subList;
try{
subList = pokeList->subList(type,"null");
for(int x = 0; x<subList->itemCount(); x++){
std::cout<<subList->getValueAt(x)->toString()<<std::endl;
}
delete(subList);
}
catch(std::invalid_argument& e){
std::cout<<"Invalid Type\n";
}
}
else if (val == "combination"){
std::cout<<"What is the first type would you like to search for? \n -> ";
std::string type1 = "";
getline(std::cin, type1);
std::cout<<"What is the second type would you like to search for? \n -> ";
std::string type2 = "";
getline(std::cin, type2);
ArrayList<Pokemon*>* subList;
try{
subList = pokeList->subList(type1, type2);
for(int x = 0; x<subList->itemCount(); x++){
std::cout<<subList->getValueAt(x)->toString()<<std::endl;
}
delete(subList);
}
catch(std::invalid_argument& e){
std::cout<<"One or more types is invalid\n";
}
}
else{
std::cout << "Invalid entry \n";
}
}
else if (input == "4"){
if(teamList->isEmpty()) {
std::cout <<"There are no teams in the list \n";
}
else {
//std::cout <<teamList->getValueAt(0)->getName()<<"\n";
for (int i = 0; i < teamList->itemCount(); i++){
std::cout << teamList->getValueAt(i)->displayTeam() << "\n";
}
}
}
else if (input == "5"){
std::cout <<"What is the name of the team you would like to see? \n -> ";
std::string teamName = "";
getline(std::cin, teamName);
int index = -1;
for (int i = 0; i < teamList->itemCount(); i++){
if (teamList->getValueAt(i)->getName() == teamName){
index = i;
}
}
if (index != -1) {
float* effectiveTypes = teamList->getValueAt(index)->getEffectiveTypes();
std::string types[18] = {"normal", "fighting", "flying", "poison", "ground", "rock", "bug", "ghost", "steel", "fire", "water", "grass", "electric", "psychic", "ice", "dragon", "dark", "fairy"};
for(int i = 0; i < 17; i++){
std::cout << types[i] << ": "<<effectiveTypes[i] << ", ";
}
std::cout<< types[17] << ": "<<effectiveTypes[17]<<"\n";
}
else{
std::cout << "Team Not Found\n";
}
}
else if (input == "6"){
std::cout <<"Would you like to: \n 1: Create a new team\n 2: Create a balanced team\n 3: Counter a given team\n -> ";
std::string teamType = "";
getline(std::cin, teamType);
bool valid = false;
std::string teamName;
bool validType = false;
if(teamType=="1"||teamType=="2"||teamType == "3"){
validType = true;
std::cout <<"What would you like to name your team? \n -> ";
teamName = "";
getline(std::cin, teamName);
valid = true;
for(int o = 0; o < teamList->itemCount(); o++){
if(teamList->getValueAt(o)->getName() == teamName){
valid = false;
}
}
}
if(valid){
if(teamType == "1"){
Team* newTeam = new Team(teamName);
teamList -> insertAtEnd(newTeam);
std::cout <<"Would you like to: \n 1: Add a pokemon\n 2: Remove a pokemon\n 3: Change the name \n 'done' to finish editing \n 'help' to bring up this menu again\n -> ";
std::string editOption = "";
getline(std::cin, editOption);
while (editOption != "done"){
if(editOption == "1"){
std::cout <<"What is the name of the pokemon you would like to add? \n -> ";
std::string pokemonName = "";
getline(std::cin, pokemonName);
try{
newTeam->addPokemon(pokeList->getValueAt(pokeList->find(pokemonName)));
}
catch(std::invalid_argument& e){
std::cout<<"Team is full\n";
}
catch(std::out_of_range& e){
std::cout<<"Invalid Pokemon name\n";
}
}
else if(editOption == "2"){
std::cout <<"What is the name of the pokemon you would like to remove? \n -> ";
std::string pokemonName = "";
getline(std::cin, pokemonName);
try{
newTeam->removePokemon(pokemonName);
}
catch(std::invalid_argument& e){
std::cout<<"Pokemon not in team\n";
}
}
else if(editOption == "3"){
std::cout <<"What would you like the new name to be? \n -> ";
std::string newTeamName = "";
getline(std::cin, newTeamName);
newTeam->changeName(newTeamName);
}
else if(editOption == "help"){
std::cout <<"Would you like to: \n 1: Add a pokemon\n 2: Remove a pokemon\n 3: Change the name \n 'done' to finish editing \n 'help' to bring up this menu again\n";
}
else{
std::cout<<"Not a valid option\n";
}
std::cout << " -> ";
getline(std::cin, editOption);
}
}
else if(teamType == "2"){
Team* newTeam = createBalancedTeam(teamName, pokeList);
teamList -> insertAtEnd(newTeam);
}
else if(teamType == "3"){
std::cout <<"What is the name of the team you would like to counter? \n -> ";
std::string counterTeam = "";
getline(std::cin, counterTeam);
Team* teamCounter = nullptr;
for(int x = 0; x < teamList->itemCount(); x++){
if(counterTeam==teamList->getValueAt(x)->getName()){
teamCounter = teamList->getValueAt(x);
}
}
if(teamCounter!=nullptr){
Team* newTeam = createTeamCounter(teamCounter, teamName, pokeList);
teamList -> insertAtEnd(newTeam);
}
else{
std::cout<< "Invalid Team Name\n";
}
}
else {
std::cout << "Invalid entry \n";
}
}
else if(validType){
std::cout<<"Team Already exists\n";
}
else{
std::cout<<"Invalid Option\n";
}
}
else if (input == "7"){
std::cout << "Which team would you like to edit? \n -> ";
std::string teamName = "";
getline(std::cin, teamName);
Team* teamEdit= nullptr;
for(int x = 0; x < teamList->itemCount(); x++){
if(teamList->getValueAt(x)->getName() == teamName){
teamEdit = teamList->getValueAt(x);
}
}
if (teamEdit!= nullptr){
std::cout <<"Would you like to: \n 1: Add a pokemon\n 2: Remove a pokemon\n 3: Change the name \n 4: Delete Team\n 'done' to finish editing \n 'help' to bring up this menu again\n -> ";
std::string editOption = "";
getline(std::cin, editOption);
while (editOption != "done"){
if(editOption == "1"){
std::cout <<"What is the name of the pokemon you would like to add? \n -> ";
std::string pokemonName = "";
getline(std::cin, pokemonName);
try{
teamEdit->addPokemon(pokeList->getValueAt(pokeList->find(pokemonName)));
}
catch(std::invalid_argument& e){
std::cout<<"Team is full\n";
}
catch(std::out_of_range& e){
std::cout<<"Invalid Pokemon name\n";
}
}
else if(editOption == "2"){
std::cout <<"What is the name of the pokemon you would like to remove? \n -> ";
std::string pokemonName = "";
getline(std::cin, pokemonName);
try{
teamEdit->removePokemon(pokemonName);
}
catch(std::invalid_argument& e){
std::cout<<"Pokemon not in team\n";
}
}
else if(editOption == "3"){
std::cout <<"What would you like the new name to be? \n -> ";
std::string newTeamName = "";
getline(std::cin, newTeamName);
teamEdit->changeName(newTeamName);
}
else if(editOption == "help"){
std::cout <<"Would you like to: \n 1: Add a pokemon\n 2: Remove a pokemon\n 3: Change the name \n 'done' to finish editing \n 'help' to bring up this menu again\n -> ";
}
else if(editOption == "4"){}
else{
std::cout<<"Not a valid option\n";
}
if(editOption == "4"){
for(int x = 0; x < teamList->itemCount(); x++){
if(teamList->getValueAt(x)->getName() == teamName){
teamList->removeValueAt(x);
}
}
editOption = "done";
}
else{
std::cout << " -> ";
getline(std::cin, editOption);
}
}
}
else{
std::cout<<"Invalid Team Name";
}
}
else if (input == "8"){
std::cout <<"What is the name of the team you would like to fill?\n -> ";
std::string teamName = "";
getline(std::cin, teamName);
Team* teamEdit= nullptr;
for(int x = 0; x < teamList->itemCount(); x++){
if(teamList->getValueAt(x)->getName() == teamName){
teamEdit = teamList->getValueAt(x);
}
}
if (teamEdit!= nullptr){
smartTeamFill(teamEdit, pokeList);
}
else{
std::cout<<"Invalid Team\n";
}
}
else{
std::cout<<"Invalid Option\n";
}
std::cout<<" -> ";
getline(std::cin, input);
}
printToFileTeam("team.txt", teamList, teamList->itemCount());
}