-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint.cs
More file actions
309 lines (292 loc) · 13.4 KB
/
Print.cs
File metadata and controls
309 lines (292 loc) · 13.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
using PokeDex.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Globalization.CultureInfo;
namespace PokeDex
{
class Print
{
public static string DisplayOptions(string entry, PokeList pokeList)
{
var skipForms = new List<string> { "-small", "-super", "-average", "-large", "-battle-bond", "-ash" };
var displayOptions = new List<Result>(pokeList.Results.Where(p => p.Name.Contains(entry)));
displayOptions.RemoveAll(p => p.Name.Contains("-cap") || p.Name.Contains("totem"));
if (displayOptions.Count > 1)
{
Console.WriteLine("\r\nYour entry matches a few options. Please enter the number that you are looking for.");
int counter = 1;
foreach (var item in displayOptions)
{
string pokemonName = Formatting.FormatProperNouns(item.Name);
Settings.CheckColors(ConsoleColor.White);
Console.WriteLine($" Press {counter++}: {pokemonName}");
}
Settings.CheckColors(ConsoleColor.Yellow);
var userChoice = Console.ReadLine();
int number;
bool numberEntered = false;
while (!numberEntered)
{
bool success = int.TryParse(userChoice, out number);
if (!success)
{
Settings.CheckColors(ConsoleColor.Cyan);
Console.WriteLine($"Please enter a number.");
Settings.CheckColors(ConsoleColor.Yellow);
userChoice = Console.ReadLine();
}
else if (number > displayOptions.Count || number <= 0)
{
Settings.CheckColors(ConsoleColor.Cyan);
Console.WriteLine($"That's not one of the options...try again please.");
Settings.CheckColors(ConsoleColor.Yellow);
userChoice = Console.ReadLine();
}
else if (success)
{
numberEntered = true;
entry = displayOptions[number - 1].Name;
}
}
Settings.CheckColors(ConsoleColor.Cyan);
return Formatting.FilterNameEntry(entry);
}
else
{
return entry;
}
}
private static string PrintPokemonName(PokemonEntry pokemonMainEntry, PokemonSpecies pokemonSpeciesEntry)
{
string pokemonName = pokemonMainEntry.Name;
var info = CurrentCulture.TextInfo;
pokemonName = info.ToTitleCase(Formatting.FormatNameOuput(pokemonMainEntry));
//This fills the space between the end of the Pokemon's name and the beginning of it's Dex Number.
//Makes sure that the bottom and top are of even length.
int totalLength = pokemonName.Length + pokemonSpeciesEntry.ID.ToString().Length;
for (int i = totalLength; i <= 61; i++)
{
pokemonName += "=";
}
return pokemonName;
}
private static string PrintPokemonGeneration(PokemonSpecies pokemonSpeciesEntry)
{
//There's a better way to do this but I would like to avoid another call to PokeAPI for something so small:
//1. Make a call to https://pokeapi.co/api/v2/generation
//2. Iterate through the array.
//3. If Generation.Name === i, take the index number, add 1, put it in the string "Generation: ${indexNumber}"
var gen = pokemonSpeciesEntry.Generation.Name;
Dictionary<string, string> generations = new Dictionary<string, string>()
{
{"generation-viii", "Generation: 8"},
{"generation-vii", "Generation: 7"},
{"generation-vi", "Generation: 6"},
{"generation-v", "Generation: 5"},
{"generation-iv", "Generation: 4"},
{"generation-iii", "Generation: 3"},
{"generation-ii", "Generation: 2"},
{"generation-i", "Generation: 1"}
};
if (generations.Keys.Contains(gen))
{
gen = generations[gen];
}
else
{
gen = "Generation: ?";
};
return gen;
}
private static string PrintPokemonType(PokemonEntry pokemonMainEntry)
{
var info = CurrentCulture.TextInfo;
string pokemonType = info.ToTitleCase(pokemonMainEntry.Types[0].Type.Name);
if (pokemonMainEntry.Types.Length != 1)
{
string pokemonSecondType = info.ToTitleCase(pokemonMainEntry.Types[1].Type.Name);
pokemonType = $"Types: {pokemonType}/{pokemonSecondType}";
}
else
{
pokemonType = $"Type: {pokemonType}";
}
return pokemonType;
}
private static string PrintPokemonHabitat(PokemonSpecies pokemonSpeciesEntry)
{
var pokemonHabitat = "";
if (pokemonSpeciesEntry.Habitat != null)
{
pokemonHabitat = $"Habitat: {pokemonSpeciesEntry.Habitat.Name}";
}
return pokemonHabitat;
//Some Pokemon don't have habitats. This just removes habitat from the output if none exists.
//Handles: System.NullReferenceException
}
private static string PrintPokemonAbilities(PokemonEntry pokemonMainEntry)
{
string abilities = "";
if (pokemonMainEntry.Abilities.Length > 1)
{
abilities = $"Abilities: ";
}
else
{
abilities = $"Ability: ";
}
foreach (var ability in pokemonMainEntry.Abilities)
{
if (ability.Slot == 1)
{
abilities += Formatting.FormatProperNouns(ability.Ability.Name);
}
else
{
abilities += ", " + Formatting.FormatProperNouns(ability.Ability.Name);
}
}
return abilities;
}
private static string PrintPokemonMeasurements(PokemonEntry pokemonMainEntry)
{
string pokemonMeasure;
double pokemonHeight = pokemonMainEntry.Height / 10;
double pokemonWeight = pokemonMainEntry.Weight / 10;
if (Settings.EmperialMeasureSetting == true)
{
pokemonHeight = pokemonHeight * 39.370;
pokemonWeight = pokemonWeight * 35.274;
int pounds = (int)pokemonWeight / 16;
int ouncesLeft = (int)pokemonWeight % 16;
int feet = (int)pokemonHeight / 12;
int inchesLeft = (int)pokemonHeight % 12;
pokemonMeasure = $"Height: {feet}ft {inchesLeft}in Weight: {pounds}lb {ouncesLeft}oz";
}
else
{
pokemonMeasure = $"Height: {pokemonHeight}M Weight: {pokemonWeight}Kg";
}
return pokemonMeasure;
}
private static string PrintPokemonDescription(PokemonSpecies pokemonSpeciesEntry, string entry)
{
pokemonSpeciesEntry.FlavorTextEntries.RemoveAll(f => f.Language.Name != "en");
var description = pokemonSpeciesEntry.FlavorTextEntries[0].FlavorText;
var specialDescriptionForms = new List<string> { "-galar", "-alola", "-gmax", "-mega", "rotom", "-black", "-white" };
foreach (var item in specialDescriptionForms)
{
if (entry.Contains(item))
{
description = Formatting.GetActualDescription(entry);
}
}
return description = description.Replace("\n", " ").Replace("\f", " ");
}
private static string PrintPokemonForms(PokemonSpecies pokemonSpeciesEntry)
{
string pokemonForms = "";
int formsCounter = 0;
if (pokemonSpeciesEntry.Varieties.Length > 1)
{
pokemonForms = "||\r\n" + "||Forms: ";
foreach (var item in pokemonSpeciesEntry.Varieties)
{
formsCounter++;
if (formsCounter == pokemonSpeciesEntry.Varieties.Length)
{
pokemonForms += $"{Formatting.FormatProperNouns(item.Pokemon.Name)}";
}
else
{
pokemonForms += $"{Formatting.FormatProperNouns(item.Pokemon.Name)}, ";
}
}
pokemonForms += "\r\n";
}
return pokemonForms;
}
private static string PrintPokemonEvolutions(PokemonEvolution pokemonEvolutionEntry)
{
var info = CurrentCulture.TextInfo;
string evolvesTo = "";
var evolutions = pokemonEvolutionEntry.Chain.EvolvesTo;
if (evolutions.Length != 0)
{
//Handles evolution branching if base pokemon has two possible evolutions that then evolve.
//It checks for how many evolutions the base has AND if any of those also evolve.
//(ex: Wurmple to Cascoon OR Silcoon. Then Cascoon to Dustox AND Silcoon to Beautifly.)
if (evolutions.Length > 1 && evolutions.Any(e => e.EvolvesTo1.Length > 0))
{
evolvesTo = $"||\r\n";
foreach (var item in evolutions)
{
evolvesTo += $"||Evolution chain: {info.ToTitleCase(pokemonEvolutionEntry.Chain.SpeciesEvo.Name)} ===> {info.ToTitleCase(item.Species.Name)} ";
foreach (var i in item.EvolvesTo1)
{
evolvesTo += $"===> {info.ToTitleCase(i.Species.Name)}\r\n";
}
}
evolvesTo += "\r\n";
}
else
//Handles evolution branching if there are no more evolutions after the branch
//(ex: Slowpoke to Slowbro OR Slowking; Poliwag to Poliwhirl to Poliwrath OR Politoad.).
//Allows pokemon like Eevee that do not evolve again to be formatted easily.
{
evolvesTo = $"||\r\n||Evolution chain: {info.ToTitleCase(pokemonEvolutionEntry.Chain.SpeciesEvo.Name)} ===> ";
foreach (var item in evolutions)
{
evolvesTo += $"{info.ToTitleCase(item.Species.Name)} ";
if (item.EvolvesTo1.Length != 0)
{
string complexEvolution = "===> ";
int count = 0;
foreach (var i in item.EvolvesTo1)
{
count++;
if (count == item.EvolvesTo1.Length)
{
complexEvolution += $"{info.ToTitleCase(i.Species.Name)} ";
}
else
{
complexEvolution += $"{info.ToTitleCase(i.Species.Name)}, ";
}
}
evolvesTo += complexEvolution;
}
}
evolvesTo += "\r\n";
}
}
return evolvesTo;
}
public static string PrintPokemonPokedexEntry(PokemonEntry pokemonMainEntry,PokemonSpecies pokemonSpeciesEntry, PokemonEvolution pokemonEvolutionEntry, string entry)
{
string pokemonName = PrintPokemonName(pokemonMainEntry, pokemonSpeciesEntry);
string pokemonGen = PrintPokemonGeneration(pokemonSpeciesEntry);
string pokemonType = PrintPokemonType(pokemonMainEntry);
string pokemonHabitat = PrintPokemonHabitat(pokemonSpeciesEntry);
string abilities = PrintPokemonAbilities(pokemonMainEntry);
string pokemonMeasure = PrintPokemonMeasurements(pokemonMainEntry);
string description = Formatting.WrapText(PrintPokemonDescription(pokemonSpeciesEntry, entry));
string pokemonForms = Formatting.WrapText(PrintPokemonForms(pokemonSpeciesEntry));
string evolvesTo = PrintPokemonEvolutions(pokemonEvolutionEntry);
string bottomBar = "==================================================================================";
string completedEntry = $"\r\n{pokemonName}No. {pokemonSpeciesEntry.ID}==={pokemonGen}\r\n" +
$"||{pokemonType}; Color: {pokemonSpeciesEntry.Color.Name}; {pokemonHabitat}\r\n" +
$"||\r\n" +
$"||{abilities}\r\n" +
$"||\r\n" +
$"||{pokemonMeasure}\r\n" +
$"||\r\n" +
$"||Description: {description}\r\n" +
$"{pokemonForms}" +
$"{evolvesTo}" +
$"{bottomBar}\r\n";
return completedEntry;
}
}
}