-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript1.js
109 lines (85 loc) · 2.43 KB
/
script1.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
async function ded() {
const playground = document.querySelector('#playground');
const playground_width = Math.floor($('#playground').width());
const playground_height = Math.floor($('#playground').height());
const btn_start = document.querySelector('#btn_start');
const DB = document.querySelector('#DB');
const block = document.querySelector('#block')
const block2 = document.querySelector('#block2')
const block_width = $('#block').width();
const block_height = $('#block').height();
const block_width2 = $('#block2').width();
const block_height2 = $('#block2').height();
let razy = 0;
let game = {
started: false,
points: 0,
clicked:false,
}
function pt(){
let block_pos_x = Math.floor((Math.random()*playground_width))-block_width;
let block_pos_y = Math.floor((Math.random()*playground_height))-block_height;
btn_start.style.display = 'none';
game.started = true;
if(game.started == true)
{
block.style.display = 'block';
block.style.left = block_pos_x + 'px';
block.style.top = block_pos_y + 'px';
console.log(block_pos_x + 'x' + ' ' + block_pos_y + 'y');
}
}
function pt2(){
let block_pos_x = Math.floor((Math.random()*playground_width))-block_width2;
let block_pos_y = Math.floor((Math.random()*playground_height))-block_height2;
btn_start.style.display = 'none';
game.started = true;
if(game.started == true)
{
block2.style.display = 'block';
block2.style.left = block_pos_x + 'px';
block2.style.top = block_pos_y + 'px';
console.log(block_pos_x + 'x' + ' ' + block_pos_y + 'y');
}
}
btn_start.addEventListener('click', ()=>{
game.points=0;
razy=0;
DB.innerHTML = game.points;
pt()
})
block.addEventListener('click',()=>{
game.points++;
game.clicked=true;
DB.innerHTML = game.points;
pt();
console.log(game)
if(game.points>=30){
if(razy == 0){
razy++;
pt2();
}
}
})
block2.addEventListener('click',()=>{
game.clicked=true;
game.points++
DB.innerHTML = game.points;
if(game.points>=30){
pt2();
}
else block2.style.dysplay='none';
})
playground.addEventListener('click', ()=>{
if(game.started == true){
if(game.clicked==false){
game.started=false;
block.style.display='none'
block2.style.display='none'
btn_start.style.display='block';
}
else game.clicked=false;
}
})
}
ded();