-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmolebuster.js
More file actions
122 lines (107 loc) · 3.46 KB
/
molebuster.js
File metadata and controls
122 lines (107 loc) · 3.46 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
let POSICIONANTERIOR = 0;
const Start = () =>{
let temporizador = 1;
buttonStop(true);
OcultaTodos();
EventoClic();
time$$ = document.querySelector(".tiempo");
time$$.style.color = "black";
time$$.innerText="00:30";
points$$ = document.querySelector(".points");
points$$.innerText = 0;
points$$.style.color = "red";
for(let i=29; i>=0; i--){
setTimeout( () =>{
ActualizaContador(i);
if(i===0) Stop();
}
,1000*temporizador)
setTimeout( () =>{
OcultaActivo();
MuestraAleatorio();
},1000*temporizador)
temporizador++
}
}
const buttonStop = (active) =>{
if (active){
const buttonStop$$ = document.createElement('button');
buttonStop$$.innerHTML= "Stop";
buttonStop$$.classList="stop";
buttonStop$$.onclick = () => Stop();
const insertButton$$ = document.querySelector(".buttons");
insertButton$$.appendChild(buttonStop$$);
const startButton$$ = document.querySelector("#start");
startButton$$.onclick=""
}else{
const buttonStop$$ = document.querySelector('.stop');
const insertButton$$ = document.querySelector(".buttons");
if (buttonStop$$) insertButton$$.removeChild(buttonStop$$);
const startButton$$ = document.querySelector("#start");
startButton$$.onclick= () => Start();
}
}
const Stop = () =>{
let id = window.setTimeout(function() {}, 0);
while (id--) {
window.clearTimeout(id);
}
MostrarTodos();
buttonStop(false);
}
const ActualizaContador = (segundo) => {
time$$ = document.querySelector(".tiempo");
if (segundo<10){
segundo = '0'+segundo
time$$.style.color = "red";
}
time$$.innerText= `00:${segundo}`
}
const OcultaActivo = () =>{
let images = document.querySelectorAll('.active');
Array.from(images).forEach((element)=>{
element.classList.remove("active")
element.style.visibility= "hidden";
})
}
const OcultaTodos = () =>{
let images = document.querySelectorAll('.game img');
Array.from(images).forEach((element)=>{
element.classList.remove("active")
element.style.visibility= "hidden";
element.ondragstart = () => {
return false;
};
})
}
const EventoClic = () =>{
let images = document.querySelectorAll('.game img');
Array.from(images).forEach((element)=>{
element.addEventListener("click",() =>{
if(element.classList.contains("active")){
points$$ = document.querySelector(".points");
let puntos = parseInt(points$$.innerText) +5
points$$.innerText = puntos
console.log(puntos);
if (puntos>100) points$$.style.color = "green";
OcultaTodos();
}
})
})
}
const MostrarTodos = () =>{
let images = document.querySelectorAll('.game img');
Array.from(images).forEach((element)=>{
element.classList.remove("active")
element.style.visibility= "visible";
})
}
const MuestraAleatorio = () =>{
let random = Math.floor(Math.random() * 9)+1;
if (random ===POSICIONANTERIOR && random<9) random++
else if (random ===POSICIONANTERIOR && random===9) random--
let image = document.querySelector(`#img${random}`);
image.classList.add("active");
image.style.visibility= "visible";
POSICIONANTERIOR = random;
}