Passed on from beginner forum under recommendation of another user
for the past week or two I've been rebuilding a small rpg that i wrote in visual basic up in c++, coming across some issues such as inventory and others that thankfully i've been able to pull through, however i see an issue that will arise soon when i come to recreate my battle system due to the way c++ requires prior notice of classes when calling methods between them.
My, hero class atm was created in a seperate function contained within my system class (just a large container to store everything) which is then passed by reference into my main menu
1 2 3 4 5 6 7 8 9 10 11 12
|
//creates the player object with the code defined for an arcanist
Player *hero;
hero = new Arcanist;
F_menu(hero);
void F_menu(Player *character)
{
//menu stuff
};
|
Our arcanist being an inherited job class and so on, From here i was hoping to pass our Hero along the functions where needed until we reach our battle function, were by a similar method to our hero creation, we would create the enemy we wanted and then pass them both into the battle function
1 2 3 4 5 6 7 8 9
|
//Example:
void F_enemy_creation (Player *character) {
monster *enemy;
enemy = new (type of monster);
F_battle(character, enemy);
}
|
Here is were i can see our issue arising, both our hero and monster is now stored in our battle function for the moment, then by following a turn based theme, our function would call our players battle method ( with reference to our monster) and the our monsters battle method ( with reference to our layer)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
//example:
void F_battle(Player *character , monster *enemy)
{
our loop {
character-> player_turn(enemy);
enemy-> monster_turn(character);
//until either dies
}
//end battle stuff
}
|
due to as i previously said above and you all well know, c++ will throw a wobbly here as I have written out all our classes above, (.h and .cpp files didnt like me) therefore depending on which class is declared above the other, one of them will throw an unknown identifier error.
potentially i could write a third man function in between them which takes the input from one and outputs it to the other but to me, it seems like it would end up being more of a hassle when attempting to pass over things like status effects, our ai for the monsters that would select an ability depending on what our remaining health is.
overall what i'm asking help for in is that is there a way to break away the top
down reading of c++ to allow classes to identify with those, below and above,
than you for your help