// 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 の初心者です)。カプセル化、多形性などを聞いたことがあります。
- インターフェイス、アブストラクトなどを適切に使用する方法がわかりません。
- クラスの一般的な状態と動作を考える
- 武器クラスでわかるように。銃、剣、弓は、近接、範囲、さらには魔法として使用できます。そして、これらを WeaponType と呼ぶ必要がありますか? (範囲、近接、魔法)