// in general, it could be potion, armor, weapon, etc.
Item class {
// states
id
name
// behavior
set, get of states here..
use()
// still thinking what is the other general behavior
}
// in general, it could be Gun,Sword,Wand, Bow (range,melee,magic)
Weapon class extends Item{
// gun - fire(); type: range (in the movie, the gun can be use as melee weapon too xD)
// sword - slash(); type: melee (in the movie, the sword can be thrown :) or use as magic wand?)
// wand - ??
// mace - bash();
// bow - shoot() ??
// so what is the general behavior of this weapon?
}
Bag class {} // parent is Item, collection of items here
// Human, Orc, etc
Character class {
// states
Weapon
// behavior
attack();
// still thinking what is the other behavior and states
}
// Swordsman, Magician, Archer, etc.
Hero class extends Character{
}
上面的代码是我正在开发的角色扮演游戏的 OOP 类,我很难考虑每个类的一般状态和行为。
问题
- 如何创建这些类(我是 OOP 的初学者)。我听说过一些封装,多态等。
- 我不知道如何正确使用接口、抽象等。
- 思考类的一般状态和行为
- 正如您在武器类中看到的那样。枪、剑、弓可以用作近战、射程甚至魔法。我应该称这些武器类型吗?(范围,近战,魔法)