-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (79 loc) · 2.5 KB
/
app.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
// svg levels
const levelOne = document.querySelector(".level-one");
const levelTwo = document.querySelector(".level-two");
// next button
const nextRetryButton = document.querySelector(".next-retry-button")
// UI Objects
const uiLevel = document.querySelector(".ui-level");
const uiMessage = document.querySelector(".ui-message");
// Colors
const LIGHT_BLUE = "#1872AE";
const RED = "#FF0000";
// Variables
let hasLevelCompleted = false;
let currentLevel = 1;
const CollisionCheck = (value) => {
console.log(value);
if(value === "maze-border") Retry();
if(value === "finish"){
hasLevelCompleted = true;
nextRetryButton.style.background = LIGHT_BLUE;
nextRetryButton.style.opacity = 1;
nextRetryButton.style.pointerEvents = "all";
nextRetryButton.textContent = 'Next Level';
switch(currentLevel) {
case 1:
levelOne.style.pointerEvents = "none";
break;
case 2:
levelTwo.style.pointerEvents = "none";
break;
}
}
}
const Retry = () => {
nextRetryButton.style.opacity = 1;
nextRetryButton.style.background = RED;
nextRetryButton.style.pointerEvents = 'all';
nextRetryButton.textContent = 'Retry!';
switch(currentLevel) {
case 1:
levelOne.style.pointerEvents = "none";
break;
case 2:
levelTwo.style.pointerEvents = "none";
}
}
window.addEventListener("mousemove", (e) => {
if(hasLevelCompleted) return;
let check = e.target.classList.value;
CollisionCheck(check);
})
nextRetryButton.addEventListener("click", () => {
nextRetryButton.style.opacity = 0;
nextRetryButton.style.pointerEvents = "none";
if(hasLevelCompleted) {
switch(currentLevel) {
case 1:
levelOne.style.display = "none";
levelTwo.style.display = "block";
uiLevel.textContent = "Level 02";
uiMessage.textContent = "Good..Continue to finish the levels";
currentLevel += 1;
break;
case 2:
window.location.href = "https://www.youtube.com/watch?v=xvFZjo5PgG0"
break;
}
hasLevelCompleted = false;
} else {
switch(currentLevel) {
case 1:
levelOne.style.pointerEvents = "all";
break;
case 2:
levelTwo.style.pointerEvents = "all";
break;
}
}
})