Skip to content

Instantly share code, notes, and snippets.

@diazabdulm
Created March 19, 2021 01:18
Show Gist options
  • Save diazabdulm/f2314e066db009eb0abf24dce772a0c3 to your computer and use it in GitHub Desktop.
Save diazabdulm/f2314e066db009eb0abf24dce772a0c3 to your computer and use it in GitHub Desktop.
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