Below is a simple 1v1 Pokémon battle game implemented using HTML, CSS, and JavaScript. I've used sprites from the website you mentioned (https://pokemondb.net/sprites). Specifically, I'll use the "home" sprites for Pikachu and Bulbasaur as examples.
Key Features:
- Pokemon Selection: For simplicity, the game is hardcoded with two Pokémon: Pikachu (Player 1) and Bulbasaur (Player 2). Each starts with 100 HP.
- Moves: Each Pokémon has a single fixed move that deals 20 damage (e.g., "Quick Attack" for Pikachu and "Tackle" for Bulbasaur).
- Battle Mechanics: Players take turns attacking. After one player attacks, the turn switches to the other player. The game checks for win conditions (HP ≤ 0).
- UI: Displays Pokémon sprites, HP bars, and attack buttons. Buttons are disabled/enabled based on whose turn it is.
- Sprites: I'm using the following sprite URLs:
This is a basic implementation and assumes you're running it in a web browser. You can copy the code into an HTML file and open it in your browser to play.
HTML, CSS, and JavaScript Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Pokémon Battle</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
}
#battle-arena {
display: flex;
justify-content: space-around;
align-items: center;
margin-top: 50px;
}
.pokemon-container {
text-align: center;
}
img {
width: 200px; /* Adjust size as needed */
height: 200px;
}
#player1, #player2 {
margin: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
margin: 10px;
cursor: pointer;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
</style>
</head>
<body>
<h1>Simple 1v1 Pokémon Battle</h1>
<div id="battle-arena">
<div id="player1" class="pokemon-container">
<h2>Player 1: Pikachu</h2>
<img id="p1Sprite" src="https://img.pokemondb.net/sprites/home/normal/2x/pikachu.png" alt="Pikachu">
<p id="p1HP">HP: 100/100</p>
<button id="p1Attack">Pikachu Attacks (Quick Attack)</button>
</div>
<div id="player2" class="pokemon-container">
<h2>Player 2: Bulbasaur</h2>
<img id="p2Sprite" src="https://img.pokemondb.net/sprites/home/normal/2x/bulbasaur.png" alt="Bulbasaur">
<p id="p2HP">HP: 100/100</p>
<button id="p2Attack">Bulbasaur Attacks (Tackle)</button>
</div>
</div>
<script>
// Define the Pokémon objects
const pikachu = {
name: 'Pikachu',
hp: 100,
maxHp: 100,
move: { name: 'Quick Attack', damage: 20 }
};
const bulbasaur = {
name: 'Bulbasaur',
hp: 100,
maxHp: 100,
move: { name: 'Tackle', damage: 20 }
};
let currentTurn = 'player1'; // Start with Player 1
// Function to update HP display
function updateHP() {
document.getElementById('p1HP').textContent = `HP: ${pikachu.hp}/${pikachu.maxHp}`;
document.getElementById('p2HP').textContent = `HP: ${bulbasaur.hp}/${bulbasaur.maxHp}`;
}
// Function to update buttons based on turn
function updateButtons() {
document.getElementById('p1Attack').disabled = currentTurn !== 'player1';
document.getElementById('p2Attack').disabled = currentTurn !== 'player2';
}
// Event listener for Player 1's attack
document.getElementById('p1Attack').addEventListener('click', () => {
if (currentTurn === 'player1' && bulbasaur.hp > 0) {
// Pikachu attacks Bulbasaur
bulbasaur.hp -= pikachu.move.damage;
if (bulbasaur.hp < 0) bulbasaur.hp = 0;
updateHP(); // Update the display
if (bulbasaur.hp <= 0) {
alert('Pikachu wins the battle!');
// End the game (disable buttons)
document.getElementById('p1Attack').disabled = true;
document.getElementById('p2Attack').disabled = true;
} else {
currentTurn = 'player2'; // Switch turn
updateButtons();
}
}
});
// Event listener for Player 2's attack
document.getElementById('p2Attack').addEventListener('click', () => {
if (currentTurn === 'player2' && pikachu.hp > 0) {
// Bulbasaur attacks Pikachu
pikachu.hp -= bulbasaur.move.damage;
if (pikachu.hp < 0) pikachu.hp = 0;
updateHP(); // Update the display
if (pikachu.hp <= 0) {
alert('Bulbasaur wins the battle!');
// End the game (disable buttons)
document.getElementById('p1Attack').disabled = true;
document.getElementById('p2Attack').disabled = true;
} else {
currentTurn = 'player1'; // Switch turn
updateButtons();
}
}
});
// Initial setup
updateHP(); // Set initial HP
updateButtons(); // Disable Player 2's button at start
</script>
</body>
</html>
How to Play:
- Save the above code in a file named
index.html.
- Open the file in a web browser.
- Player 1's Turn: Click the "Pikachu Attacks" button to attack Bulbasaur.
- Player 2's Turn: After Player 1 attacks, the turn switches, and you can click "Bulbasaur Attacks" to attack Pikachu.
- The game alternates turns until one Pokémon's HP reaches 0 or below, at which point an alert declares the winner and disables the buttons.
Limitations and Notes:
- Simplicity: This is a very basic version. It doesn't include Pokémon types, multiple moves, accuracy checks, or AI for a second player. You can expand it by adding more features like random damage or user-selectable Pokémon.
- Sprites: I used publicly available sprites from the website. Make sure the URLs are correct and accessible; they might change over time.
- Error Handling: The game assumes players will follow the turn order. In a more advanced version, you could add animations or sound effects.
- Customization: If you want to use different Pokémon, simply replace the sprite URLs and adjust the Pokémon objects in the JavaScript code.
This should give you a functional, simple Pokémon battle game! If you'd like to add more features, let me know.