// 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類,我在一般狀態很難思維和行爲的每個類。Java的面向對象 - 角色扮演類一般
問題
- 如何創建這些類(我在OOP的初學者)。我聽說過一些封裝,polymorphish等
- 我不知道如何正確使用接口,抽象等 一般狀態和類行爲
- 思考
- 正如你可以在武器看類。槍,劍,弓可以用作近戰,射程,甚至魔法。我應該把這些WeaponType稱爲什麼? (範圍,肉搏,法術)
注意它是'Foo類'而不是'Foo類'也許你可以從閱讀一些教程開始,比如https://docs.oracle.com/javase/tutorial/java/index.html,這個問題太寬泛了作爲 –
確定你有正確的標籤?這當然不是Java源代碼?! – GhostCat
只是一個錯字,對不起。 – ronscript