Hello,
I’m just now getting started in OOP after doing everything procedurally in a variety of languages since QBASIC. I’m working through the concepts explained in the Java book I’m reading but instead of creating the pointless business apps they want me to do, I’m trying to make simple text-based games.
So I’m writing a cage-fighting app right now, where I define an NPC class, create two identical NPC objects, and then have them hack away at each other to see whose hitpoints drop below 0 first. More of a simulation than a game.
Right now I’d like to modify it so that there are certain types of NPC. For instance humans, orcs, elves, etc, all with different stats. The next step after that will be creating an arbitrary number of NPCs and have all of them fight each other at the same time. So what I do now needs to be scalable.
What’s the ideal way of going about this? I was thinking about extending the NPC class to include base stats, then overriding them with race-specific values via extension. The only problem is, right now I’ve got it hardcoded so that “nextEnemy = new Fighter();” but I don’t know (yet) how to refer to the object that extends Fighter as anything other than Fighter (i.e. if it’s an Orc, it’s already hardcoded to refer to “new Fighter()”, not “new Orc();”).
Am I supposed to create some kind of container object and use a loop to just have the player attack anything contained within?
I’d appreciate any direction you all could give me as I try to get better at this.
Thanks!