-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
201 lines (178 loc) · 7.68 KB
/
index.js
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
//Current line
var CurrentId = undefined;
var inputValues = [];
const inputPrompts = [
`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.`,
`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?`,
];
let isFirstClick = true;
//Click Run
$(document).ready(function () {
$("#run-button").click(function () {
inputValues = [];
$("#Content").empty();
NewLine(
`
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" '"=.| |
|___________________|__"=._o'"-._ '"=.______________|___________________
| '"=._o'"=._ _'"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; '"=._o." ,-"""-._ ". |
|___________________|_._" ,. .' ' '' , '"-._"-._ ". '__|___________________
| |o'"=._' , "' '; .". , "-._"-._; ; |
_________|___________| ;'-.o'"=._; ." ' ''."\' . "-._ /_______________|_______
| | |o; '"-.o'"=._'' '' " ,__.--o; |
|___________________|_| ; (#) '-.o '"=.'_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " '".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
Welcome to Treasure Island.
Your mission is to find the treasure.
`,
false
);
NewLine(
`You\'re at a cross road. Where do you want to go?
Type "left" or "right"`,
true
);
});
});
//Enter button
$(document).on("keydown", function (e) {
var x = event.which || event.keyCode;
if (x === 13 || x == 13) {
var consoleLine = $("#" + CurrentId + " input").val();
console.log(consoleLine);
inputValues.push({ id: CurrentId, val: consoleLine });
console.log(inputValues[0].val);
if (inputValues[0].val.toLowerCase() == "left" && inputValues.length == 1) {
NewLine(inputPrompts[0], true);
return;
}
if (
inputValues[0].val.toLowerCase() == "right" &&
inputValues.length == 1
) {
NewLine("You fell into a hole. Game Over.", false);
return;
}
if (inputValues[1].val.toLowerCase() == "wait" && inputValues.length == 2) {
NewLine(inputPrompts[1], true);
return;
}
if (inputValues[1].val.toLowerCase() == "swim" && inputValues.length == 2) {
NewLine("You get attacked by an angry trout. Game Over.", false);
return;
}
if (inputValues[2].val.toLowerCase() == "red" && inputValues.length == 3) {
NewLine("It's a room full of fire. Game Over.", false);
return;
}
if (
inputValues[2].val.toLowerCase() == "yellow" &&
inputValues.length == 3
) {
NewLine("You found the treasure! You Win!", false);
return;
}
if (inputValues[2].val.toLowerCase() == "blue" && inputValues.length == 3) {
NewLine("You enter a room of beasts. Game Over.", false);
return;
}
// NewLine(inputPrompts[inputValues.length - 1], true);
// setTimeout(NewLine, delay);
}
});
$(document).on("keydown", function (e) {
var x = event.which || event.keyCode;
var line = $("#" + CurrentId + " input");
var length = line.val().length;
if (x != 8) {
line.attr("size", 1 + length);
} else {
line.attr("size", length * 0.95);
}
if (length === 0) {
$("#" + CurrentId + " input").attr("size", "1");
}
});
$(document).on("click", function (e) {
$("#" + CurrentId + " input").focus();
});
//New line
function NewLine(text, isPrompt) {
$(".console-carrot").remove();
if (CurrentId !== undefined) {
$("#" + CurrentId + " input").prop("disabled", true);
}
CurrentId = "consoleInput-" + GenerateId();
if (isPrompt) {
$("#Content").append("<div>" + text + "</div>");
$("#Content").append(
'<div id="' +
CurrentId +
'">' +
'<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" type="text" class="terminal-input" /><div class="console-carrot"></div></div>'
);
$("#" + CurrentId + " input").focus();
$("#" + CurrentId + " input").attr("size", "1");
} else {
$("#Content").append('<div id="' + CurrentId + '">' + text + "</div>");
}
document.getElementById(CurrentId).scrollIntoView();
}
function GenerateId() {
return Math.random().toString(16).slice(2);
}
// 'print('''
// *******************************************************************************
// | | | |
// _________|________________.=""_;=.______________|_____________________|_______
// | | ,-"_,="" '"=.| |
// |___________________|__"=._o'"-._ '"=.______________|___________________
// | '"=._o'"=._ _'"=._ |
// _________|_____________________:=._o "=._."_.-="'"=.__________________|_______
// | | __.--" , ; '"=._o." ,-"""-._ ". |
// |___________________|_._" ,. .' ' '' , '"-._"-._ ". '__|___________________
// | |o'"=._' , "' '; .". , "-._"-._; ; |
// _________|___________| ;'-.o'"=._; ." ' ''."\' . "-._ /_______________|_______
// | | |o; '"-.o'"=._'' '' " ,__.--o; |
// |___________________|_| ; (#) '-.o '"=.'_.--"_o.-; ;___|___________________
// ____/______/______/___|o;._ " '".o|o_.--" ;o;____/______/______/____
// /______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
// ____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
// /______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
// ____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
// /______/______/______/______/______/______/______/______/______/______/_____ /
// *******************************************************************************
// ''')
// print("Welcome to Treasure Island.")
// print("Your mission is to find the treasure.")
// #Write your code below this line 👇
// choice1 = input('You\'re at a cross road. Where do you want to go? Type "left" or "right" \n').toLowerCase()()
// if choice1 == "left":
// choice2 = input('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. \n').toLowerCase()()
// if choice2 == "wait":
// choice3 = input("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? \n").toLowerCase()()
// if choice3 == "red":
// print("It's a room full of fire. Game Over.")
// elif choice3 == "yellow":
// print("You found the treasure! You Win!")
// elif choice3 == "blue":
// print("You enter a room of beasts. Game Over.")
// else:
// print("You chose a door that doesn't exist. Game Over.")
// else:
// print("You get attacked by an angry trout. Game Over.")
// else:
// print("You fell into a hole. Game Over.")';