shijian5
Version:
游戏对象类库
35 lines (29 loc) • 639 B
JavaScript
class GameObj {
constructor(name) {
this.name = name;
}
move() {
console.log(`${this.name}进行了移动`);
}
}
class NPC extends GameObj {
constructor(name, tittle) {
super(name);
this.tittle = tittle;
this.name = "NPC-" + name;
}
talk() {
console.log(`${this.tittle}头衔的${this.name}进行了说话`);
}
}
class Enemy extends GameObj {
constructor(name, hp) {
super(name);
this.hp = hp;
this.name = "Enemy-" + name;
}
attack() {
console.log(`${this.hp}血量的${this.name}进行了攻击`);
}
}
module.exports = { NPC, Enemy };