UNPKG

my-game-library-linjunhe

Version:

A simple game library with game objects and items

38 lines (32 loc) 780 B
// 父类 GameObj class GameObj { constructor(name) { this.name = name; } move() { console.log(`${this.name}进行了移动`); } } // NPC 子类 class NPC extends GameObj { constructor(name, title) { super(name); this.title = title; this.name = `NPC_${name}`; // 覆盖name属性 } talk() { console.log(`${this.title}头衔的${this.name}进行了说话`); } } // Enemy 子类 class Enemy extends GameObj { constructor(name, hp) { super(name); this.hp = hp; this.name = `Enemy_${name}`; // 覆盖name属性 } attack() { console.log(`${this.hp}血量的${this.name}进行了攻击`); } } export { NPC, Enemy };