You're making progress.
Here are some issues that i see:
Line 123: monster1 is local in scope to YourMonster. It goes out of scope when YourMonster exits.
Lines 124-137. You call your various get function, but don't do anything with the result. e.g. GetType() returns a string, but you don't do anything with it.
Line 144: Same problem as line 123.
Lines 145-158: Same problem as 124-137.
To pass by reference do the following:
1 2 3 4 5
|
void YourMonster (Monster & monster)
{ Monster monster;
monster.SetType("fire");//type
...etc
}
|
When you call YourMonster, you will pass an instance of Monster:
1 2
|
Monster monster1; // Define the instance
YourMonster (monster1); // Initialize the instance
|
You will also need to pass monster1 and monster2 to BattlePhase.
1 2
|
void BattlePhase (Monster & monster1, Monster Monster2)
{...}
|
Issues in BattlePhase:
Numerous places: You are trying to reference private members of Monster. e.g.
|
while (monster1.Health > 0 && monster2.Health > 0)
|
You should be calling your GetHealth functions:
|
while (monster1.GetHealth() > 0 && monster2.GetHealth() > 0)
|
Likewise, when you try to change private members of Monster, you need to all the appropriate set function.
Should be:
Your main function should declare monster1 and monster2, initialize them and then call BattlePhase.
1 2 3 4 5 6 7 8 9 10
|
int main(int argc, char *argv[])
{ Monster monster1;
Monster monster2;
YourMonster (monster1);
OpponentMonster (monster2);
BattlePhase (monster1, monster2);
cin.get();
return 0;
}
|