1
\$\begingroup\$

Me and a friend are trying to make an RPG in Java, while we are learning the language, and we have been discussing the character implementation. We would like to know which is the best solution in computational and expanding criteria s.

The game will be something like Final Fantasy 6. We would have a lot of different characters, each having their own stats and 3 different abilities. The stats would change frequently, and be saved for future reference. It's not supposed to have two identical characters.


Option 1: My idea defends that there would be a class "Hero", and a class to every character that would extend Hero. For example, if I have 10 characters, there would be 10 classes that extend "Hero". This character class would contain all variables concerning stats and a method for each ability. We would implement a singleton pattern, to assure there is only ever one instance.


Option 2: For my friends idea, the object "Hero" would have several attributes, the more important ones being for name, stats and character class. While name and stats can be summarized as simple variables, a character class is manifested as an object of its own tied to a specific hero. In short, an instance of a character class is bound only to one "Hero", but many heroes can have a common character class. For example, Josh and John can both be "Fighters", but they don't share the same instance of the character class object; they're just similar in functionality.

A "Hero" must have a character class in order to work properly, therefore his creaion would demand his own name and the name of a character class.

This method guarantees much higher flexibility when it comes to creating heroes, since the use of generic character classes (having many "Fighters" in a party, for example) becomes possible; in fact, this idea of character classes can be expanded for use with enemy units. However, it will require a bit more processing power.

\$\endgroup\$
1
  • \$\begingroup\$ It appears your objective, at least to me, was to ask for an opinion. While an opinion can be very useful, it is not helpful within the scope of GameDevSE, and thus opinion-based questions are closed and deleted. Instead, I would specifically ask in regards to comparing option one to option two (as such, I have removed the part suggesting a recommendation for option 3). A good answer can thus be based off fact, rather than opinion; if there is a more suitable alternative, a good answer would suggest as such, anyway. \$\endgroup\$
    – Gnemlock
    Dec 27, 2016 at 5:14

1 Answer 1

6
\$\begingroup\$

We would like to know which is the best solution in computational [...]

[...] it'll require a bit more processing power.

Stop right there. This is a non issue. The scope of these character classes is so small in comparison to what you'll have to compute when managing physics and graphics that it's really not worth to take that into consideration now.

You should still profile your game once in a while and make sure the processing power goes to the right place.

Option 1

It's ok to have specialized classes that inherits a base class. You could even make your base class an interface and have all the Heroes specialized.

But please, don't use singletons. Find another way to enforce that, i.e. make the rest of your design aware of it, or make it enforce it.

Option 2

It seems to be the same design as what's in option 1, but you use composition over inheritance.

this idea of character classes can be expanded to be used on enemy units

You said it :) Go with that, and don't bother with 'processing power' now, it's quite trivial.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .