Pedra, Papel, Tesoura Neon
by 201flaviosilva
HTML
<h1>Escolha sua jogada</h1>
<div>
<button id="Pedra">Pedra</button>
<button id="Papel">Papel</button>
<button id="Tesoura">Tesoura</button>
</div>
<h1>Resultado</h1>
<div id="resultado"></div>
<script src="game.js"></script>
CSS
body {
background-color: black;
color: white;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-size: 2em;
margin: 30px 0;
}
button {
background-color: #f44336;
border: none;
color: white;
padding: 12px 24px;
font-size: 16px;
cursor: pointer;
margin: 0 10px;
box-shadow: 0 0 10px #ff8c00;
}
button:active {
transform: translateY(3px);
box-shadow: none;
}
#resultado {
font-size: 2em;
margin: 30px 0;
text-shadow: 0 0 10px #ff8c00;
}
JavaScript
const choices = ["Pedra", "Papel", "Tesoura"];
let playerChoice;
let computerChoice;
function getComputerChoice() {
return choices[Math.floor(Math.random() * choices.length)];
}
function determineWinner(playerChoice, computerChoice) {
if (playerChoice === computerChoice) return "Empate";
else if (playerChoice === "Pedra" && computerChoice === "Tesoura" ||
playerChoice === "Papel" && computerChoice === "Pedra" ||
playerChoice === "Tesoura" && computerChoice === "Papel") {
return "Jogador venceu";
} else return "Computador venceu";
}
function play() {
computerChoice = getComputerChoice();
document.getElementById("resultado").innerHTML = `${playerChoice} - ${determineWinner(playerChoice, computerChoice)} - ${computerChoice}`;
}
// Adicionando eventos de clique para cada escolha do jogador
document.getElementById("Pedra").addEventListener("click", () => {
playerChoice = "Pedra";
play()
});
document.getElementById("Papel").addEventListener("click", () => {
playerChoice = "Papel";
play()
});
document.getElementById("Tesoura").addEventListener("click", () => {
playerChoice = "Tesoura";
play()
});