I have in mind an idea for my first java project (OO focused). This project is some kind of a very basic roleplaying game (NO GUI, it's very basic), so I have some OOD questions.
A player (no player class is intended, at least for now) can choose a character class (you know, fighter, wizard etc... in the future he might be able to choose a few characters so he can have a party). After the character has been created he can fight against other foes (controlled by the program).
- Each charcter has some info like: a character class (like fighter), Level, Armor Class, Abilities (Strength, Dexterity, Wisdom etc.).
- Each Class has an inventory.
Each character has some methods like:
Attack (use a weapon, if he's a spell caster then casting spells also can use Attack).
- Defend (like defensive spells or use abilities like parry. note: changes armor class.
Some character classes (like wizards) can Cast Spells. Most spells will are offensive or defensive, so they can use Attack or Defend method. let's say that castFireball can call Attack(20) for example. Some spells can do other things like castHeal which heals the character and changes the current hit points.
Buy (optional for future). same implementation for all characters of course.
- Add/Remove from inventory.
Suggested implementation: I thought about creating an abstract class (with info like Level, Armor class, Abilities (like strength, dexterity, wisdom etc.). and some methods like attack and defend. Other specific classes will extend Character so it looks like:
Character (abstract)
Character Class (like fighter)
Level
Hit Points
Current Hit Points
Armor Class
.
.
.
Inventory (List)
Strength
Dexterity
Wisdom
Fighter Wizard Rouge Cleric (All extends Character)
Questions:
- Using abstract class here is considered as a good design in this case? would you suggest using an interface and change the design ?
- Should I make a another class for Abilities like strength, wisdom etc. or it's ok that it's a part of Character ?
- Should I make another class for inventory? I think it might be better, right?
- Storing data for all weapons, armors, and shield (maybe other stuff in the future) by using enums is a good solution?
- Spells - I'm not sure what is a good way to implement them. I can create a spells class, with static methods for each spell (like castFireball, castHeal methods). Casting spells is relevant only to spell casters characters of course (and each character has a known spells list, so he can cast only spells he knows). Is it a good way to implement that? I can also use a txt file and get the relevant data from the file, but I'm not fond of this idea.
Keep in mind that it should be basic, but it should be planned for future changes and additions. It would look like:
How would you like to attack?
- Dagger (primary weapon)
- Sword
- Cast Spell
3
Which spell would you like to cast?
- Fireball
- Heal
- Ice Storm
1
You hit the enemy with a fireball, and dealt 20 damage.
It's very vague, but you get the idea..
Thanks a lot !!