Java OOP - 角色扮演游戏 类 一般

Java OOP - Role Playing Game classes in GENERAL

// 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{
} 

The above code is my OOP classes of Role Playing Game that I am developing, and I'm having hard time thinking of the general states and behavior of each classes.

问题

让我们逐行回答您的问题

How do I create these classes (I am beginner in OOP). I've heard some encapsulations, polymorphish etc.

如果不彻底了解 OOPS.Spend 一段时间就无法开发游戏 Abstraction/Encapsulation/Polymerphsim/Inheritance。

I don't know how to use properly the interface, abstract etc.

也许如果您知道它们的含义,您就可以决定何时以及如何使用它们(如果您确实需要它们的话)。

Thinking of the general states and behavior of classes As you can see in the weapon class. The gun, sword, bow can be use as melee, range, or even magic. And should I call these WeaponType? (range,melee,magic)

在这种情况下,你可以有一个名为 Weapons 的接口,它们的类型是抽象的 methods.You 可以继承它们并使武器 属性 为每个武器等改变攻击力,强度 etc.Of 当然,您需要再次学习 OOPS 概念。 如果你学得很快 Start by watching this Video.

对于像游戏这样复杂的设计,我建议你研究更好的界面和抽象类。然后,我建议您绘制游戏模型的 UML 图。 Weapon 可以是一个带有 fire() 方法的接口,所有实现该接口的武器都有自己的 fire() 方法。

为了好的设计我也建议好好学习设计模式。如果你对你的游戏做了很好的设计,将来会很容易地用新的功能扩展你的游戏!