Created
March 19, 2021 01:18
-
-
Save diazabdulm/f2314e066db009eb0abf24dce772a0c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pokemon { | |
constructor(name, attack, defense, health, type) { | |
this.name = name; | |
this.attack = attack; | |
this.defense = defense; | |
this.health = health; | |
this.type = type; | |
this.initialHealth = health; | |
} | |
takeDamage(amount) { | |
this.health = Math.max(this.health - amount, 0); | |
} | |
attackOpponent(Opponent) { | |
const damage = Math.max(this.attack - Opponent.defense, 1); | |
Opponent.takeDamage(damage); | |
} | |
display() { | |
const { name, type, health, initialHealth } = this; | |
return `${name.toUpperCase()} (${type.toUpperCase()}) ${health}/${initialHealth}`; | |
} | |
} | |
module.exports = Pokemon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment