I am having problems trying to output a string thats in an array. There are three member function of a class that I am trying to use to get this done.
The first is setPlayerAbilities() which assigns what abilities a player can have.
Code:
void Player::setPlayerAbilities(){
if (PlayerState == "Mage"){
string MageAbilities[14]={"Mana Burn", "Fireball", "Frostbolt", "Lightening Bolt", "Chain Lightening", "Earth Shatter",
"Mana Shield", "Mana Siphon", "FlameWalker", "WaterWalker", "Mana Shield Nova", "Mana Siphon Nova",
"FlameWalker Nova", "WaterWalker Nova" };
}
if (PlayerState == "Warrior"){
string WarrAbilities[11]={"Howl", "Sunder", "FireBlade", "IceBlade", "LighteningBlade", "Soul Siphon", "Berserk",
"Sweeping Strikes", "Hostile Charge", "Heal", "Attack" };
}
}
The second is a function that controls the menu options. It starts by giving the player 2 choices (1.CastSpell or 2. VeiwSpells). The loop I have it in is horrendous I know but it works for now. Once the player selects 1 (CastSpell), I then pass the integer cast to the member function CastSpell() (which in turn calls the function). There is a lot of text here...Ill try to cut it down as much as I can so you see more of the code, less of the text.
Code:
void Player::callPlayerUI(){
int choice = 0;
int cast;
int use;
int control; // This is used to prevent the error message after inputing a invalid choice options when viewing spells
if (PlayerState == "Mage"){
setPlayerAbilities();
while (choice >= 3 || choice < 1){
cout <<"=============================================="<<endl;
cout <<"Hit Points: test value Mana: test value|"<<endl;
cout <<"| 1.CastSpell 2.ViewSpells|"<<endl;
cout <<"=============================================="<<endl;
cin >>choice;
if (choice == 1){
cout <<"============================================="<<endl;
cout <<"|[1]ManaBurn [8]Mana Siphon |"<<endl;
cout <<"|[2]Fireball [9]FlameWalker |"<<endl;
cout <<"|[3]Frostbolt [10]WaterWalker |"<<endl;
cout <<"|[4]LBolt [11]Mana Shield Nova |"<<endl;
cout <<"|[5]ChainL [12]Mana Siphon Nova |"<<endl;
cout <<"|[6]Earth shatter [13]FlameWalker Nova |"<<endl;
cout <<"|[7]Mana Shield [14]WaterWalker Nova |"<<endl;
cout <<"============================================="<<endl;
cin >>cast;
CastSpell(cast);
}
if (choice == 2){
cout <<"+++++++++++++++++LIST SPELLS+++++++++++++++++++++++++++++"<<endl;
cout <<"+++++++++++++++++++++++++++END SPELLS+++++++++++++++++++++++++"<<endl;
choice = 0;
control = 1;
}
if (choice > 2 || choice <1 && control != 1){
cout <<"Error, try again"<<endl;
choice = 0;
}
}
}
/* YOU CAN IGNORE EVERYTHING FROM HERE DOWN */
/* =+!+!+!+!+!+!+!+ Start Warrior Section +!+!+!+!+!+!+!+ */
if (PlayerState == "Warrior") {
while (choice >= 3 || choice < 1){
cout <<"=============================================="<<endl;
cout <<"| Hit Points: test value |"<<endl;
cout <<"| 1.UseAbility 2.ViewAbilities|"<<endl;
cout <<"=============================================="<<endl;
cin >>choice;
if (choice == 1){
cout <<"============================================="<<endl;
cout <<"|[1]Attack [7]Soul Siphon |"<<endl;
cout <<"|[2]Sunder [8]Berserk |"<<endl;
cout <<"|[3]Fire Blade [9]Sweeping Strikes |"<<endl;
cout <<"|[4]Ice Blade [10]Hostile Charge |"<<endl;
cout <<"|[5]Lightening Blade [11]Heal |"<<endl;
cout <<"|[6]Howl |"<<endl;
cout <<"============================================="<<endl;
cin >>use;
}
if (choice == 2) {
cout <<"\n\n!+!+!+!+!+!+!+!+!+!+!+!+Abilities+!+!+!+!+!+!+!+!+!+!+!+!+"<<endl;
choice = 0;
control = 1;
}
if (choice > 2 || choice <1 && control != 1){
cout <<"Error, try again"<<endl;
choice = 0;
}
}
if (PlayerState != "Warrior" && PlayerState != "Mage"){
cout <<"Error, no PlayerState!!!!"<<endl;
}
}
}
The last is the CastSpell() member function that is supposed to receive the integer (cast) from the previous function and output an element of the array (cast - 1 since array elements start from 0).
Code:
void Player::CastSpell(int cast){
setPlayerAbilities();
cout <<MageAbilities[cast-1];
}
However, nothing is printed or output. I've changed the cout message to say "You have casted " <<MageAbilities[cast-1] <<", grats"...but it prints everything but the array element.