-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_hamster.js
50 lines (44 loc) · 1.34 KB
/
script_hamster.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
var proceed = true;
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function initTime()
{
var time = document.getElementById('time');
var t_interval = setInterval(() => {
time.textContent = parseInt(time.textContent) - 1;
if (time.textContent == '0')
{
clearInterval(t_interval);
time.textContent = 'Fini!';
proceed = false;
}
}, 1000);
}
function score(bonus)
{
var el = document.getElementById("counter");
el.textContent = parseInt(el.textContent) + 1 + bonus;
}
var sources = ['images/taupe_sb.png', 'images/taupe.png'];
function taupeHehe(init) {
if (proceed) {
var type = rand(0,1);
var img = document.createElement("img");
img.src = sources[type];
img.width = 50;
img.height = 50;
img.alt = type;
// set the position
img.style.position = 'absolute';
img.style.top = document.body.clientHeight * Math.random() + 'px';
img.style.left = document.body.clientWidth * Math.random() + 'px';
img.addEventListener('click', () => {
img.remove();
taupeHehe(1);
score(type);
if (init == 0) initTime();
});
document.body.appendChild(img);
}
}