Needing help with my text rpg again. I have two classes that I am using to check and assign which decision a user picks. They have 2 choices (warrior or mage). If they choose mage some text is printed, if they choose warrior some different text is printed. My problem is that it only outputs text if they choose mage. Nothing is printed when they choose warrior.
The first class which assigns the information
And the class that asks the question.Code:class Player { public: string getPlayerState(int); private: string PlayerState; }; string Player::getPlayerState(int x){ if (x==1) { PlayerState = "Warrior"; } if (x==2){ PlayerState = "Mage"; } if (x != 1 && x != 2){ cout <<"Error, no PlayerState"<<endl; } return PlayerState; }
And the last bit.Code:class Game { public: void StartGame(); private: int x; //not important }; void Game::StartGame() { string urname; int typeClass; // 1 if they pick warrior, 2 if they pick mage cout <<"What is your name?"<<endl; cin >>urname; cout <<"[1] Warrior"<<endl; cout <<"[2] Mage" <<endl; cout <<"Please make a choice"<<endl; cin >>typeClass; Player PlayerInfo; // yes I declared them as friends PlayerInfo.setPName(urname); // pass's urname to setPName() PlayerInfo.getPlayerState(typeClass); PlayerInfo.callPlayerUI(); }
Once again, no text is being printed if they pick warrior. I know what the problem is, I just don't know how to fix it. PlayerState never equals "Warrior" and/or int x in getPlayerState never equals 2....even when I explicitly type in 2.Code:Player::callPlayerUI(){ if (PlayerState == "Mage") { cout <<"Something important" <<endl; } if (PlayerState == "Warrior") { cout <<"Totally different text" <<endl; } }
I think thats all thats needed to help me with this problem...let me know if I am missing something.



LinkBack URL
About LinkBacks




.