-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokeTools.java
344 lines (269 loc) · 12.7 KB
/
pokeTools.java
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
import java.util.*;
/**
* Some useful methods that are used in the project
*/
public class pokeTools {
private static Scanner input = new Scanner(System.in); // the Scanner for input
private static Random rNumber = new Random();
/**
* Getting Data from user, but limiting responses
*
* @param helper what to print as hint
* @param error the error if the user enters a unknown input
* @param data the valid inputs
* @return a valid response
*/
public static String getData(String helper, String error, String[] data) {
HashSet<String> correctResponse = new HashSet<>(Arrays.asList(data)); // Making a hashset for easier comparison
String response; // the response from the user
while (true) { // While the user has not entered a valid response
delayPrint(helper); // Prints the helper
response = input.next(); // gets input
if (correctResponse.contains(response)) { // If the input is valid then return the input
return response;
}
delayPrintln(error);
}
}
/**
* Same as getData but with range of number
*
* @param helper what to print as hint
* @param error the error if the user enters a unknown input
* @param starting the start for the range, inclusive
* @param end the end for the range, inclusive
* @return A valid response (Integer)
*/
public static int getRange(String error, String helper, int starting, int end) {
String response;
int selection;
while (true) {
delayPrint(helper);
response = input.next();
if (response.matches("^[0-9]+$")) { // regular expression to check if input is a number from the start of the input, match digits 0-9, match 1 or more times, until the end of the string
selection = Integer.parseInt(response); // parsing the input if its a integer
if (selection >= starting && selection <= end) { // checking if its within the valid range
return selection; // returns the input
}
}
delayPrintln(error);
}
}
/**
* Generating a random number, python style
* @param min The min for the random number
* @param max The max for the random number
* @return a int of the random number
*/
public static int randint(int min, int max) {
return rNumber.nextInt(max - min + 1) + min;
}
/**
* Helper method with default delay with new line added
* @param toPrint String to print
*/
public static void delayPrintln(String toPrint) {
delayPrint(toPrint + "\n", 5, 0);
}
/**
* Printing a table/large amount of text.
* @param toPrint to print
*/
public static void delayPrintTable(String toPrint) {
String[] table = toPrint.split("\n"); // Spiting the input into lines
for (String line : table) { // Go through each individual line
System.out.println(line);
try {
Thread.sleep(5); // Stop printing for 5 millisecond after every line
} catch (Exception e) {
}
}
}
/**
* Helper method with default delay
* @param toPrint String to print
*/
public static void delayPrint(String toPrint) {
delayPrint(toPrint, 5, 0);
}
/**
* Printing a piece of text with a typing effect
*
* @param toPrint The text to print
* @param micro The amount of millisecond to wait
* @param nano The amound of nano seconds to wait
*/
public static void delayPrint(String toPrint, int micro, int nano) {
for (char c : toPrint.toCharArray()) { // Iterating through each character of the input
System.out.print(c);
try {
Thread.sleep(micro, nano); // stopping the program
} catch (Exception e) {
}
}
}
/**
* adds a pause effect to allow the user to read the information before progressing
*/
public static void pause() {
delayPrintln("\nPress enter to continue...");
try {
System.in.read(); // System.in.read is used here because scanner considers <enter>(\n) to be a white space therefore skipping it
} catch (Exception e) {
}
}
/**
* Prints a bunch of blank lines, "clearing" the screen
*/
public static void clearScreen() {
for (int j = 0; j < 100; j++)
System.out.println();
}
/**
* Prints the main title graphics for the starting screen
*/
public static void mainMenu() {
String pokeTitle =
" .::. \n" +
" .;:**' \n" +
" ` \n" +
" .:XHHHHk. db. .;;. dH MX \n" +
"oMMMMMMMMMMM ~MM dMMP :MMMMMR MMM MR ~MRMN \n" +
"QMMMMMb 'MMX MMMMMMP !MX' :M~ MMM MMM .oo. XMMM 'MMM\n" +
" `MMMM. )M> :X!Hk. MMMM XMM.o' . MMMMMMM X?XMMM MMM>!MMP\n" +
" 'MMMb.dM! XM M'?M MMMMMX.`MMMMMMMM~ MM MMM XM `' MX MMXXMM \n" +
" ~MMMMM~ XMM. .XM XM`'MMMb.~*?**~ .MMX M t MMbooMM XMMMMMP \n" +
" ?MMM> YMMMMMM! MM `?MMRb. `MM !L'MMMMM XM IMMM \n" +
" MMMX 'MMMM' MM ~%: !Mh.''' dMI IMMP \n" +
" 'MMM. IMX \n" +
" ~M!M IM \n";
delayPrintTable(pokeTitle);
delayPrintln("");
delayPrintln("Datafile by: Aaron Li");
delayPrintln("Game made by: Ryan Zhang");
delayPrintln("");
delayPrintln("Welcome to pokemon");
pause();
}
/**
* prints the you win tag
*/
public static void win() {
clearScreen();
delayPrintln(" __ ______ _ _ __ _______ _ _ _ \n" +
" \\ \\ / / __ \\| | | | \\ \\ / /_ _| \\ | | |\n" +
" \\ \\_/ / | | | | | | \\ \\ /\\ / / | | | \\| | |\n" +
" \\ /| | | | | | | \\ \\/ \\/ / | | | . ` | |\n" +
" | | | |__| | |__| | \\ /\\ / _| |_| |\\ |_|\n" +
" |_| \\____/ \\____/ \\/ \\/ |_____|_| \\_(_)\n");
pause();
}
/**
* prints the you loose tag
*/
public static void lose() {
clearScreen();
delayPrintln(" _____ __ __ ______ ______ ________ _____ _ \n" +
" / ____| /\\ | \\/ | ____| / __ \\ \\ / / ____| __ \\| | \n" +
" | | __ / \\ | \\ / | |__ | | | \\ \\ / /| |__ | |__) | | \n" +
" | | |_ | / /\\ \\ | |\\/| | __| | | | |\\ \\/ / | __| | _ /| | \n" +
" | |__| |/ ____ \\| | | | |____ | |__| | \\ / | |____| | \\ \\|_| \n" +
" \\_____/_/ \\_\\_| |_|______| \\____/ \\/ |______|_| \\_(_) ");
pause();
}
/**
* the introduction screen
* @param pokemon The pokemon to be printed at the introduction
* @return Returns String[] with the first element being the player's name and the second being the enemy's name
*/
public static String[] intro(String pokemon) {
String[] names = new String[2];
clearScreen();
delayPrintln("Oak: Hello there! Welcome to the world of POKEMON! My name is OAK! People call me the POKEMON PROF!");
pause();
clearScreen();
delayPrintTable(pokemon);
delayPrintln("Oak: This world is inhabited by creatures called POKEMON! For some people, POKEMON are pets. Others use them for fights. Myself... I study POKEMON as a profession.");
pause();
clearScreen();
delayPrintln("Oak: First, what is your name?");
delayPrint(">>> ");
names[0] = input.next();
clearScreen();
delayPrintln("Oak: Right! So your name is " + names[0] + "!");
pause();
clearScreen();
delayPrintln("Oak: This is my grandson. He's been your rival since you were a baby. ...Erm, what is his name again?");
delayPrint(">>> ");
names[1] = input.next();
clearScreen();
delayPrintln("Oak: That's right! I remember now! His name is " + names[1] + "!");
pause();
clearScreen();
delayPrintln("Oak: " + names[0] + "! Your very own POKEMON legend is about to unfold! A world of dreams and adventures with POKEMON awaits! Let's go!");
pause();
clearScreen();
return names;
}
/**
* Displays the pokemons that are selected
* @param pokemonLibrary The pokedex
* @param selected The selected pokemons
*/
public static void displaySelected(Pokedex pokemonLibrary, ArrayList<Integer> selected) {
clearScreen();
delayPrintln("Oak: Great choice of POKEMONS.\n");
delayPrintTable(String.format("║ %-20s ║ %-5s ║ %-20s ║ %-20s ║ %-20s ║", "Name", "HP", "Type", "Resistance", "weakness"));
delayPrintTable("╠══════════════════════╬═══════╬══════════════════════╬══════════════════════╬══════════════════════╣");
for (Integer p : selected) { // Iterating through the pokemons printing each one
delayPrintTable(pokemonLibrary.getPokemon(p).toString());
}
pause();
}
/**
* Gettubg the user to select the pokemons
* @param pokedex The pokedex used
* @param number The number of pokemons for the user to select
* @return the list of pokemons selected
*/
public static ArrayList<Integer> selectPokemon(Pokedex pokedex, int number) {
ArrayList<Integer> selectedPokemons = new ArrayList<>(); // Declaring a new list for storing the selections
Pokemon selectedPokemon; // The current pokemon that is selected
String confirmation; // The confirmation
int pokemonCounter = 0; // The counter for the number of pokemon selected
int pokeSelect;
while (pokemonCounter < number) {
pokedex.printTable();
if (pokemonCounter > 0) { // Prints whats currently on the player's team
delayPrint("Your team currently has: ");
for (int n : selectedPokemons) {
delayPrint(pokedex.getPokemon(n).getName() + " ");
}
System.out.println();
}
pokeSelect = getRange("Error, please enter a valid Pokemon number.", "Please select a pokemon >>> ", 1, 151); // gets the input
selectedPokemon = pokedex.getPokemon(pokeSelect);
clearScreen();
delayPrintTable(pokedex.getPokemon(pokeSelect).getArt());
if (selectedPokemons.contains(pokeSelect)) { // If the pokemon has already been selected
delayPrintln(selectedPokemon.getName() + " is already on your team.");
pause();
} else {
delayPrintTable(String.format("║ %-20s ║ %-10s ║ %-10s ║ %-20s ║", "Attack", "EC", "DMG", "Special")); // displays the attacks for the selected pokemon
delayPrintTable("╠══════════════════════╬════════════╬════════════╬══════════════════════╣");
for (Attack a : selectedPokemon.getAttack()) {
delayPrintTable(a.toString());
}
confirmation = getData("You have chosen " + selectedPokemon.getName() + "(y/n) >>> ", "Invalid selection.", new String[]{"y", "n"}); // gets a confirmation
if (confirmation.equals("y") && !selectedPokemons.contains(pokeSelect)) { // confirmed
selectedPokemons.add(pokeSelect); // add the pokemon to the selected
pokemonCounter += 1;
delayPrintln(selectedPokemon.getName() + " has been added to your team.");
pause();
}
delayPrintln(confirmation);
}
}
return selectedPokemons;
}
}