create Javascript pseudocode for minion card Heartstone
- User
create Javascript pseudocode for minion card Heartstone
- Assistant
- Declare variables for minion name, mana cost, attack, health and text description
- Define function to create minion card with input parameters
- Create div element for card
- Create elements for minion name, attack, health and mana cost
- Set text content of elements with corresponding input parameters
- Create element for text description and set text content with corresponding input parameter
- Append all elements to div element
- Return div element to display on screen.
Sample code:
function createMinionCard(minionName, manaCost, attack, health, textDescription) { var cardDiv = document.createElement("div"); var minionNameEl = document.createElement("h2"); var attackEl = document.createElement("p"); var healthEl = document.createElement("p"); var manaCostEl = document.createElement("p"); var textDescEl = document.createElement("p");
minionNameEl.textContent = minionName; attackEl.textContent = "Attack: " + attack; healthEl.textContent = "Health: " + health; manaCostEl.textContent = "Mana Cost: " + manaCost; textDescEl.textContent = textDescription;
cardDiv.appendChild(minionNameEl); cardDiv.appendChild(attackEl); cardDiv.appendChild(healthEl); cardDiv.appendChild(manaCostEl); cardDiv.appendChild(textDescEl);
return cardDiv; }
- User
write it as class
- Assistant
Sure! Here's the Heartstone minion card class written in JavaScript:
class HeartstoneMinionCard { constructor(minionName, manaCost, attack, health, textDescription) { this.minionName = minionName; this.manaCost = manaCost; this.attack = attack; this.health = health; this.textDescription = textDescription; } createCard() { const cardDiv = document.createElement("div"); const minionNameEl = document.createElement("h2"); const attackEl = document.createElement("p"); const healthEl = document.createElement("p"); const manaCostEl = document.createElement("p"); const textDescEl = document.createElement("p"); minionNameEl.textContent = this.minionName; attackEl.textContent = "Attack: " + this.attack; healthEl.textContent = "Health: " + this.health; manaCostEl.textContent = "Mana Cost: " + this.manaCost; textDescEl.textContent = this.textDescription; cardDiv.appendChild(minionNameEl); cardDiv.appendChild(attackEl); cardDiv.appendChild(healthEl); cardDiv.appendChild(manaCostEl); cardDiv.appendChild(textDescEl); return cardDiv; } }This HeartstoneMinionCard class has a constructor for the minion's name, mana cost, attack, health, and text description, and a createCard method that generates the HTML elements for a minion card with those properties when called. You would create a new minion card by instantiating the class with the desired stats, like so:
const minion = new HeartstoneMinionCard("Minion Name", 2, 2, 2, "Text description."); document.body.appendChild(minion.createCard());This would create an instance of the HeartstoneMinionCard class with the specified properties, and append the generated HTML to the document body.
- User
add minion with battlecry and minion with deathrattle
- Assistant
Absolutely! Here's an updated version of the HeartstoneMinionCard class with two additional subclasses, HeartstoneBattlecryMinionCard and HeartstoneDeathrattleMinionCard, which inherit from the base class and add either a battlecry or a deathrattle effect, respectively:
class HeartstoneMinionCard { constructor(minionName, manaCost, attack, health, textDescription) { this.minionName = minionName; this.manaCost = manaCost; this.attack = attack; this.health = health; this.textDescription = textDescription; } createCard() { const cardDiv = document.createElement("div"); const minionNameEl = document.createElement("h2"); const attackEl = document.createElement("p"); const healthEl = document.createElement("p"); const manaCostEl = document.createElement("p"); const textDescEl = document.createElement("p"); minionNameEl.textContent = this.minionName; attackEl.textContent = "Attack: " + this.attack; healthEl.textContent = "Health: " + this.health; manaCostEl.textContent = "Mana Cost: " + this.manaCost; textDescEl.textContent = this.textDescription; cardDiv.appendChild(minionNameEl); cardDiv.appendChild(attackEl); cardDiv.appendChild(healthEl); cardDiv.appendChild(manaCostEl); cardDiv.appendChild(textDescEl); return cardDiv; } } class HeartstoneBattlecryMinionCard extends HeartstoneMinionCard { constructor(minionName, manaCost, attack, health, textDescription, battlecryEffect) { super(minionName, manaCost, attack, health, textDescription); this.battlecryEffect = battlecryEffect; } createCard() { const cardDiv = super.createCard(); const battlecryEl = document.createElement("p"); battlecryEl.textContent = "Battlecry: " + this.battlecryEffect; cardDiv.appendChild(battlecryEl); return cardDiv; } } class HeartstoneDeathrattleMinionCard extends HeartstoneMinionCard { constructor(minionName, manaCost, attack, health, textDescription, deathrattleEffect) { super(minionName, manaCost, attack, health, textDescription); this.deathrattleEffect = deathrattleEffect; } createCard() { const cardDiv = super.createCard(); const deathrattleEl = document.createElement("p"); deathrattleEl.textContent = "Deathrattle: " + this.deathrattleEffect; cardDiv.appendChild(deathrattleEl); return cardDiv; } }Now, the HeartstoneBattlecryMinionCard subclass adds a battlecry effect to the card, and the HeartstoneDeathrattleMinionCard subclass adds a deathrattle effect. Both these subclasses override the createCard() method of the base class to add the additional effect text to the generated HTML. You could create a new minion card with either of these effects by instantiating the corresponding subclass with the desired stats and effect text, like so:
const battlecryMinion = new HeartstoneBattlecryMinionCard("Minion Name", 3, 4, 5, "Text description.", "Deal 2 damage to all enemy minions"); document.body.appendChild(battlecryMinion.createCard()); const deathrattleMinion = new HeartstoneDeathrattleMinionCard("Another Minion Name", 2, 2, 2, "Another text description.", "Draw a card"); document.body.appendChild(deathrattleMinion.createCard());This would create a battlecry minion card with the specified properties and effect text, and a deathrattle minion card with the specified properties and effect text, and append their generated HTML to the document body.