Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgrqf2r9xgg7bwkuntitledPlain Text
<!DOCTYPE html>
<html>
<head>
<title>Mini Pokémon Battle</title>
<style>
body { font-family: Arial; background:#f2f2f2; padding:20px; }
.pokemon-box { border:1px solid #ccc; padding:15px; margin:10px; background:white; }
.hp-bar { height:20px; background:green; width:100%; transition:0.3s; }
button { padding:10px 20px; margin-top:10px; }
</style>
</head>
<body>
<h1>Mini Pokémon Battle</h1>
<div id="game"></div>
<script>
// --- Pokémon Data ---
const pokemonList = [
{ name: "Pikachu", hp: 60, attack: 15 },
{ name: "Charmander", hp: 55, attack: 18 },
{ name: "Bulbasaur", hp: 65, attack: 14 }
];
const enemies = [
{ name: "Squirtle", hp: 60, attack: 13 },
{ name: "Eevee", hp: 55, attack: 12 },
{ name: "Meowth", hp: 50, attack: 10 }
];
let player, enemy;
// --- Start Game ---
function startGame() {
const game = document.getElementById("game");
game.innerHTML = "<h2>Choose your Pokémon:</h2>";
pokemonList.forEach((p, index) => {
const box = document.createElement("div");
box.className = "pokemon-box";
box.innerHTML = `<strong>${p.name}</strong><br>HP: ${p.hp}<br>Attack: ${p.attack}`;
box.onclick = () => choosePokemon(index);
game.appendChild(box);
});
}
function choosePokemon(index) {
player = JSON.parse(JSON.stringify(pokemonList[index]));
enemy = JSON.parse(JSON.stringify(enemies[Math.floor(Math.random()*enemies.length)]));
battleScreen();
}
// --- Battle Screen ---
function battleScreen() {
const game = document.getElementById("game");
game.innerHTML = `
<h2>Battle!</h2>
<div class="pokemon-box">
<h3>${player.name}</h3>
<div id="playerHP" class="hp-bar"></div>
</div>
<div class="pokemon-box">
<h3>${enemy.name}</h3>
<div id="enemyHP" class="hp-bar"></div>
</div>
<button onclick="attack()">Attack!</button>
<p id="log"></p>
`;
updateBars();
}
// --- Attack Logic ---
function attack() {
enemy.hp -= player.attack;
document.getElementById("log").innerText = `${player.name} hits ${enemy.name} for ${player.attack}!`;
if (enemy.hp <= 0) {
enemy.hp = 0;
updateBars();
endGame(true);
return;
}
// Enemy turn
setTimeout(() => {
player.hp -= enemy.attack;
document.getElementById("log").innerText += `
${enemy.name} hits ${player.name} for ${enemy.attack}!`;
if (player.hp <= 0) {
player.hp = 0;
updateBars();
endGame(false);
return;
}
updateBars();
}, 600);
}
function updateBars() {
document.getElementById("playerHP").style.width = (player.hp / 60 * 100) + "%";
document.getElementById("enemyHP").style.width = (enemy.hp / 60 * 100) + "%";
}
// --- End Game ---
function endGame(win) {
const game = document.getElementById("game");
game.innerHTML = `
<h2>${win ? "You Win!" : "You Lose!"}</h2>
<button onclick="startGame()">Play Again</button>
`;
}
// Start the game
startGame();
</script>
</body>
</html>2,966 chars · codepastes.com