-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
142 lines (128 loc) · 4.4 KB
/
index.js
File metadata and controls
142 lines (128 loc) · 4.4 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
let level = 1;
let isOpen = false
setTimeout(()=>{
if(localStorage.getItem('join') == null) {
alert(
"Чтобы вызвать подсказку в игре нажмите кнопку H (англ.яз.)\n Кратко: \n Первый уровень - нужно на клавиши WSAD стрелочки или свайпы управлять персонажем, \n Второй уровень - клавишами WSAD или свайпами управлять персонажем, \n Третьий уровень - клавишами WSAD или свайпами управлять персонажем, \n Четвёртый уровень: клавишами WSAD или свайпами управлять персонажем на кнопку РАЗДОВИТЬ или клавишу SPACE (ПРОБЕЛ) вывезти машину!"
)
}
},1500)
function DownB() {
if(level > 1) {
level -= 1;
}
}
function UpB() {
if(level < 5) {
level += 1
}
}
document.querySelector('#back').addEventListener('click', DownB);
document.querySelector('#up').addEventListener('click', UpB);
document.querySelector('#play').addEventListener('click',()=>{
if(level == 1) {
document.location.href = "level_1.html"
}
if(level == 2) {
document.location.href = "level_2.html"
}
if(level == 3) {
document.location.href = "level_3.html"
}
if(level == 4) {
document.location.href = "level_4.html"
}
if(level == 5) {
if(isOpen) {
document.location.href = "end.html"
} else {
alert('Пройдите все уровни!')
}
}
})
setInterval(()=>{
if(level == 1) {
document.querySelector('#l').innerHTML = "Первый уровень";
document.querySelector('#levelPrew').src = "./img/prew_1.jpg"
}
if(level == 2) {
document.querySelector('#l').innerHTML = "Второй уровень";
document.querySelector('#levelPrew').src = "./img/prew_2.jpg"
}
if(level == 3) {
document.querySelector('#l').innerHTML = "Третий уровень";
document.querySelector('#levelPrew').src = "./img/prew_3.jpg"
}
if(level == 4) {
document.querySelector('#l').innerHTML = "Четвёртый уровень";
document.querySelector('#levelPrew').src = "./img/prew_4.jpg"
}
if(level == 5) {
document.querySelector('#l').innerHTML = "Конец";
if(!isOpen) {
document.querySelector('#levelPrew').src = "./img/Конец_закрыто.png"
}
}
},100)
setTimeout(()=>{
localStorage.setItem("join", true)
},2000)
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);
let xDown = null;
let yDown = null;
function getTouches(evt) {
return evt.touches ||
evt.originalEvent.touches;
}
function handleTouchStart(evt) {
const firstTouch = getTouches(evt)[0];
xDown = firstTouch.clientX;
yDown = firstTouch.clientY;
};
function handleTouchMove(evt) {
if ( ! xDown || ! yDown ) {
return;
}
let xUp = evt.touches[0].clientX;
let yUp = evt.touches[0].clientY;
let xDiff = xDown - xUp;
let yDiff = yDown - yUp;
if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {
if ( xDiff > 0 ) {
UpB()
} else {
DownB()
}
} else {
if ( yDiff > 0 ) {
//
} else {
//
}
}
xDown = null;
yDown = null;
};
setInterval(()=>{
if(
localStorage.getItem('isVerif_1') == 'true' &&
localStorage.getItem('isVerif_2') == 'true' &&
localStorage.getItem('isVerif_3') == 'true' &&
localStorage.getItem('isVerif_4') == 'true'
) {
isOpen = true;
if(level == 5 && isOpen) {
document.querySelector('#levelPrew').src = "./img/Конец_открыто.png"
}
}
},1)
function onKey(event) {
if(event.keyCode === 37) {
DownB();
}
if(event.keyCode === 39) {
UpB();
}
}
document.addEventListener('keydown', onKey)