-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
425 lines (370 loc) · 11.7 KB
/
main.js
File metadata and controls
425 lines (370 loc) · 11.7 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
"use strict";
class Game {
constructor(gameName, levelNames) {
this.gameName = gameName;
this.levels = levelNames.map(x => new Level(x));
}
}
class Level {
constructor(levelName) {
this.levelName = levelName;
this.relaxedLevelName = relaxLevelName(levelName);
}
}
// Globals
const games = [
new Game("Tomb Raider", [
"Caves",
"City of Vilcabamba",
"The Lost Valley",
"Tomb of Qualopec",
"St. Francis' Folly",
"Colosseum",
"Palace Midas",
"The Cistern",
"Tomb of Tihocan",
"City of Khamoon",
"Obelisk of Khamoon",
"Sanctuary of the Scion",
"Natla's Mines",
"Atlantis",
"The Great Pyramid",
"Lara's Home"
]),
new Game("Tomb Raider II", [
"The Great Wall",
"Venice",
"Bartoli's Hideout",
"Opera House",
"Offshore Rig",
"Diving Area",
"40 Fathoms",
"Wreck of the Maria Doria",
"Living Quarters",
"The Deck",
"Tibetan Foothills",
"Barkhang Monastery",
"Catacombs of the Talion",
"Ice Palace",
"Temple of Xian",
"Floating Islands",
"Dragon's Lair",
"Home Sweet Home",
"Lara's Home"
]),
new Game("Tomb Raider III: Adventures of Lara Croft", [
"Jungle",
"Temple Ruins",
"The River Ganges",
"Caves of Kaliya",
"Nevada Desert",
"High Security Compound",
"Area 51",
"Coastal Village",
"Crash Site",
"Madubu Gorge",
"Temple of Puna",
"Thames Wharf",
"Aldwych",
"Lud's Gate",
"City",
"Antarctica",
"RX-Tech Mines",
"Lost City of Tinnos",
"Meteorite Cavern",
"All Hallows",
"Lara's Home"
]),
new Game("Tomb Raider: Unfinished Business", [
"Return to Egypt",
"Temple of the Cat",
"Atlantean Stronghold",
"The Hive"
]),
new Game("Tomb Raider II: Golden Mask", [
"The Cold War",
"Fool's Gold",
"Furnace of the Gods",
"Kingdom",
"Nightmare in Vegas"
]),
new Game("Tomb Raider: The Lost Artifact", [
"Highland Fling",
"Willard's Lair",
"Shakespeare Cliff",
"Sleeping with the Fishes",
"It's a Madhouse!",
"Reunion"
]),
new Game("Tomb Raider: The Last Revelation", [
"Angkor Wat",
"Race for the Iris",
"The Tomb of Seth",
"Burial Chambers",
"Valley of the Kings",
"KV5",
"Temple of Karnak",
"Great Hypostyle Hall",
"Sacred Lake",
"Tomb of Semerkhet",
"Guardian of Semerkhet",
"Desert Railroad",
"Alexandria",
"Coastal Ruins",
"Catacombs",
"Temple of Poseidon",
"The Lost Library",
"Hall of Demetrius",
"Pharos, Temple of Isis",
"Cleopatra's Palaces",
"City of the Dead",
"Chambers of Tulun",
"Citadel Gate",
"Trenches",
"Street Bazaar",
"Citadel",
"Sphinx Complex",
"Underneath the Sphinx",
"Menkaure's Pyramid",
"Inside Menkaure's Pyramid",
"The Mastabas",
"The Great Pyramid",
"Khufu's Queen's Pyramid",
"Inside the Great Pyramid",
"Temple of Horus"
]),
new Game("Tomb Raider Chronicles", [
"Streets of Rome",
"Trajan's Markets",
"The Colosseum",
"The Base",
"The Submarine",
"Deepsea Dive",
"Sinking Submarine",
"Gallows Tree",
"Labyrinth",
"Old Mill",
"The 13th Floor",
"Escape with the Iris",
"Red Alert!"
]),
new Game("Tomb Raider: The Angel of Darkness", [
"Parisian Back Streets",
"Derelict Apartment Block",
"Industrial Roof Tops",
"Margot Carvier's Apartment",
"Louvre Storm Drains",
"Louvre Galleries",
"The Archaeological Dig",
"Tomb Of Ancients",
"Neptune's Hall",
"Wrath Of The Beast",
"The Sanctuary Of Flame",
"The Breath Of Hades",
"The Hall Of Seasons",
"Galleries Under Siege",
"Von Croy's Apartment",
"The Monstrum Crimescene",
"The Strahov Fortress",
"Bio-research Facility",
"The Sanitarium",
"Maximum Containment Area",
"Aquatic Research Area",
"The Vault of Trophies",
"Boaz Returns",
"The Lost Domain",
"Eckhardt's Lab"
]),
new Game("Tomb Raider: Legend", [
"Bolivia",
"Peru",
"Japan",
"Ghana",
"Kazakhstan",
"England",
"Nepal",
"Bolivia Redux"
]),
new Game("Tomb Raider: Anniversary", [
"Mountain Caves",
"City of Vilcabamba",
"The Lost Valley",
"Tomb of Qualopec",
"St. Francis' Folly",
"The Coliseum",
"Midas Palace",
"Tomb of Tihocan",
"Temple of Khamoon",
"Obelisk of Khamoon",
"Sanctuary of the Scion",
"Natla's Mines",
"The Great Pyramid",
"Final Conflict",
"Croft Manor"
]),
new Game("Tomb Raider: Underworld", [
"No Illusions",
"The Path to Avalon",
"Niflheim",
"The Norse Connection",
"God of Thunder",
"Realm of the Dead",
"Remnants",
"Bhogavati",
"The Ancient World",
"Puppet No Longer",
"Protected by the Dead",
"The Unnamed Days",
"Xibalba",
"The Midgard Serpent",
"Land of the Dead",
"Gate of the Dead",
"Valhalla",
"Rituals Old",
"Helheim",
"Yggdrasil",
"Out of Time"
])
];
const levels = games.map(x => x.levels).reduce((a, b) => a.concat(b), []);
const levelNames = levels.map(x => x.levelName);
const relaxedLevelNames = levels.map(x => x.relaxedLevelName);
const namedLevels = new Set();
let counter = 0;
initializePage();
function initializePage() {
const gameList = document.getElementById("gameList");
for (const game of games) {
const gameDiv = document.createElement("div");
gameDiv.className = "col text-center";
const gameTitle = document.createElement("h3");
gameTitle.innerHTML = game.gameName;
gameDiv.appendChild(gameTitle);
const levelList = document.createElement("ul");
levelList.className = "list-unstyled";
gameDiv.appendChild(levelList);
for (const level of game.levels) {
const levelListItem = document.createElement("li");
levelListItem.className = "levelName";
levelListItem.innerHTML = "???";
levelListItem.setAttribute("data-level-name", level.relaxedLevelName);
levelList.appendChild(levelListItem);
}
gameList.appendChild(gameDiv);
}
const startModal = bootstrap.Modal.getOrCreateInstance(document.getElementById("startModal"));
startModal.show();
updateCounterText();
}
function startGame() {
const startModal = bootstrap.Modal.getOrCreateInstance(document.getElementById("startModal"));
startModal.hide();
const levelNameInput = document.getElementById("levelNameInput");
levelNameInput.value = "";
levelNameInput.focus();
const minutes = 10; // change this to affect how much time the game lasts
const timeStarted = new Date().getTime();
const targetTime = new Date(timeStarted + (minutes * 60 * 1000 + 1000)).getTime(); // 10 minutes later
const interval = setInterval(() => {
const now = new Date().getTime();
const timeRemaining = targetTime - now;
const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
if (timeRemaining < 1000) {
document.getElementById("timer").innerHTML = "0:00";
clearInterval(interval);
endGame();
} else {
document.getElementById("timer").innerHTML = minutes + ":" + String(seconds).padStart(2, '0');
}
}, 1000);
}
function endGame() {
const endMessage = document.getElementById("endMessage");
if (counter === 0) {
endMessage.innerHTML = "Wow. You couldn't name even one?";
} else if (counter <= 10) {
endMessage.innerHTML = `You either have to play more TR games or type faster. You named ${counter} out of ${levelNames.length} levels.`;
} else if (counter <= 80) {
endMessage.innerHTML = `Not bad. You managed to name ${counter} out of ${levelNames.length} levels!`;
} else {
endMessage.innerHTML = `Congratulations! You managed to name ${counter} out of ${levelNames.length} levels!`;
}
const endModal = bootstrap.Modal.getOrCreateInstance(document.getElementById("endModal"));
endModal.show();
for (let i = 0; i < relaxedLevelNames.length; i++) {
const relaxedLevelName = relaxedLevelNames[i];
const levelListItems = document.querySelectorAll(`[data-level-name="${relaxedLevelName}"]`);
for (const levelListItem of levelListItems) {
if (levelListItem.innerHTML === "???") {
levelListItem.classList.add("text-danger");
levelListItem.innerHTML = levelNames[i];
} else {
levelListItem.classList.add("text-success");
}
}
}
}
function restartGame() {
const restartDiv = document.getElementById("restartDiv");
restartDiv.className = "d-none";
const inputDiv = document.getElementById("inputDiv");
inputDiv.className = "";
counter = 0;
resetLevelNames();
document.getElementById("timer").innerHTML = "10:00";
updateCounterText();
const endModal = bootstrap.Modal.getOrCreateInstance(document.getElementById("endModal"));
endModal.hide();
setWarning("");
startGame();
}
function checkLevelName(key = "Enter") {
if (key !== "Enter") {
return;
}
const levelNameInput = document.getElementById("levelNameInput");
const relaxedLevelName = relaxLevelName(levelNameInput.value.trim());
if (namedLevels.has(relaxedLevelName)) {
setWarning("Level already on the list.");
return;
}
const levelNameIndex = relaxedLevelNames.indexOf(relaxedLevelName);
if (levelNameIndex !== -1) {
const levelListItems = document.querySelectorAll(`[data-level-name="${relaxedLevelName}"]`);
for (const levelListItem of levelListItems) {
levelListItem.innerHTML = levelNames[levelNameIndex];
}
namedLevels.add(relaxedLevelName);
counter += levelListItems.length;
updateCounterText();
levelNameInput.focus();
levelNameInput.value = "";
setWarning("");
} else {
setWarning("Level doesn't exist.");
}
}
function updateCounterText() {
document.getElementById("counter").innerHTML = counter + "/" + levelNames.length;
}
function relaxLevelName(levelName) {
return levelName.replace(/[^a-zA-Z0-9 ]/g, "").toLowerCase();
}
function setWarning(message) {
document.getElementById("warning-text").innerHTML = message;
}
function resetLevelNames() {
namedLevels.clear();
const levelListItems = document.getElementsByClassName("levelName");
for (const levelNameItem of levelListItems) {
levelNameItem.innerHTML = "???";
levelNameItem.className = "levelName";
}
}
function checkNames() {
const restartDiv = document.getElementById("restartDiv");
restartDiv.className = "";
const inputDiv = document.getElementById("inputDiv");
inputDiv.className = "d-none";
}