-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainer.js
75 lines (70 loc) · 2.21 KB
/
mainer.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
"use strict";
var start = document.getElementById("start");
var pause = document.getElementById("pause");
var newGame = document.getElementById("newGame");
var timerCount = document.getElementsByClassName("bot_head_time_block_count_text")[0];
let mainBlock = document.getElementsByClassName("game_blocks")[0]; // наш блок *
var points = document.getElementsByClassName("bot_head_points_block_count_text")[0];
var pickBlock = document.getElementsByClassName("game_blocks")[0];
// Global :(
var objectPanel={
timeCount: 60,
points: 0,
pauseGame: false
}
var objBlock={
clicked: false,
color: ""
}
//
var date = new Date(new Date().getTime() + 60 * 1000);
document.cookie = "name="+points+"; path=/; expires=" + date.toUTCString();
alert(document.cookie);
// button's
newGame.onclick = function(){ // or newGame
status("start");
};
pause.onclick = function(){
objectPanel.pauseGame = true;
};
start.onclick = function(){
objectPanel.pauseGame = false;
if(objectPanel.timeCount > 0)
{
status("start");
}
}
pickBlock.onclick = function(){
objBlock.clicked = true;
}
// function's
function status(status){
if(status == "start"){
var myInterval = setInterval(function(){
// перемещение
mainBlock.style.marginLeft = Math.floor(Math.random()*900) + "px";
mainBlock.style.marginTop = Math.floor(Math.random()*360) + "px";
timerCount.textContent = objectPanel.timeCount; // время
if(objBlock.clicked == true){ // добавляем 1 балл
points.textContent = objectPanel.points++;
}
objBlock.color = "rgb("+Math.floor(Math.random()*256)+","
+Math.floor(Math.random()*256)+","
+Math.floor(Math.random()*256)+")";
mainBlock.style.backgroundColor = objBlock.color; // пересылаем свойство объекта в html
objBlock.clicked = false; // обнуляем для блока статус нажатого
// чтобы за 1 сек не было 2 клика.
objectPanel.timeCount--;
if(objectPanel.pauseGame == true){
clearInterval(myInterval);
}
else if(objectPanel.timeCount < 0)
{
clearInterval(myInterval);
}
},1000);
}
else{
return 0;
}
}