Repository navigation
Expand file tree
/
Copy pathControl.java
More file actions
1042 lines (948 loc) · 32.3 KB
/
Copy pathControl.java
File metadata and controls
1042 lines (948 loc) · 32.3 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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* title: Control.java
* description: This class contains the majority of the
* methods for the Locations class to use.
* date: January 23, 2021
* @author Jenna McDonnell
* @version 1.0
* 3435506
*/
/************************************************************
* METHODS
************************************************************
* <H3> Methods <H3>
*
* <P>
* public void bankIntro(String text){<BR>
Introduces the river bank scene.
* public void climbDownTree(String text){<BR>
Outputs text and tests for answers after climbing
down the tree.
* public void climbHigher(String text){<BR>
Outputs text and tests for answers after climbing
higher up the tree.
* public void investigateRedObject(String text, String text2){<BR>
Outputs text, adds a heart to inventory and tests for answers
after gaining the heart.
* public void goToRiver(String text){<BR>
Outputs text and tests for answers at the river.
* public void openChest(String text){<BR>
Outputs text and tests for answers after trying to open
the chest in the river.
* public void backToSister(String text){<BR>
Outputs text and tests for answers while standing beside
sister.
* public void lookAtBook(String text){<BR>
Outputs text and tests for answer while looking at
sister's book.
* public void classChosen(String text){<BR>
Outputs text and waits for user to type "adventure".
* public void rabbitIntro(String text){<BR>
Outputs text for the rabbit hole introduction and
tests for answer.
* public void lookAroundBush(String text){<BR>
Outputs text and tests for answer when looking around the
bush above the rabbit hole.
* public void pickUpMetal(String text){<BR>
Outputs text and tests for answer on what the user wants
to do after finding the piece of metal.
* public void crawlInHole(String text){<BR>
Outputs text and tests for answer after the player crawls into
the rabbit hole.
* public void lookForMoreBushItems(String text){<BR>
Outputs text and tests for answer after player chooses to look for
more items around the bush that is above the rabbit hole.
* public void takeItem(String text){<BR>
Outputs text and tests for answer of which item the player
wants to take while falling down the rabbit hole.
* public String openBag(String answer){<BR>
Opens bag and tests for player's answer on what they
want to do with the item they chose to use in their bag.
* public void lookAroundHole(String text){<BR>
Outputs text and tests for answer on what the player wants
to do after looking around the rabbit hole for items.
* public void pickItem(String text){<BR>
Outputs text and tests for answer on what the player wants
to do after taking an item in the rabbit hole.
* public void dropCandlestick(String text){<BR>
Outputs text and tests for what player wants to do after
dropping the candlestick.
* public void letGoAxe(String text){<BR>
Outputs text and tests for answer on what the
player wants to do after letting go of the axe.
* public void swingAxe(String text){<BR>
Outputs text and tests for answer on what the user wants
to do after swinging the axe.
* public void afterBatFight(String text){<BR>
Outputs text after the bat fight.
* public void hallwayIntro(String text){<BR>
Outputs text and tests for answer on what the player
wants to do upon entering the hallway.
* public void tryDoor(String text){<BR>
Outputs text and tests for answer on what the player wants to
do after trying to open one of the doors.
* public void table1(String text){<BR>
Outputs text and tests for answer if the player has already
examined table 1.
* public void table2(String text){<BR>
Outputs text and tests for answer if player has already examined
table 2.
* public void table3(String text1, String text2){<BR>
Outputs text and tests for answer if player has already examined
table 3.
* public void foundPotion(String text){<BR>
Outputs text, adds potion to inventory, and tests for answer
on what the player wants to do after finding the potion.
* public void foundKey(String text){<BR>
Outputs text and tests for answer on what the player wants to
do after finding the key.
* public void foundTableHeart(String text1, String text2){<BR>
Outputs text and tests for answer on what the player wants
to do after finding the extra heart on one of the tables in the
hallway.
* public boolean usePotion(){<BR>
Uses potion after testing to make sure it is in the
player's inventory and shrinks Alice if she is normal sized or
grows her if she is shrunk.
* public void smallDoor(String text){<BR>
Outputs text and gets an answer after Alice tries to
go through the small door.
* public void hallwayEnding(String text){<BR>
Outputs text to end the hallway scene.
* public void forestIntro(String text){<BR>
Outputs text to introduce the forest scene and tests
for answer on which direction the player wants to go.
* public boolean race(String text1, String text2){<BR>
Implements the race mechanics and explains the rules
to the player. Creates five random numbers from 1 to
10 and uses them to output three different equations for
the user to answer. If the user answers all three correctly,
they win the game and gain a heart.
* public void cheshireCat(String text1){<BR>
Implements the interaction with the Cheshire Cat. Tests
to see if piece of metal is in inventory and gives player
the chance to tell the truth and gain 2 hearts or lie and
lose 1 heart. If the player does not have the piece of metal,
they can't do anything here.
* public void castleIntro(String text){<BR>
Outputs text to introduce the castle scene and
tests for answer on whether the player agrees to
play the Queen's game or not.
* public boolean queenGame(String text1, String text2){<BR>
Outputs text and implements the game of croquet
with the Queen. Player gains points by guessing
which number the computer chose, either 1 or 2,
gaining a point if they guess correctly. If they guess
incorrectly, the player loses half a heart. The
game is over if the player gains 3 points or runs
out of hearts.
* public void defaultOutput(){<BR>
Outputs a default text if the user does not input an acceptable
answer and tests for their next answer.
* public void getAnswer(){<BR>
Gets the user's answer using the input Scanner and
converts the answer to lower case.
* public String testForMultipleAnswers(String answer, String output,
String option1, String option2, String option3){<BR>
Tests answer to see which acceptable answer the user was
trying to input.
* </P>
*/
/************************************************************
* VARIABLES
************************************************************
* <H3> Variables Used </H3>
*
* <P>
* public String answer; - the answer the user inputs
*
* public Scanner input = new Scanner(System.in); -
* the Scanner being used to retrieve the user's input
*
* Inventory invent = new Inventory(); - creates an inventory
* object to store items
*
* String clas; - stores the class of the character chosen
*
* boolean table1 = false; - true if table 1 has already
* been examined
*
* boolean table2 = false; - true if table 2 has already
* been examined
*
* boolean table3 = false; - true if table 3 has already
* been examined
*
* Boolean shrunk = false; - true when Alice is in a shrunken
* state after drinking the potion
*
* int points = 0; - number of points player has in the
* croquet game
* </P>
*/
import java.util.*;
import java.io.*;
public class Control{
//the answer the user inputs
public String answer;
//the Scanner being used to retrieve the user's input
public Scanner input = new Scanner(System.in);
//creates an inventory object to store items
Inventory invent = new Inventory();
/*
* Introduces the river bank scene.
*
* @param String text the text being output
*/
public void bankIntro(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "climb down tree",
"a", "climb down", "go down");
answer = testForMultipleAnswers(answer, "climb higher",
"b", "climb up", "go up");
}
/*
* Outputs text and tests for answers after climbing down the tree.
*
* @param String text the text being output
*/
public void climbDownTree(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "go to the river",
"a", "go to river", "river");
answer = testForMultipleAnswers(answer, "look at sister's book",
"b", "look at book", "book");
}
/*
* Outputs text and tests for answers after climbing higher up the tree.
*
* @param String text the text being output
*/
public void climbHigher(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "investigate the red object",
"a", "red object", "investigate");
answer = testForMultipleAnswers(answer, "climb down",
"b", "down", "go down");
}
/*
* Outputs text, adds a heart to inventory and tests for answers after gaining
* the heart.
*
* @param String text the first text being output
* @param String text2 the second text being output
*/
public void investigateRedObject(String text, String text2){
System.out.println(text);
invent.heartMeter(1);
System.out.println(text2);
getAnswer();
answer = testForMultipleAnswers(answer, "go to the river",
"a", "go to river", "river");
answer = testForMultipleAnswers(answer, "look at sister's book",
"b", "look at book", "book");
}
/*
* Outputs text and tests for answers at the river.
*
* @param String text the text being output
*/
public void goToRiver(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "open the chest",
"a", "open chest", "open");
answer = testForMultipleAnswers(answer, "go back to sister",
"b", "back to sister", "go back");
}
/*
* Outputs text and tests for answers after trying to open
* the chest in the river.
*
* @param String text the text being output
*/
public void openChest(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "open the chest",
"a", "open chest", "open");
answer = testForMultipleAnswers(answer, "go back to sister",
"b", "back to sister", "go back");
}
/*
* Outputs text and tests for answers while standing beside
* sister.
*
* @param String text the text being output
*/
public void backToSister(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "go to the river",
"a", "go to river", "river");
answer = testForMultipleAnswers(answer, "look at sister's book",
"b", "look at book", "book");
}
//stores the class of the character chosen
String clas;
/*
* Outputs text and tests for answer while looking at
* sister's book.
*
* @param String text the text being output
*/
public void lookAtBook(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "assassin",
"a", "a", "1");
answer = testForMultipleAnswers(answer, "wizard",
"b", "w", "2");
answer = testForMultipleAnswers(answer, "shapeshifter",
"c", "s", "3");
clas = answer;
}
/*
* Outputs text and waits for user to type "adventure".
*
* @param String text the text being output
*/
public void classChosen(String text){
System.out.println(text);
getAnswer();
}
/*
* Outputs text for the rabbit hole introduction and
* tests for answer.
*
* @param String text the text being output
*/
public void rabbitIntro(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "crawl into the hole",
"a", "crawl in", "go down");
answer = testForMultipleAnswers(answer, "look around the bush",
"b", "look around the bush", "look");
}
/*
* Outputs text and tests for answer when looking around the
* bush above the rabbit hole.
*
* @param String text the text being output
*/
public void lookAroundBush(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "pick up the piece of metal",
"a", "pick up the piece of metal", "pick up metal");
answer = testForMultipleAnswers(answer, "crawl into the hole",
"b", "crawl into the hole", "crawl");
}
/*
* Outputs text and tests for answer on what the user wants
* to do after finding the piece of metal.
*
* @param String text the text being output
*/
public void pickUpMetal(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "look around for more items",
"a", "look", "look around");
answer = testForMultipleAnswers(answer, "crawl into the hole",
"b", "crawl in", "go down");
}
/*
* Outputs text and tests for answer after the player crawls into
* the rabbit hole.
*
* @param String text the text being output
*/
public void crawlInHole(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "take one of the items",
"a", "take item", "item");
answer = testForMultipleAnswers(answer, "look around",
"b", "look", "look more");
answer = testForMultipleAnswers(answer, "open bag",
"c", "open", "bag");
}
/*
* Outputs text and tests for answer after player chooses to look for
* more items around the bush that is above the rabbit hole.
*
* @param String text the text being output
*/
public void lookForMoreBushItems(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "look around for more items",
"a", "look", "look around");
answer = testForMultipleAnswers(answer, "crawl into the hole",
"b", "crawl in", "go down");
}
/*
* Outputs text and tests for answer of which item the player
* wants to take while falling down the rabbit hole.
*
* @param String text the text being output
*/
public void takeItem(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "matches",
"a", "lighter", "fire");
answer = testForMultipleAnswers(answer, "candlestick",
"b", "candle", "firestick");
answer = testForMultipleAnswers(answer, "pick axe",
"c", "axe", "pick");
}
/*
* Opens bag and tests for player's answer on what they
* want to do with the item they chose to use in their bag.
*
* @param String answer the current answer
*
* @return String answer the current answer
*/
public String openBag(String answer){
answer = invent.openBag();
if(answer.equals("noAnswer")){
System.out.println("What do you want to do?");
getAnswer();
}else{
String temp = answer;
switch(temp){
case "candlestick":
answer = input.nextLine();
answer = answer.toLowerCase();
answer = testForMultipleAnswers(answer, "light candle",
"a", "light", "candle");
answer = testForMultipleAnswers(answer, "drop candle",
"b", "drop", "drop candle");
break;
case "pick axe":
answer = input.nextLine();
answer = answer.toLowerCase();
answer = testForMultipleAnswers(answer, "swing axe",
"a", "swing", "axe");
answer = testForMultipleAnswers(answer, "drop axe",
"b", "drop", "drop axe");
break;
case "potion":
answer = input.nextLine();
answer = answer.toLowerCase();
answer = testForMultipleAnswers(answer, "drink potion",
"a", "drink", "potion");
break;
}
}
return answer;
}
/*
* Outputs text and tests for answer on what the player wants
* to do after looking around the rabbit hole for items.
*
* @param String text the text being output
*/
public void lookAroundHole(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "take one of the items",
"a", "take item", "item");
answer = testForMultipleAnswers(answer, "look around",
"b", "look", "look more");
answer = testForMultipleAnswers(answer, "open bag",
"c", "open", "bag");
}
/*
* Outputs text and tests for answer on what the player wants
* to do after taking an item in the rabbit hole.
*
* @param String text the text being output
*/
public void pickItem(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "take one of the items",
"a", "take item", "item");
answer = testForMultipleAnswers(answer, "look around",
"b", "look", "look more");
answer = testForMultipleAnswers(answer, "open bag",
"c", "open", "bag");
}
/*
* Outputs text and tests for what player wants to do after
* dropping the candlestick.
*
* @param String text the text being output
*/
public void dropCandlestick(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "open bag",
"a", "open", "bag");
answer = testForMultipleAnswers(answer, "look around",
"b", "look", "around");
}
/*
* Outputs text and tests for answer on what the
* player wants to do after letting go of the axe.
*
* @param String text the text being output
*/
public void letGoAxe(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "open bag",
"a", "open", "bag");
answer = testForMultipleAnswers(answer, "look around",
"b", "look", "around");
}
/*
* Outputs text and tests for answer on what the user wants
* to do after swinging the axe.
*
* @param String text the text being output
*/
public void swingAxe(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "let go of pick axe",
"a", "let go", "drop axe");
answer = testForMultipleAnswers(answer, "open bag",
"b", "open", "bag");
answer = testForMultipleAnswers(answer, "fight",
"c", "weapon", "hit");
}
/*
* Outputs text after the bat fight.
*
* @param String text the text being output
*/
public void afterBatFight(String text){
System.out.println(text);
}
/*
* Outputs text and tests for answer on what the player
* wants to do upon entering the hallway.
*
* @param String text the text being output
*/
public void hallwayIntro(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "try one of the doors",
"a", "doors", "open");
answer = testForMultipleAnswers(answer, "examine table 1",
"b", "1", "table 1");
answer = testForMultipleAnswers(answer, "examine table 2",
"c", "2", "table 2");
answer = testForMultipleAnswers(answer, "examine table 3",
"d", "3", "table 3");
}
/*
* Outputs text and tests for answer on what the player wants to
* do after trying to open one of the doors.
*
* @param String text the text being output
*/
public void tryDoor(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "examine table 1",
"a", "1", "table 1");
answer = testForMultipleAnswers(answer, "examine table 2",
"b", "2", "table 2");
answer = testForMultipleAnswers(answer, "examine table 3",
"c", "3", "table 3");
}
//true if table 1 has already been examined
boolean table1 = false;
//true if table 2 has already been examined
boolean table2 = false;
//true if table 3 has already been examined
boolean table3 = false;
/*
* Outputs text and tests for answer if the player has already
* examined table 1.
*
* @param String text some of the text being output
*/
public void table1(String text){
if(table1 == true){
System.out.println("You already examined this table.");
System.out.println("These are your options from here: ");
System.out.println(" a) open bag");
System.out.println(" b) examine table 2");
System.out.println(" c) examine table 3");
getAnswer();
answer = testForMultipleAnswers(answer, "open bag",
"a", "open", "bag");
answer = testForMultipleAnswers(answer, "examine table 2",
"b", "2", "table 2");
answer = testForMultipleAnswers(answer, "examine table 3",
"c", "3", "table 3");
}else{
foundPotion(text);
table1 = true;
}
}
/*
* Outputs text and tests for answer if player has already examined
* table 2.
*
* @param String text some of the text being output
*/
public void table2(String text){
if(table2 == true){
System.out.println("You already examined this table.");
System.out.println("These are your options from here: ");
System.out.println(" a) try the small door");
System.out.println(" b) try the medium door");
System.out.println(" c) try the big door");
getAnswer();
answer = testForMultipleAnswers(answer, "try the small door",
"a", "small", "small door");
answer = testForMultipleAnswers(answer, "try the medium door",
"b", "medium", "medium door");
answer = testForMultipleAnswers(answer, "try the big door",
"c", "big", "big door");
}else{
foundKey(text);
table2 = true;
}
}
/*
* Outputs text and tests for answer if player has already examined
* table 3.
*
* @param String text1 the first text being output
* @param String text2 the second text being output
*/
public void table3(String text1, String text2){
if(table3 == true){
System.out.println("You already examined this table.");
System.out.println("These are your options from here: ");
System.out.println(" a) examine table 1");
System.out.println(" b) examine table 2");
getAnswer();
answer = testForMultipleAnswers(answer, "examine table 1",
"a", "1", "table 1");
answer = testForMultipleAnswers(answer, "examine table 2",
"b", "2", "table 2");
}else{
foundTableHeart(text1, text2);
table3 = true;
}
}
/*
* Outputs text, adds potion to inventory, and tests for answer
* on what the player wants to do after finding the potion.
*
* @param String text the text being output
*/
public void foundPotion(String text){
System.out.println(text);
invent.addToBag("potion");
getAnswer();
answer = testForMultipleAnswers(answer, "open bag",
"a", "open", "bag");
answer = testForMultipleAnswers(answer, "examine table 2",
"b", "2", "table 2");
answer = testForMultipleAnswers(answer, "examine table 3",
"c", "3", "table 3");
}
/*
* Outputs text and tests for answer on what the player wants to
* do after finding the key.
*
* @param String text the text being output
*/
public void foundKey(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "try the small door",
"a", "small", "small door");
answer = testForMultipleAnswers(answer, "try the medium door",
"b", "medium", "medium door");
answer = testForMultipleAnswers(answer, "try the big door",
"c", "big", "big door");
}
/*
* Outputs text and tests for answer on what the player wants
* to do after finding the extra heart on one of the tables in the
* hallway.
*
* @param String text1 the first text being output
* @param String text2 the second text being output
*/
public void foundTableHeart(String text1, String text2){
System.out.println(text1);
invent.heartMeter(1);
System.out.println(text2);
getAnswer();
answer = testForMultipleAnswers(answer, "examine table 1",
"a", "1", "table 1");
answer = testForMultipleAnswers(answer, "examine table 2",
"b", "2", "table 2");
}
//true when Alice is in a shrunken state after drinking the potion
Boolean shrunk = false;
/*
* Uses potion after testing to make sure it is in the
* player's inventory and shrinks Alice if she is normal sized or
* grows her if she is shrunk.
*
* @return boolean shunk whether Alice is shrunk or not
*/
public boolean usePotion(){
if(invent.searchBag("potion")){
if(shrunk == false){
shrunk = true;
System.out.println("You shrink to the size of a small garden gnome.");
}else{
shrunk = false;
System.out.println("You grow back to your normal size.");
}
}else{
System.out.println("You do not have the potion.");
}
return shrunk;
}
/*
* Outputs text and gets an answer after Alice tries to
* go through the small door.
*
* @param String text the text being output
*/
public void smallDoor(String text){
System.out.println(text);
System.out.println("What do you want to do?");
getAnswer();
}
/*
* Outputs text to end the hallway scene.
*
* @param String text the text being output
*/
public void hallwayEnding(String text){
System.out.println(text);
}
/*
* Outputs text to introduce the forest scene and tests
* for answer on which direction the player wants to go.
*
* @param String text the text being output
*/
public void forestIntro(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "left",
"a", "l", "go left");
answer = testForMultipleAnswers(answer, "forward",
"b", "f", "go forward");
answer = testForMultipleAnswers(answer, "right",
"c", "r", "go right");
}
/*
* Implements the race mechanics and explains the rules
* to the player. Creates five random numbers from 1 to
* 10 and uses them to output three different equations for
* the user to answer. If the user answers all three correctly,
* they win the game and gain a heart.
*
* @param String text1 the first text being output
* @param String text2 the second text being output
*
* @return boolean true if race won, false if lost
*/
public boolean race(String text1, String text2){
int equals;
System.out.println(text1);
int num1, num2, num3, num4, num5;
num1 = (int)(Math.random() * 10 + 1);
num2 = (int)(Math.random() * 10 + 1);
num3 = (int)(Math.random() * 10 + 1);
num4 = (int)(Math.random() * 10 + 1);
num5 = (int)(Math.random() * 10 + 1);
System.out.println(num1 + " * " + num2 + " = ");
equals = input.nextInt();
if(equals != num1 * num2){
System.out.println("You lost the race :(");
return false;
}
System.out.println(num3 + " * " + num4 + " + " + num5 + " = ");
equals = input.nextInt();
if(equals != num3 * num4 + num5){
System.out.println("You lost the race :(");
return false;
}
System.out.println(num1 + " + " + num3 + " * " + num5 + " + "
+ num4 + " - " + num2 + " = ");
equals = input.nextInt();
if(equals != num1 + num3 * num5 + num4 - num2){
System.out.println("You lost the race :(");
return false;
}else{
System.out.println("You won the race :)");
invent.heartMeter(1);
System.out.println(text2);
answer = input.nextLine();
getAnswer();
answer = testForMultipleAnswers(answer, "forward",
"a", "f", "go forward");
answer = testForMultipleAnswers(answer, "right",
"b", "r", "go right");
return true;
}
}
/*
* Implements the interaction with the Cheshire Cat. Tests
* to see if piece of metal is in inventory and gives player
* the chance to tell the truth and gain 2 hearts or lie and
* lose 1 heart. If the player does not have the piece of metal,
* they can't do anything here.
*
* @param String text1 the text being output
*/
public void cheshireCat(String text1){
System.out.println(text1);
if(invent.findItem("piece of metal") == true){
System.out.println(" a) give him the piece of metal");
System.out.println(" b) tell him you don't have it");
getAnswer();
answer = testForMultipleAnswers(answer, "give him the piece of metal",
"a", "give", "give metal");
answer = testForMultipleAnswers(answer, "tell him you don't have it",
"b", "don't have it", "tell him");
if(answer == "give him the piece of metal"){
System.out.println("The cat thanks you for finding his name tag.");
System.out.println("To show you his gratitude, he gives you two hearts!");
invent.heartMeter(2);
}else if(answer == "tell him you don't have it"){
System.out.println("The cat looks at you with a frown.");
System.out.println("It suddenly leaps at you and knocks you to the ground!");
System.out.println("The piece of metal with his name on it falls out of your bag.");
System.out.println("He takes the name tag and disappears back into the tree.");
System.out.println("You lose a heart from your injuries.");
invent.heartMeter(-1);
}else{
defaultOutput();
}
}else{
System.out.println(" a) tell him you don't have it");
getAnswer();
answer = testForMultipleAnswers(answer, "tell him you don't have it",
"a", "don't have it", "tell him");
if(answer == "tell him you don't have it"){
System.out.println("The cat looks disappointed and fades back into the darkness.");
System.out.println("You go back to the crossroads.");
}else{
defaultOutput();
}
}
System.out.println(" a) left");
System.out.println(" b) forward");
getAnswer();
answer = testForMultipleAnswers(answer, "left",
"a", "l", "go left");
answer = testForMultipleAnswers(answer, "forward",
"b", "f", "go forward");
}
/*
* Outputs text to introduce the castle scene and
* tests for answer on whether the player agrees to
* play the Queen's game or not.
*
* @param String text the text being output
*/
public void castleIntro(String text){
System.out.println(text);
getAnswer();
answer = testForMultipleAnswers(answer, "agree to play",
"a", "agree", "play");
answer = testForMultipleAnswers(answer, "refuse to play",
"b", "refuse", "don't play");
}
//number of points player has in the croquet game
int points = 0;
/*
* Outputs text and implements the game of croquet
* with the Queen. Player gains points by guessing
* which number the computer chose, either 1 or 2,
* gainingg a point if they guess correctly. If they guess
* incorrectly, the player loses half a heart. The
* game is over if the player gains 3 points or runs
* out of hearts.
*
* @param String text1 the first text being output
* @param String text2 the second text being output
*
* @return boolean returns true when game is won
*/
public boolean queenGame(String text1, String text2){
System.out.println(text1);
while(points < 3){
int gameNumber = (int)(Math.random() * 2 + 1);
System.out.println(text2);
int userNumber = input.nextInt();
if(userNumber == gameNumber){
points++;
System.out.println("You guessed correctly! You gain 1 point and "
+ "now have " + points + " points.");
}else{
System.out.println("How unfortunate! you have guessed wrong and now "
+ "lose half a heart.");
invent.heartMeter((float)(-0.5));
}
}
System.out.println("You won the game! :)");
return true;
}
/*