Skip to content

Instantly share code, notes, and snippets.

@burnjohn
Created September 1, 2019 11:29
Show Gist options
  • Save burnjohn/e9231d1b62b26d841d1e07010e61c94d to your computer and use it in GitHub Desktop.
Save burnjohn/e9231d1b62b26d841d1e07010e61c94d to your computer and use it in GitHub Desktop.
class Enemy {
constructor(config) {
const {name, health, attackPoints} = config;
this.#name = name;
this.#health = health;
this.#attackPoints = attackPoints;
this.enemyType = config.enemyType;
}
#name = null;
#health = null;
#attackPoints = null;
go() {
console.log(this.#name + " go");
}
protect() {
console.log(this.#name + " protect");
}
stop() {
console.log(this.#name + " stop");
}
attack() {
return `I attack ${this.#attackPoints} health points`;
}
}
class EnemyWeak extends Enemy {
constructor(config) {
const enemyType = 'enemyWeak';
const allParams = {...config, enemyType};
EnemyWeak.count = EnemyWeak.count + 1;
super(allParams);
}
static count = 0;
static getWeekEnemyCount() {
console.log(this);
return EnemyWeak.count;
}
attack() {
const baseString = super.attack();
console.log(baseString + ' 10 magic points');
}
}
const greenTurtle = new EnemyWeak({
name: 'green-turtle', health: 200, attackPoints:10
});
class EnemyStrong extends Enemy {
constructor(config) {
const enemyType = 'enemyStrong';
const allParams = {...config, enemyType};
super(allParams);
}
#location = ['desert', 'sea'];
attack() {
const baseString = super.attack();
console.log(baseString + ' 30 magic points');
}
getLocation() {
return this.#location;
}
}
const redTurtle = new EnemyStrong({
name: 'Red-turtle', health: 400, attackPoints:30
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment