All right, I'll try to explain my predicament as best as I can.
In my game, I'll have a lot of different enemies that differ in their AI, actions, graphics, stats, etc.
Anyway, the frame-work for all this is already in place with my abstract class called "Unit".
All other Enemy classes inherit from "Unit" and overload the following methods:
virtual void runAI () = 0;
virtual void runAction () = 0;
Which is why I'll need to have enemies inherit from "Unit" instead of using "Unit" as a generic class for instanciating other enemies.
My problem is this:
Different stages of the game will spawn different kinds of enemies.
However, the only ideas I have are:
'switch' statements
Unit* createEnemy (int whichStage) {
switch (whichStage) {
case 0:
return new SomeMonster;
break;
case 1:
return new SomeOtherMonster;
break;
case 2:
return new SomeOtherKindOfMonster;
break;
.
..
...
....
}
return 0;
}
My other idea is funtion pointers to a function template
typedef (Unit*)(*c_units)();
template <typename T>
Unit* createEn () {
return new T;
}
c_units arr[max_amt];
.
..
...
arr[0] = createEn<Kobold>;
arr[1] = createEn<Goblin>;
arr[2] = createEn<Isis>;
But those two ideas are a little.. hack-ish.
Is there a better way out there?
First year student of a game-programming course