-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
65 lines (59 loc) · 1.49 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
const controle = document.querySelectorAll('[data-controle]');
const estatisticas = document.querySelectorAll('[data-estatistica]')
const pecas = {
"Arms": {
"Strength": 29,
"Power": 35,
"Energy": -21,
"Speed": -5
},
"Shield": {
"Strength": 41,
"Power": 20,
"Energy": 0,
"Speed": -20
},
"Core":{
"Strength": 0,
"Power": 7,
"Energy": 48,
"Speed": -24
},
"Legs":{
"Strength": 27,
"Power": 21,
"Energy": -32,
"Speed": 42
},
"Rockets":{
"Strength": 0,
"Power": 28,
"Energy": 0,
"Speed": -2
}
}
controle.forEach( element =>{
element.addEventListener("click", event =>{
manipulaDados(event.target.dataset.controle, event.target.parentNode);
atualizaEstatisticas(event.target.dataset.peca);
})
})
document.querySelector("#robotron").addEventListener("click", () =>{
alert('Robotron Operante');
});
function manipulaDados(operacao, controle){
const peca = controle.querySelector('[data-contador]')
if(operacao === "+"){
if(peca.value < 10)
peca.value = parseInt(peca.value) + 1;
}
else{
if(peca.value > 0 )
peca.value = parseInt(peca.value) - 1;
}
}
function atualizaEstatisticas(peca) {
estatisticas.forEach( element => {
element.textContent = parseInt(element.textContent) + pecas[peca][element.dataset.estatistica];
})
}