-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreasureIsland.java
More file actions
142 lines (125 loc) · 7.34 KB
/
Copy pathTreasureIsland.java
File metadata and controls
142 lines (125 loc) · 7.34 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
import java.util.Scanner;
public class TreasureIsland {
public static void main(String[] args) {
startGame();
}
public static void startGame() {
System.out.println("*******************************************************************************\r\n" + //
" | | | |\r\n" + //
" _________|________________.=\"\"_;=.______________|_____________________|_______\r\n" + //
" | | ,-\"_,=\"\" `\"=. |\r\n" + //
" |___________________|__\"=.o`\"-._ `\"=.______________|___________________\r\n" + //
" | `\"=.o`\"=. _`\"=. |\r\n" + //
" _________|_____________________:=._o \"=.\"_.-=\"'\"=.__________________|_______\r\n" + //
" | | __.--\" , ; `\"=.o.\" ,-\"\"\"-._ \". |\r\n" + //
" |___________________|_._\" ,. .` ` `` , `\"-._\"-._ \". '__|___________________\r\n" + //
" | |o`\"=.o`\"` , \"` `; .\" , \"-._\"-._; ; |\r\n" + //
" _________|___________| ;`-.o`\"=.o; .\" ` '`.\"` . \"-._ /_______________|_______\r\n" + //
" | | |o; `\"-.o`\"=.o`` '` \" ,__.--o; |\r\n" + //
" |___________________|_| ; (#) `-.o `\"=.o_.--\"_o.-; ;___|___________________\r\n" + //
" ____/______/______/___|o;._ \" `\".o|o_.--\" ;o;____/______/______/____\r\n" + //
" /______/______/______/'\"=._o--._ ; | ; ; ;/______/______/______/_\r\n" + //
" ____/______/______/______/__\"=._o--._ ;o|o; _._;o;____/______/______/____\r\n" + //
" /______/______/______/______/____\"=._o._; | ;_.--\"o.--\"_/______/______/______/_\r\n" + //
" ____/______/______/______/______/____\"=.o|o_.--\"\"___/______/______/______/____\r\n" + //
" /______/______/______/______/______/______/______/______/______/______/_____ /\r\n" + //
" *******************************************************************************\r\n" + //
" ");
System.out.println("Welcome to Treasure Island.");
System.out.println("Your mission is to find the treasure.");
crossRoad();
}
public static void crossRoad() {
Scanner scanner = new Scanner(System.in);
System.out.println("You're at a cross road. Where do you want to go? Type \"left\" or \"right\":");
String choice1 = scanner.nextLine().toLowerCase();
if (choice1.equals("left")) {
forest();
} else if (choice1.equals("right")) {
System.out.println("You fell into a hole. Game Over.");
} else {
System.out.println("Invalid choice. Game Over.");
}
}
public static void forest() {
Scanner scanner = new Scanner(System.in);
System.out.println("You enter a dense forest. The path splits into two: one leads deeper into the forest, the other towards a clearing.");
System.out.println("Do you want to go \"deeper\" or to the \"clearing\"?");
String choice2 = scanner.nextLine().toLowerCase();
if (choice2.equals("deeper")) {
encounterAnimal();
} else if (choice2.equals("clearing")) {
lake();
} else {
System.out.println("Invalid choice. Game Over.");
}
}
public static void encounterAnimal() {
Scanner scanner = new Scanner(System.in);
System.out.println("You encounter a wild animal! It seems aggressive.");
System.out.println("Do you \"run\" away or \"stay\" and try to calm it down?");
String choice3 = scanner.nextLine().toLowerCase();
if (choice3.equals("run")) {
System.out.println("You safely escape and find yourself near a lake.");
lake();
} else if (choice3.equals("stay")) {
quizTime();
} else {
System.out.println("Invalid choice. Game Over.");
}
}
public static void quizTime() {
Scanner scanner = new Scanner(System.in);
System.out.println("The animal speaks! It offers you a riddle to let you pass.");
System.out.println("Riddle: I speak without a mouth and hear without ears. I have no body, but I come alive with the wind. What am I?");
System.out.println("Your answer:");
String answer = scanner.nextLine().toLowerCase();
if (answer.equals("echo")) {
System.out.println("Correct! The animal lets you pass.");
lake();
} else {
System.out.println("Wrong answer. The animal chases you away. Game Over.");
}
}
public static void lake() {
Scanner scanner = new Scanner(System.in);
System.out.println("You've come to a lake. There is an island in the middle of the lake. Type \"wait\" to wait for a boat. Type \"swim\" to swim across.");
String choice4 = scanner.nextLine().toLowerCase();
if (choice4.equals("wait")) {
island();
} else if (choice4.equals("swim")) {
System.out.println("You get attacked by an angry trout. Game Over.");
} else {
System.out.println("Invalid choice. Game Over.");
}
}
public static void island() {
Scanner scanner = new Scanner(System.in);
System.out.println("You arrive at the island unharmed. There is a house with 3 doors: one red, one yellow, and one blue. Which colour do you choose?");
String choice5 = scanner.nextLine().toLowerCase();
if (choice5.equals("red")) {
System.out.println("It's a room full of fire. Game Over.");
} else if (choice5.equals("yellow")) {
treasureRoom();
} else if (choice5.equals("blue")) {
System.out.println("You enter a room of beasts. Game Over.");
} else {
System.out.println("You chose a door that doesn't exist. Game Over.");
}
}
public static void treasureRoom() {
Scanner scanner = new Scanner(System.in);
System.out.println("Congratulations! You found the treasure room. But wait, there are 3 chests here: one gold, one silver, and one bronze.");
System.out.println("Which chest do you open? Type \"gold\", \"silver\", or \"bronze\":");
String chestChoice = scanner.nextLine().toLowerCase();
if (chestChoice.equals("gold")) {
System.out.println("The chest is full of gold coins! You are rich! You Win!");
} else if (chestChoice.equals("silver")) {
System.out.println("The chest contains silver, but it also releases a sleeping gas. Game Over.");
} else if (chestChoice.equals("bronze")) {
System.out.println("The chest contains a map to another treasure. The adventure continues... You Win!");
} else {
System.out.println("You chose a chest that doesn't exist. Game Over.");
}
}
}