Design question for RPG | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Design question for RPG

For my game I need many different monsters and a factory class that can return random monsters. Should I create an Enum MonsterType with GOLEM, SPIDER, DRAGON and so on (would be easer to maintain) or should I use inheritance (would be difficult to return a random monster)? Monsters in my game have an Attack, Defense and HP stat and some weapons are effective against specific monster types, like fire is effective against Spiders. Thanks in advance. :))

30th Dec 2016, 10:34 PM
merkrafter
3 Answers
+ 7
You should use Enum, It's easier to work with them, especially for your case
30th Dec 2016, 10:44 PM
Filip
Filip - avatar
+ 1
If the amount of types is small sure, if not look into databases
30th Dec 2016, 10:42 PM
Sérgio Fernando Martins Borges Gutierres
0
One advantage of the inheritance could be, that classes can implement interfaces like Tameable, Venomous, Lootable or something (I do not have some yet, but maybe I'll implement such features later). Is there a solution for that problem with the enum style? The data base solution is a cool one, since you can easily add new monsters. But it's way harder to create, isn't it? Is there a simple free data base that's accessible with Java?
30th Dec 2016, 10:57 PM
merkrafter