html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pokémon Battle Game</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
}
#battle {
margin-top: 50px;
}
#player, #opponent {
display: inline-block;
vertical-align: top;
margin: 20px;
}
img {
width: 100px;
height: 100px;
border: 2px solid #333;
border-radius: 10px;
}
#player-health, #opponent-health {
margin-top: 10px;
font-size: 18px;
}
button {
margin-top: 30px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>🔥 Pokémon Battle 🔥</h1>
<div id="battle">
<div id="player">
<img id="player-sprite" src="" alt="Player's Pokémon">
<div id="player-health">Health: 100/100</div>
</div>
<div id="opponent">
<img id="opponent-sprite" src="" alt="Opponent's Pokémon">
<div id="opponent-health">Health: 100/100</div>
</div>
<button id="attack-button">Attack</button>
</div>
<script>
// Define Pokémon
const playerPokemon = {
name: "Bulbasaur",
health: 100,
maxHealth: 100,
attack: 25,
sprite: "https://pokemondb.net/sprites/black-white/normal/bulbasaur.png"
};
const opponentPokemon = {
name: "Charmander",
health: 100,
maxHealth: 100,
attack: 20,
sprite: "https://pokemondb.net/sprites/black-white/normal/charmander.png"
};
// Initialize sprites and health display
document.getElementById("player-sprite").src = playerPokemon.sprite;
document.getElementById("opponent-sprite").src = opponentPokemon.sprite;
function updateHealthBars() {
document.getElementById("player-health").textContent = `Health: ${playerPokemon.health}/${playerPokemon.maxHealth}`;
document.getElementById("opponent-health").textContent = `Health: ${opponentPokemon.health}/${opponentPokemon.maxHealth}`;
}
updateHealthBars();
// Battle logic
document.getElementById("attack-button").addEventListener("click", () => {
// Player attacks
opponentPokemon.health = Math.max(0, opponentPokemon.health - playerPokemon.attack);
updateHealthBars();
if (opponentPokemon.health === 0) {
alert(`${opponentPokemon.name} was defeated!`);
return;
}
// Opponent attacks
playerPokemon.health = Math.max(0, playerPokemon.health - opponentPokemon.attack);
updateHealthBars();
if (playerPokemon.health === 0) {
alert(`${playerPokemon.name} was defeated!`);
}
});
</script>
</body>
</html>