Computer Science Canada Advice for my new project (text rpg) |
Author: | Aziz [ Mon Jul 31, 2006 7:12 pm ] |
Post subject: | Advice for my new project (text rpg) |
Anyone who's been frequenting this forum can guess I'm working on an rpg-like game. Well, I'm starting with the classes, mostly. This is basically going to be my help thread (so I don't spam the forum ![]() My first question is about classes. Say I have a class like Element or Sword. Now, I'm going to have pre-made elements and swords in the game, like Air or Earth and Longsword or Saber. So would it be a bad a idea, in your opinion, to create new classes, like AirElement, EarthElement, Longsword or Saber, and have the constructor call super()? For example, say Sword's constructor required a name, description, cost, and damage value, Longsword() would call super("Longsword", "A sword with a long blade.", 50, 14); Or simply create a new Sword? I was thinking this approach for pre-defined weapons, to be added in shops, etc. But it would be a lot. Not actually a technical problem, but more an effeciency problem. Thanks a lot ![]() |
Author: | wtd [ Mon Jul 31, 2006 8:12 pm ] |
Post subject: | |
Alternatively, you may wish to define a set of behaviors which characterize a sword. This would be an interface. Then weapons can freely imp-lement this interface. Just a possibility. |
Author: | Aziz [ Tue Aug 01, 2006 11:36 am ] |
Post subject: | |
I was thinking about that, but a Sword would have fields and methods. Like int damage;. Perhaps I would just specify a getDamage() method in the Sword interface, and this would force the implementing class to do something with it? And say interface Sword extends interface Weaopon. Would "new LongSword() instanceof Weapon" work? |
Author: | wtd [ Tue Aug 01, 2006 12:37 pm ] |
Post subject: | |
You should not have public fields, and yes, that would work. |
Author: | Aziz [ Tue Aug 01, 2006 3:43 pm ] |
Post subject: | |
Okay, thank you wtd. I'm going to take your advice into mind while working on the project ![]() |