Create minion card class from Hearthstone in Javascript
- User
Create minion card class from Hearthstone in Javascript
- Assistant
class MinionCard { constructor(name, attackPoints, healthPoints, manaCost, text) { this.name = name; this.attackPoints = attackPoints; this.healthPoints = healthPoints; this.manaCost = manaCost; this.text = text; }
attack(target) { target.healthPoints -= this.attackPoints; } }
// Example Usage const minion1 = new MinionCard("Kevin", 2, 3, 3, "Taunt"); const minion2 = new MinionCard("Bob", 3, 5, 4, ""); minion1.attack(minion2); console.log(minion2.healthPoints); // Output: 2
- User
add minion which gain +1 attack when another minion added into board.
- Assistant
class MinionCard { constructor(name, attackPoints, healthPoints, manaCost, text) { this.name = name; this.attackPoints = attackPoints; this.healthPoints = healthPoints; this.manaCost = manaCost; this.text = text; }
attack(target) { target.healthPoints -= this.attackPoints; }
// New method to check and update attack points updateAttack(card) { if (card instanceof MinionCard) { this.attackPoints += 1; console.log(
${this.name}'s attack increased to ${this.attackPoints}); } } }// Example Usage const minion1 = new MinionCard("Kevin", 2, 3, 3, "Taunt"); const minion2 = new MinionCard("Bob", 3, 5, 4, ""); minion1.attack(minion2); console.log(minion2.healthPoints); // Output: 2 const minion3 = new MinionCard("Stuart", 1, 2, 2, ""); minion1.updateAttack(minion3); // Output: Kevin's attack increased to 3
- User
add minion which his attack ALWAYS equal friendly minion's count
- Assistant
You can modify the previously created MinionCard class to have the new functionality as shown below:
code - User
add minion which deal 1 damage to opponent when friendly minion added on board
- Assistant
You can modify the previously created MinionCard class to have the new functionality as shown below:
code