-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (72 loc) · 2.06 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
let score = 0
let time = 20
let mouse = document.getElementById('mouse')
let timer = document.getElementById('timer')
let scoreBoard = document.getElementById('score_container')
let resultPage = document.getElementById('resultPage')
let soundeffect = document.getElementById('soundEffect')
function fadeOutStart(str){
document.getElementById(str).parentElement.style.opacity = '0'
}
function gameFunction(){
if (mouse.style.opacity == 0 && time > 0) {
mouse.style.opacity = 1
mouse.style.zIndex = 1
let leftPosition = Math.floor(Math.random()*(50)) + 2
let topPosition = Math.floor(Math.random()*(40)) + 40
mouse.style.left = `${leftPosition}%`
mouse.style.top = `${topPosition}%`
} else {
mouse.style.opacity= '0'
mouse.style.zIndex= '0'
}
}
function start(){
if(time > 0){
setInterval(startTimer,1500)
setInterval(gameFunction,1000)
timer.style.opacity= '1'
timer.style.zIndex= '1'
scoreBoard.style.opacity= '1'
scoreBoard.style.zIndex= '1'
}
}
function startTimer(){
time--
timer.innerHTML = `${time}`
if(time === 0){
stop()
}
}
function stop(){
timer.style.opacity= '0'
timer.style.zIndex= '0'
scoreBoard.style.opacity= '0'
scoreBoard.style.zIndex= '0'
mouse.style.opacity= '0'
mouse.style.zIndex= '0'
resultPage.style.opacity='1'
result()
}
function result(){
if(score <= 20){
document.getElementById('statusMisi').innerHTML = `MISSION INCOMPLATED`
document.getElementById('paragraph').innerHTML = `you have failed to save the kingdom,
the residents are waiting for you to fight back.
let's rejoin the royal army to save the kingdom and celebrate our victory`
document.getElementById('status').innerHTML = `YOU ARE NOOB`
document.getElementById('back').style.top = '90%';
}
}
mouse.addEventListener("click", counterScore)
function counterScore(){
if(time >= 1){
score++
mouse.style.opacity = 0
document.getElementById('score').innerHTML = `${score}`
}
}
mouse.addEventListener("click", playAudio)
function playAudio() {
soundeffect.play();
}