scrimba
Build an RPG
Build a role-playing game part 3 - The gameplay
Adding more monsters 1
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Adding more monsters 1
AboutCommentsNotes
Adding more monsters 1
Expand for more info
index.js
run
preview
console
import characterData from './data.js'
import Character from './Character.js'

let monstersArray = ["orc", "demon", "goblin"];

/*
Challenge
1. Create a function called getNewMonster.
2. Write logic inside the function that takes the first
monster from monstersArray and extracts that monster's
data from characterData.
3. Save that data to a new const called nextMonsterData.
**hint.md for help!!**
*/

function attack() {
wizard.getDiceHtml()
orc.getDiceHtml()
wizard.takeDamage(orc.currentDiceScore)
orc.takeDamage(wizard.currentDiceScore)
render()

if(wizard.dead || orc.dead){
endGame()
}
}

function endGame() {
const endMessage = wizard.health === 0 && orc.health === 0 ?
"No victors - all creatures are dead" :
wizard.health > 0 ? "The Wizard Wins" :
"The Orc is Victorious"

const endEmoji = wizard.health > 0 ? "🔮" : "☠️"
document.body.innerHTML = `
<div class="end-game">
<h2>Game Over</h2>
<h3>${endMessage}</h3>
<p class="end-emoji">${endEmoji}</p>
</div>
`
}

document.getElementById("attack-button").addEventListener('click', attack)

function render() {
document.getElementById('hero').innerHTML = wizard.getCharacterHtml()
document.getElementById('monster').innerHTML = orc.getCharacterHtml()
}

const wizard = new Character(characterData.hero)
const orc = new Character(characterData.monster)
render()
Console
!
Error: Unknown error
,
/index.html
-4:49