-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
88 lines (69 loc) · 2.58 KB
/
script.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
(() => {
const btnStart = document.querySelector("button");
const btn3D = document.querySelector(".btn-3D");
const genius = document.querySelector(".genius");
const areas = Array.from(document.querySelectorAll(".blue, .red, .yellow, .green"));
const info = document.querySelector(".info");
const myScore = document.querySelector(".score");
const randomAreas = new Set();
let numberRandom = null;
let score = 0;
function showMessage(message, inf = "") {
myScore.textContent = message;
info.textContent = inf;
score = 0;
}
function gameOver() {
randomAreas.clear();
btnStart.disabled = false;
btnStart.textContent = "Iniciar";
showMessage("Você perdeu!", `Você fez ${score} pontos`);
areas.forEach(area => area.classList.remove("area"));
areas.forEach(area => area.removeEventListener("click", checkClickedArea));
}
function checkClickedArea(event) {
if(areas[numberRandom] === event.target) {
myScore.textContent = `Pontuação: ${++score}`;
randomAreas.delete(areas[numberRandom]);
shuffleOrder();
} else {
console.log(randomAreas)
gameOver();
}
}
function shuffleOrder() {
numberRandom = Math.floor(Math.random() * 4);
randomAreas.add(areas[numberRandom]);
console.log(randomAreas)
lightArea(numberRandom);
}
function lightArea(index) {
// atribui o número 1 se o valor do index for 0
let number = index | 1;
const time = 200 + (number * 100);
const colorShadow = areas[index].className.replace(" area", "");
areas[index].classList.add("selected");
if(genius.classList.contains("view3D")) {
genius.style.boxShadow = `0px 4px 4px ${colorShadow}, 0px 13px 8px #101010`;
}
setTimeout(() => {
areas[index].classList.remove("selected");
genius.style.boxShadow = "initial";
}, time)
console.log(time)
}
function start() {
randomAreas.clear()
shuffleOrder();
showMessage("Pontuação:");
btnStart.disabled = true;
btnStart.textContent = "Desabilitado";
areas.forEach(area => area.classList.add("area"));
areas.forEach(area => area.addEventListener("click", checkClickedArea));
}
function apply3DTransform() {
genius.classList.toggle("view3D");
}
btnStart.addEventListener("click", start);
btn3D.addEventListener("click", apply3DTransform);
})()