
-----------------------------------
Aziz
Mon Jul 31, 2006 7:12 pm

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 :P).

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 :)

-----------------------------------
wtd
Mon Jul 31, 2006 8:12 pm


-----------------------------------
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.

-----------------------------------
Aziz
Tue Aug 01, 2006 11:36 am


-----------------------------------
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?

-----------------------------------
wtd
Tue Aug 01, 2006 12:37 pm


-----------------------------------
You should not have public fields, and yes, that would work.

-----------------------------------
Aziz
Tue Aug 01, 2006 3:43 pm


-----------------------------------
Okay, thank you wtd. I'm going to take your advice into mind while working on the project :) I'm creating a bunch of classes first, and then going to work on a text-based battle engine, and from there on. Graphics last, I've got a book Game Programming for Teens for VB6 and it shouldn't be too hard to port the graphics to java.
