implement Strike and Block cards from Slay the spire into Javascript classes
- User
implement Strike and Block cards from Slay the spire into Javascript classes
- Assistant
// Define Strike and Block classes
class Strike { constructor() { this.name = "Strike"; this.damage = 6; this.energyCost = 1; }
execute(target) { target.takeDamage(this.damage); } }
class Block { constructor() { this.name = "Block"; this.blockAmount = 5; this.energyCost = 1; }
execute() { player.block += this.blockAmount; } }
// Define Player class
class Player { constructor(name) { this.name = name; this.currentHealth = 50; this.maxHealth = 50; this.block = 0; this.energy = 3; }
takeDamage(damage) { if (this.block >= damage) { this.block -= damage; } else { damage -= this.block; this.currentHealth -= damage; this.block = 0; } }
spendEnergy(cost) { if (cost <= this.energy) { this.energy -= cost; return true; } else { return false; } }
endTurn() { this.block = 0; this.energy = 3; }
showStats() { console.log(
${this.name}: HP ${this.currentHealth}/${this.maxHealth} | Block ${this.block} | Energy ${this.energy}); }playCard(card, target) { if (this.spendEnergy(card.energyCost)) { console.log(
${this.name} plays ${card.name}); card.execute(target); } else { console.log("Not enough energy to play this card"); } } }// Set up game
let player = new Player("Player 1"); let enemy = new Player("Enemy");
// Test Strike and Block cards
let strike = new Strike(); let block = new Block();
player.showStats(); // Player 1: HP 50/50 | Block 0 | Energy 3 enemy.showStats(); // Enemy: HP 50/50 | Block 0 | Energy 3
player.playCard(strike, enemy); // Player 1 plays Strike player.showStats(); // Player 1: HP 50/50 | Block 0 | Energy 2 enemy.showStats(); // Enemy: HP 44/50 | Block 0 | Energy 3
player.playCard(block); // Player 1 plays Block player.showStats(); // Player 1: HP 50/50 | Block 5 | Energy 1
player.playCard(strike, enemy); // Player 1 plays Strike player.showStats(); // Player 1: HP 50/50 | Block 0 | Energy 0 enemy.showStats(); // Enemy: HP 38/50 | Block 0 | Energy 3
player.endTurn(); player.showStats(); // Player 1: HP 50/50 | Block 0 | Energy 3
- User
Add a target check, if necessary, and a mana card. If the card is playable, select the target first, then reduce mana and remove the card from your hand
- Assistant