I am making a pokemon based text game. I gave the user of picking from three pokemon at the beginning. If the user chooses, lets say, Charmander (an object), then I want the rest of the program to use this object.
The problem is I have 2 more objects(the other 2 starting pokemon), and every time I call a method from the class, I am having to say (if user chose 1, use the first object. if user chose 2, use the second object. if user chose 3, use the third object).
How can I get the rest of the program to just use the user chosen object?
Here is a piece of main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
cout << "Would you like:" << endl << "1) Bulbasour (A powerful grass type)" << endl << "2) Charmander (A ruthless fire type)" << endl << "3) Squirttle (A ferocious water type)" << endl << endl;
cout << "Enter which Pokemon you want(1, 2, or 3): ";
cin >> choice;
if (choice == 1)
{
cout << endl << endl << "You chose Bulbasour!! Great choice! What would you like his name to be: ";
cin >> name;
Bulbasour.SetName(name);
cout << endl << endl << endl << endl<< "You named your Bulbasour " << Bulbasour.GetName() <<"! " << Bulbasour.GetName() << " is level " << Bulbasour.GetLevel() << ", has an attack of " << Bulbasour.GetAttack() << " and a health of " << Bulbasour.GetHealth();
}
else if (choice == 2)
{
cout << endl << endl << "You chose Charmander!! Great choice! What would you like his name to be: ";
cin >> name;
Charmander.SetName(name);
cout << endl << endl << endl << endl<< "You named your Charmander " << Charmander.GetName() <<"! " << Charmander.GetName() << " is level " << Charmander.GetLevel() << ", has an attack of " << Charmander.GetAttack() << " and a health of " << Charmander.GetHealth();
}
else if (choice == 3)
{
cout << endl << endl << "You chose Squirttle!! Great choice! What would you like his name to be: ";
cin >> name;
Squirttle.SetName(name);
cout << endl << endl << endl << endl<< "You named your Squirttle " << Squirttle.GetName() <<"! " << Squirttle.GetName() << " is level " << Squirttle.GetLevel() << ", has an attack of " << Squirttle.GetAttack() << " and a health of " << Squirttle.GetHealth();
}
|
skipping a few lines
1 2 3 4 5 6
|
cout << endl << endl << "Here you will see your health bars. After each turn, the status of the health bar will be updated." << endl << endl << endl;
cout << " " << name << " Bulbasour Charmander" << endl << " " << Bulbasour.GetHealthBar() << " " << Charmander.GetHealthBar(); //this is the line I am struggling with. I want to say "userchoice.GetHealthBar()"
cout << "When your Pokemon gets attacked, his health goes down, like this." << endl << endl << endl;
|
Also, I am trying to be able to replace a character from a string in the constructor. How can I do this?(aka something like userchoice.replace.GetHealthBar(9,10,' ') I know that isn't it, but something like that>)