Search code examples
javaoopgeneralization

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.

Problem

  • How do I create these classes (I am beginner in OOP). I've heard some encapsulations, polymorphish etc.
  • 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)

Solution

  • Let's answer your queries line by line

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

    You cannot develop a game without having a through understand of OOPS.Spend some time understanding Abstraction/Encapsulation/Polymerphsim/Inheritance.

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

    Maybe if you know what those mean you would be able to decide when and how to use them if at all you would be needing them.

    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)

    In this case,you can have an interface called Weapons with their types as abstract methods.You can inherit them and make the weapon property changes for each weapon etc like attack power,strength etc.Of course again you need to be through with OOPS concepts. If you're a quick learner Start by watching this Video.