-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
71 lines (62 loc) · 1.87 KB
/
main.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
const controle = document.querySelectorAll("[data-controle]")
const estatisticas = document.querySelectorAll('[data-estatistica')
const pecas = {
"bracos": {
"forca": 29,
"poder": 35,
"energia": -21,
"velocidade": -5
},
"blindagem": {
"forca": 41,
"poder": 20,
"energia": 0,
"velocidade": -20
},
"nucleos":{
"forca": 0,
"poder": 7,
"energia": 48,
"velocidade": -24
},
"pernas":{
"forca": 27,
"poder": 21,
"energia": -32,
"velocidade": 42
},
"foguetes":{
"forca": 0,
"poder": 28,
"energia": 0,
"velocidade": -2
}
}
controle.forEach( (elemento) => {
elemento.addEventListener('click', (evento) => {
manipulaDados(evento.target.dataset.controle, evento.target.parentNode);
atualizaEstatisticas(evento.target.dataset.peca);
})
} )
function manipulaDados(operacao, controle){
const peca = controle.querySelector('[data-contador]');
if (operacao === "-") {
peca.value = parseInt(peca.value) -1
} else{
peca.value = parseInt(peca.value) +1
}}
function atualizaEstatisticas(peca) {
estatisticas.forEach( (elemento) => {
elemento.textContent = parseInt(elemento.textContent) + pecas[peca][elemento.dataset.estatistica]
} )
}
// COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO
const buttons = document.querySelectorAll(".cores-btn");
const robotronImage = document.querySelector("#robotron");
buttons.forEach(button => {
button.addEventListener("click", event => {
const color = event.target.dataset.cor;
robotronImage.src = `${color}.png`;
});
});
// COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO--COLORAÇÃO