From 3ac518289a60e34c07c64bdca659a261be87b0ba Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 30 Jul 2024 22:37:15 -0300 Subject: [PATCH] update project robotron 2000 --- index.html | 41 ++++++++++++++++++----------------- js/main.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 js/main.js diff --git a/index.html b/index.html index 0deb0928..fc384324 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@
- Robotron + Robotron
ROBOTRON
2000
@@ -23,25 +23,25 @@

Força

-

768

+

768

Poder

-

630

+

630

Energia

-

289

+

289

Velocidade

-

597

+

597

@@ -52,45 +52,45 @@
- - - - + + - + + +

- - - - + + - + + +

- - - - + + - + + +

- - - - + + - + + +

- - - - + + - + + +
@@ -98,5 +98,6 @@
+ \ No newline at end of file diff --git a/js/main.js b/js/main.js new file mode 100644 index 00000000..908221ff --- /dev/null +++ b/js/main.js @@ -0,0 +1,63 @@ +const controle = document.querySelectorAll('[data-controle]') +const estatistica = 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": -4 + }, + "pernas": { + "forca": 27, + "poder": 21, + "energia": -32, + "velocidade": 43 + }, + "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 if (operacao === "-") { + if (peca.value >= 1) { + peca.value = parseInt(peca.value) - 1 + } else { + alert("Não é possível deixar o atributo braço com valor negativo.") + } + } +} + +function atualizaEstatisticas(peca) { + estatistica.forEach( (elemento) => { + elemento.textContent = parseInt(elemento.textContent) + pecas[peca][elemento.dataset.estatistica] + }) +} \ No newline at end of file