Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 22, 2019 04:31
Show Gist options
  • Save jsmanifest/55726260275d3f23516676618865bd70 to your computer and use it in GitHub Desktop.
Save jsmanifest/55726260275d3f23516676618865bd70 to your computer and use it in GitHub Desktop.
const characters = []
const Warrior = function createWarrior(name) {
this.name = name
this.hp = 100
this.mp = 100
this.defence = 60
return {
// Slash the enemy, decreasing their hp down by 35
slash(target) {
target.hp -= 35
return target
},
// Increases the warrior's defence by 100 for 40 seconds.
// Each second will decrement their defence by 1 as the time runs out.
battleCry() {
this.defence += 100
this.battleCryInterval = setInterval(() => {
this.defence -= 1
}, 1000)
this.battleCryTimeout = setTimeout(() => {
this.defence = 60
}, 40000)
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment