-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinishedCode
More file actions
506 lines (463 loc) · 19.9 KB
/
FinishedCode
File metadata and controls
506 lines (463 loc) · 19.9 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
import java.util.Scanner;
public class BankRobberyGame {
public static final String RED = "\u001B[31m";
public static final String RESET = "\u001B[0m";
public static final String PINK = "\u001B[95m";
public static final String LIGHT_GREEN = "\u001B[92m";
public static final String LIGHT_BLUE = "\u001B[94m";
public static final String YELLOW = "\u001B[33m";
public static void main(String[] args) {
if (args.length != 0 && args[0].equals("-help")) {
displayHelp();
} else {
gamePlay();
}
}
public static void displayHelp() {
System.out.println("Erm, you really need help???");
}
public static void gamePlay() {
Scanner input = new Scanner(System.in);
printWelcomeMessage();
int breakInChoice = chooseBreakInMethod(input);
if (breakInChoice == 1) {
handleSneakily(input);
} else {
handleLoudly();
}
input.close();
}
// Method to print welcome message
public static void printWelcomeMessage() {
System.out.println(" ");
slowType(pink("Welcome to the Bank Robbery Simulator!"),50);
System.out.println(" ");
slowType(pink("You are about to rob the city's most secure bank."), 50);
System.out.println(" ");
//we used this link for our ASCII art (Output Width In Characters:30)
//https://convertcase.net/ascii-art-generator/
System.out.println(" ");
slowType(pink(" .::.:: "),5);
slowType(pink(" .:::...::.. "),5);
slowType(pink(" ::--+:.+--:.:.: "),5);
slowType(pink(" ::-..:==+**-=...::: "),5);
slowType(pink(" :::.................::."),5);
slowType(pink(" .:..................... "),5);
slowType(pink(" :---==---===--===--:. "),5);
slowType(pink(" .:-=#*--:*#*::+##:::. "),5);
slowType(pink(" .:+#*-:=**+.-+**+:: "),5);
slowType(pink(" .-#*+=:+*+=.-+++*:: "),5);
slowType(pink(" .-#*+-:+*+=.-++++:: "),5);
slowType(pink(" .-#*+-:+*+=.-++++:: "),5);
slowType(pink(" .-#*+-:+*+=.-++++:: "),5);
slowType(pink(" .-#*+-:+*+=.-++++:: "),5);
slowType(pink(" .-#*+=:+*+=.-+++*:: "),5);
slowType(pink(" .-##*-:=**+.-***.:-. "),5);
slowType(pink(" .:=*+-:-*++.:+++.::. "),5);
slowType(pink(" ..................... "),5);
slowType(pink(" ....................... "),5);
slowType(pink(" ............... "),5);
System.out.println(" ");
slowType(pink("****************************\n"), 50);
System.out.println(" ");
}
//method to choose break-in method
public static int chooseBreakInMethod(Scanner input) {
int breakInChoice;
do {
slowType(blue("How do you want to break into the bank?"), 50);
System.out.println(" ");
slowType(red("Answer using 1 or 2"), 50);
System.out.println(" ");
slowType(yellow("1. Sneakily"), 50); //lower risk of getting caught
System.out.println(" ");
slowType(yellow("2. Loudly"), 50); //higher risk of getting caught
System.out.println(" ");
//informing the user of invalid input
if (input.hasNextInt()) {
int choice = input.nextInt();
if (choice >= 1 && choice <= 2) {
breakInChoice = choice;
break;
} else {
slowType(red("Invalid input! Please enter 1 or 2"), 50);
System.out.println(" ");
}
} else {
slowType(red("Invalid input! Please enter 1 or 2"), 50);
System.out.println(" ");
input.next();
}
} while (true);
return breakInChoice;
}
//method to handle sneakily breaking in
public static void handleSneakily(Scanner input) {
slowType(blue("You choose to break in sneakily."),50);
System.out.println(" ");
slowType(blue("You carefully plan your approach, avoiding detection by security"),50);
//user inputs for these other methods if user chooses to be sneaky
handleSecurityCameras(input);
handleDiamond(input);
handleBigDoor(input);
handleInsideVault(input);
handleEscaping(input);
}
//method to handle loudly breaking in
public static void handleLoudly() {
slowType(blue("You choose to break in loudly"),50);
slowType(blue("You cause a commotion, alerting security"),50);
System.out.println(" ");
slowType(blue("You get caught by the police and go to jail...what a loser"),50);
slowType(red("You lost!"),50);
//https://www.patorjk.com
slowType(red(" _____ ____ "), 5);
slowType(red(" / ____| / __ \\ "), 5);
slowType(red("| | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ "), 5);
slowType(red("| | |_ |/ _` | '_ ` _ \\ / _ \\ | | | \\ \\ / / _ \\ '__|"), 5);
slowType(red("| |__| | (_| | | | | | | __/ | |__| |\\ V / __/ | "), 5);
slowType(red(" \\_____|\\__,_|_| |_| |_|\\___| \\____/ \\_/ \\___|_| "), 5);
}
//method to handle security cameras scenario
public static void handleSecurityCameras(Scanner input) {
int cameraChoice;
do {
System.out.println(" ");
slowType(blue("You are now inside the bank. What do you want to do about the security cameras?"), 50);
System.out.println(" ");
slowType(red("Answer using 1, 2, or 3"), 50);
System.out.println(" ");
slowType(yellow("1. Disable the security cameras"), 50);
System.out.println(" ");
slowType(yellow("2. Spray paint the cameras"), 50);
System.out.println(" ");
slowType(yellow("3. Leave the cameras alone"), 50);
System.out.println(" ");
if (input.hasNextInt()) {
int choice = input.nextInt();
if (choice >= 1 && choice <= 3) {
cameraChoice = choice;
break;
} else {
slowType(red("Invalid input! Please enter 1, 2, or 3"), 50);
System.out.println(" ");
}
} else {
slowType(red("Invalid input! Please enter 1, 2, or 3"), 50);
System.out.println(" ");
input.next(); // Consume the invalid input
}
} while (true);
System.out.println(" ");
if (cameraChoice == 1) {
slowType(blue("You successfully disable the security cameras"), 50);
slowType(blue("The security guard gets distracted trying to fix the cameras"), 50);
System.out.println(" ");
} else if (cameraChoice == 2) {
slowType(blue("You spray paint the security cameras to obscure their vision"), 50);
slowType(blue("It's a risky move, but it might buy you some time"), 50);
System.out.println(" ");
double chanceOfBeingSeen = Math.random();
if (chanceOfBeingSeen < 0.5) { //50% chance of being seen
slowType(blue("Uh oh! A security guard saw what you did! Hurry!"), 50);
slowType(blue("You need to act fast!"), 50);
}
} else {
slowType(red("NOOO! They saw you coming!"), 50);
//https://www.patorjk.com
slowType(red(" _____ ____ "), 5);
slowType(red(" / ____| / __ \\ "), 5);
slowType(red("| | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ "), 5);
slowType(red("| | |_ |/ _` | '_ ` _ \\ / _ \\ | | | \\ \\ / / _ \\ '__|"), 5);
slowType(red("| |__| | (_| | | | | | | __/ | |__| |\\ V / __/ | "), 5);
slowType(red(" \\_____|\\__,_|_| |_| |_|\\___| \\____/ \\_/ \\___|_| "), 5);
System.exit(0);
}
}
//method to handle diamond scenario
public static void handleDiamond(Scanner input) {
int diamondChoice;
do {
slowType(blue("You spot a cool looking diamond on display"), 50);
System.out.println(" ");
//https://convertcase.net/ascii-art-generator/
slowType(pink(" . "), 5);
slowType(pink(" :-.=+:--= "), 5);
slowType(pink(" :..==:: -:..: "), 5);
slowType(pink(":::-::.-.::..=+"), 5);
slowType(pink(" =-==-.-=-:.-= "), 5);
slowType(pink(" -:-:. =-.:: "), 5);
slowType(pink(" :::. -:.: "), 5);
slowType(pink(" .:. :.. "), 5);
slowType(pink(" .. .. "), 5);
System.out.println(" ");
slowType(blue("What do you want to do?"), 50);
System.out.println(" ");
slowType(red("Answer using 1 or 2"), 50);
System.out.println(" ");
slowType(yellow("1. Steal it"), 50);
System.out.println(" ");
slowType(yellow("2. Leave it alone"), 50);
System.out.println(" ");
if (input.hasNextInt()) {
int choice = input.nextInt();
if (choice >= 1 && choice <= 2) {
diamondChoice = choice;
break;
} else {
slowType(red("Invalid input! Please enter 1 or 2"), 50);
System.out.println(" ");
}
} else {
slowType(red("Invalid input! Please enter 1 or 2"), 50);
System.out.println(" ");
input.next();
}
} while (true);
input.nextLine();
if (diamondChoice == 1) {
slowType(blue("You decide to steal the diamond..."), 50);
System.out.println(" ");
if (decidesToStealDiamond(input)) {
slowType(blue("You successfully steal the diamond!"), 50);
System.out.println(" ");
slowType(blue("As you grab it, an alarm goes off!"), 50);
System.out.println(" ");
slowType(blue("You need to move quickly!"), 50);
System.out.println(" ");
}
} else {
slowType(blue("You choose to leave the diamond alone and focus on the main objective"), 50);
System.out.println(" ");
}
}
//mini game to steal diamond
public static boolean decidesToStealDiamond(Scanner input) {
slowType(blue("To steal the diamond you have to play a number guessing game"),50);
slowType(blue("Good luck I guess!"),50);
int secretNumber = (int) (Math.random() * 10) + 1; //random number between 1 and 10
slowType(blue("Guess the secret number between 1 and 10:"), 50);
System.out.println(" ");
int guess;
do {
while (!input.hasNextInt()) {
slowType(red("Please enter a number between 1 and 10"), 50);
input.next();
}
guess = input.nextInt();
input.nextLine();
if (guess < 1 || guess > 10) {
slowType(red("Please enter a number between 1 and 10"), 50);
System.out.println(" ");
}
} while (guess < 1 || guess > 10);
if (guess == secretNumber) {
slowType(green("Congratulations! You guessed the secret number!"), 50);
return true;
} else {
slowType(red("Sorry, the secret number was " + secretNumber + ". You failed to steal the diamond!"), 50);
System.out.println(" ");
return false;
}
}
//method to handle big door scenario
public static void handleBigDoor(Scanner input) {
slowType(blue("You reach a big door leading to the vault"),50);
System.out.println(" ");
slowType(blue("How do you want to proceed?"),50);
System.out.println(" ");
slowType(red("Answer using 1 or 2"),50);
System.out.println(" ");
slowType(yellow("1. Blow up the door with an explosive"),50);
System.out.println(" ");
slowType(yellow("2. Make a hole in the door to go in"),50);
System.out.println(" ");
int doorChoice;
do {
while (!input.hasNextInt()) {
slowType(red("Please enter 1 or 2"),50);
input.next();
}
doorChoice = input.nextInt();
if (doorChoice < 1 || doorChoice > 2) {
slowType(red("Invalid input! Please enter 1 or 2"),50);
System.out.println(" ");
}
} while (doorChoice < 1 || doorChoice > 2);
input.nextLine();
if (doorChoice == 1) {
slowType(red("Another alarm goes off! You need to hurry!"),50);
System.out.println(" ");
} else {
slowType(blue("You decide to make a hole in the door to go in..."),50);
System.out.println(" ");
slowType(blue("You manage to bypass the alarm and enter the vault"),50);
System.out.println(" ");
}
}
//method to handle inside vault scenario
public static void handleInsideVault(Scanner input) {
slowType(blue("You are now inside the vault"),50);
System.out.println(" ");
slowType(red("Answer using 1 or 2"),50);
System.out.println(" ");
slowType(yellow("1. Break everything inside the vault"),50);
System.out.println(" ");
slowType(yellow("2. Steal"),50);
System.out.println(" ");
int insideVaultChoice;
do {
while (!input.hasNextInt()) {
slowType(red("Please enter 1 or 2"),50);
input.next();
}
insideVaultChoice = input.nextInt();
if (insideVaultChoice < 1 || insideVaultChoice > 2) {
slowType(red("Invalid input! Please enter 1 or 2"),50);
System.out.println(" ");
}
} while (insideVaultChoice < 1 || insideVaultChoice > 2);
input.nextLine();
if (insideVaultChoice == 1) {
slowType(blue("What was the point of going in then... whatever!"),50);
System.out.println(" ");
slowType(blue("You need to hurry or you'll get caught!"),50);
System.out.println(" ");
} else {
slowType(blue("You decide to steal..."), 50);
System.out.println(" ");
if (decidesToSteal(input)) {
slowType(blue("Yaasss! you unscrambled the word and stole the goodies!"), 50);
System.out.println(" ");
slowType(blue("You manage to bypass the alarm and leave the vault"), 50);
System.out.println(" ");
} else {
slowType(blue("If you don't know how to write you aren't a good robber..."), 50);
System.out.println(" ");
slowType(red("You're quickly apprehended and sent to jail. Game over!"), 50);
}
}
}
//part of the code were we asked for help
//Jasmine suggested having two methods (boolean and string)
//so the coding could be more easier, understandable and also work
//word scramble mini-game if user wants to steal
public static boolean decidesToSteal(Scanner input) {
slowType(blue("So you want to steal..."), 50);
slowType(blue("To do so, you have to unscramble the letters I give you and make a word"), 50);
slowType(blue("I hope you know how to write..."), 50);
System.out.println(" ");
String[] words = {"diamond", "money", "bank", "robber", "heist"};
int randomIndex = (int) (Math.random() * words.length);
String scrambledWord = scrambleWord(words[randomIndex]);
slowType(blue("Scrambled word: " + scrambledWord),50);
slowType(blue("Your guess: "),50);
String wordGuess = input.nextLine().toLowerCase();
return wordGuess.equals(words[randomIndex]);
}
//we used the character i cause we thought it'd be easier for us to code
//scrambled word
public static String scrambleWord(String word) {
char[] chars = word.toCharArray();
for (int i = 0; i < chars.length; i++) {
int randomIndex = (int) (Math.random() * chars.length);
char temp = chars[i];
chars[i] = chars[randomIndex];
chars[randomIndex] = temp;
}
return new String(chars);
}
//method to handle escaping scenario
public static void handleEscaping(Scanner input) {
slowType(blue("You gotta go"),50);
System.out.println(" ");
slowType(red("Answer using 1 or 2"),50);
System.out.println(" ");
slowType(yellow("1. Blow the bank up"),50);
System.out.println(" ");
slowType(yellow("2. Run away as fast as you can"),50);
System.out.println(" ");
int runningAwayChoice;
do {
while (!input.hasNextInt()) {
slowType(red("Please enter 1 or 2"),50);
input.next();
}
runningAwayChoice = input.nextInt();
if (runningAwayChoice < 1 || runningAwayChoice > 2) {
slowType(red("Invalid input! Please enter 1 or 2"),50);
System.out.println(" ");
}
} while (runningAwayChoice < 1 || runningAwayChoice > 2);
input.nextLine();
if (runningAwayChoice == 1) {
slowType(blue("You blow up the bank, but the explosion attracts police attention."),50);
System.out.println(" ");
slowType(red("You're quickly apprehended and sent to jail!"),50);
//https://www.patorjk.com
slowType(red(" _____ ____ "), 5);
slowType(red(" / ____| / __ \\ "), 5);
slowType(red("| | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ "), 5);
slowType(red("| | |_ |/ _` | '_ ` _ \\ / _ \\ | | | \\ \\ / / _ \\ '__|"), 5);
slowType(red("| |__| | (_| | | | | | | __/ | |__| |\\ V / __/ | "), 5);
slowType(red(" \\_____|\\__,_|_| |_| |_|\\___| \\____/ \\_/ \\___|_| "), 5);
} else {
double escapeChance = Math.random();
if (escapeChance < 0.5) { //50% chance of successful escape
slowType(blue("You run away as fast as you can..."),50);
System.out.println(" ");
slowType(blue("You manage to escape from the bank"),50);
System.out.println(" ");
slowType(green("Congratulations! You successfully robbed the bank and got away with it!"),50);
//https://www.patorjk.com
slowType(green(" __ __ __ __"), 5);
slowType(green(" \\ \\ / / \\ \\ / /"), 5);
slowType(green(" \\ V /__ _|\\ V / "), 5);
slowType(green(" \\ // _` | \\ /"), 5);
slowType(green(" | | (_| | | | "), 5);
slowType(green(" \\_/\\__,_| \\_/"), 5);
} else {
slowType(blue("You run away as fast as you can..."),50);
System.out.println(" ");
slowType(blue("Oh no! The police catch up with you!"),50);
System.out.println(" ");
slowType(red("You're quickly apprehended and sent to jail!"),50);
//https://www.patorjk.com
slowType(red(" _____ ____ "), 5);
slowType(red(" / ____| / __ \\ "), 5);
slowType(red("| | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ "), 5);
slowType(red("| | |_ |/ _` | '_ ` _ \\ / _ \\ | | | \\ \\ / / _ \\ '__|"), 5);
slowType(red("| |__| | (_| | | | | | | __/ | |__| |\\ V / __/ | "), 5);
slowType(red(" \\_____|\\__,_|_| |_| |_|\\___| \\____/ \\_/ \\___|_| "), 5);
}
}
}
//making the text print out slowly to make it like an actual text based game
public static void slowType(String s, long delay) {
for (int i = 0; i < s.length(); i++) {
System.out.print(s.charAt(i));
try {
Thread.sleep(delay); //adds delay between characters
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(); //adds a newline after printing the whole string
}
//adding color to our code
public static String red(String s){
return RED + s + RESET;
}
public static String pink(String s){
return PINK + s + RESET;
}
public static String green(String s){
return LIGHT_GREEN + s + RESET;
}
public static String blue(String s){
return LIGHT_BLUE + s + RESET;
}
public static String yellow(String s){
return YELLOW + s + RESET;
}
}