Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#commit "vecel" #10

Open
wants to merge 1 commit into
base: projeto_inicial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Teko:wght@300;500&display=swap" rel="stylesheet">

</head>
<body>
<main>
<section class="robotron">
<img class="robo" src="img/robotron.png" alt="Robotron">
<img class="robo" src="img/robotron.png" alt="Robotron" id="robotron">
<figcaption class="titulo">ROBOTRON <br>2000</figcaption>
</section>

<section class="box estatisticas">
<div class="estatistica">
<p class="estatistica-titulo">Força</p>
<div class="estatistica-valor">
<p class="estatistica-numero">768</p>
<p class="estatistica-numero" data-estatistica="forca">0</p>
</div>
</div>
<div class="estatistica">
<p class="estatistica-titulo">Poder</p>
<div class="estatistica-valor">
<p class="estatistica-numero">630</p>
<p class="estatistica-numero" data-estatistica="poder">0</p>
</div>
</div>
<div class="estatistica">
<p class="estatistica-titulo">Energia</p>
<div class="estatistica-valor">
<p class="estatistica-numero">289</p>
<p class="estatistica-numero" data-estatistica="energia">0</p>
</div>
</div>
<div class="estatistica">
<p class="estatistica-titulo">Velocidade</p>
<div class="estatistica-valor">
<p class="estatistica-numero">597</p>
<p class="estatistica-numero" data-estatistica="velocidade">0</p>
</div>
</div>
</section>
Expand All @@ -52,51 +53,54 @@
<div class="peca">
<label for="" class="peca-titulo">Braços</label>
<div class="controle">
<buttom class="controle-ajuste">-</buttom>
<input type="text" class="controle-contador" value="00">
<buttom class="controle-ajuste">+</buttom>
<buttom class="controle-ajuste" id="subtrair" data-controle="-" data-peca="bracos">-</buttom>
<input type="text" class="controle-contador" value="00" data-contador>
data-controle="+" <buttom class="controle-ajuste" data-controle="+" data-peca="bracos">+</buttom>
</div>
</div>
<hr class="linha">
<div class="peca">
<label for="" class="peca-titulo">Blindagem</label>
<div class="controle">
<buttom class="controle-ajuste">-</buttom>
<input type="text" class="controle-contador" value="00">
<buttom class="controle-ajuste">+</buttom>
<buttom class="controle-ajuste" data-controle="-" data-peca="blindagem">-</buttom>
<input type="text" class="controle-contador" value="00" data-contador>
<buttom class="controle-ajuste" data-controle="+" data-peca="blindagem">+</buttom>
</div>
</div>
<hr class="linha">
<div class="peca">
<label for="" class="peca-titulo">Núcleos</label>
<div class="controle">
<buttom class="controle-ajuste">-</buttom>
<input type="text" class="controle-contador" value="00">
<buttom class="controle-ajuste">+</buttom>
<buttom class="controle-ajuste" data-controle="-" data-peca="nucleos">-</buttom>
<input type="text" class="controle-contador" value="00" data-contador>
<buttom class="controle-ajuste" data-controle="+" data-peca="nucleos">+</buttom>
</div>
</div>
<hr class="linha">
<div class="peca">
<label for="" class="peca-titulo">Pernas</label>
<div class="controle">
<buttom class="controle-ajuste">-</buttom>
<input type="text" class="controle-contador" value="00">
<buttom class="controle-ajuste">+</buttom>
<buttom class="controle-ajuste" data-controle="-" data-peca="pernas">-</buttom>
<input type="text" class="controle-contador" value="00" data-contador>
<buttom class="controle-ajuste" data-controle="+" data-peca="pernas">+</buttom>
</div>
</div>
<hr class="linha">
<div class="peca">
<label for="" class="peca-titulo">Foguetes</label>
<div class="controle">
<buttom class="controle-ajuste">-</buttom>
<input type="text" class="controle-contador" value="00">
<buttom class="controle-ajuste">+</buttom>
<buttom class="controle-ajuste" data-controle="-" data-peca="foguetes">-</buttom>
<input type="text" class="controle-contador" value="00" data-contador>
<buttom class="controle-ajuste" data-controle="+" data-peca="foguetes">+</buttom>
</div>
</div>
</div>
<input type="submit" value="Iniciar produção" class="producao" id="producao">
</form>
</section>
</main>

<script src="js/main.js"></script>

</body>
</html>
65 changes: 65 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// const subtrair = document.querySelector("#subtrair"); refatorado no ForEach. Na funcao manipulaDados, as operacoes somar e subtrair ja sao as condicoes if e else.
// const somar = document.querySelector("#somar"); refatorado no ForEach. Na funcao manipulaDados, as operacoes somar e subtrair ja sao as condicoes if e else.
// const braco = document.querySelector("#braco"); refatorado na function manipulaDados(... , controle)

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);
})
});

// somar.addEventListener("click", () => {manipulaDados("somar")}); <------ refatorado no ForEach. Na funcao manipulaDados, as operacoes somar e subtrair ja sao as condicoes if e else.
// subtrair.addEventListener("click", () => {manipulaDados("subtrair")}); <------ refatorado no ForEach. Na funcao manipulaDados, as operacoes somar e subtrair ja sao as condicoes if e else.

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]
})
}