Let's say I'm programming a small RPG game. I have several instances of the Enemy class. They share common properties (they all have a name, an amount of life/strength/dexterity/a weapon, etc), but all these values are different for each enemy. I'm looking for an appropriate way to initiate these instances.
I'm new to programming and Java, so I'm looking for the best practice to properly organize information in my project.
My first idea was, when creating the instance of the game, to instantiate all the occurrences of the required enemies in the constructor of the Game object, and put everything in a vector. Something like Enemy e1 = new Enemy("goblin", 10, 14, 10, a_weapon, ...)
. But this can get very tedious if there are a lot of enemies, a lot of properties, it gets very hard to maintain, and I don't find very "logical" to put that in the constructor of the Game object.
I just discovered XML files, and it looks promising. So maybe I could put everything in an XML file, and parse it in my program to extract the data and create all the enemies from it. It could look like
<Enemies>
<Enemy>
<Name>"Goblin"</Name>
<Strength>20</Strength>
<Agility>20</Agility>
<Life>20</Life>
<Weapon>
<Name>"Sword"</Name>
<Damage>3</Damage>
</Weapon>
<Enemy>
<Enemy>
...
</Enemy>
</Enemies>
I guess I could write a function that parses the XML file, extract the data and create the vector of enemies automatically, so I just have to edit the XML file to modify the values.
However, and before I dig into this solution, I want to ask if this is the preferred method, and if not, what would be the most common way of managing this kind of situation.