-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (33 loc) · 920 Bytes
/
script.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
var gameState = "ready";
function startGame() {
if(gameState === "ready") {
var start = document.querySelector("#start");
start.classList.toggle("start-running");
gameState = "running";
document.getElementById("message").innerHTML = "Go!";
}
}
function finishGame() {
if(gameState === "running")
gameState = "finished";
}
function loseGame(element) {
if(gameState === "running") {
element.classList.add("hit");
gameState = "lost";
document.getElementById("message").innerHTML = "Game over!";
}
}
function winGame() {
if(gameState === "running") {
var start = document.querySelector("#finish");
start.classList.toggle("finish-victory");
gameState = "victory";
document.getElementById("message").innerHTML = "Hurrrayyy!! You won!";
}
}
function cursorOutside(e, maze) {
console.log(e);
if(e.target === maze && e.relatedTarget === document.documentElement)
loseGame(document.body);
}