Ok now i'm getting slightly confused, I've defined a difficulty class which should change a few settings of my game.
The difficulty should determine how many rings there are in the game, set up as follows.Code:class CDifficulty{ public: CDifficulty(const char* itsSetting = "",const int nRings = 3): setting(itsSetting),numRings(nRings) {} CDifficulty(const string& itsSetting,int nRings): setting(itsSetting),numRings(nRings) {} int setDifficulty(const string itsSetting){ setting = itsSetting; if(setting == "easy"){ numRings = 3; return OK; }else if(setting == "medium"){ numRings = 5; return OK; }else if(setting == "hard"){ numRings = 7; return OK; }else return FAILED; } string getDifficulty(){ return setting; } private: string setting; int numRings; };
The user is able to choose the difficulty from the menu set up, I have the following set of actions defined for this.Code:void createRings(struct gameStruct hanoiGame){ int i; if(hanoiGame.diff->getDifficulty() == "easy"){ for(i = 3; i>0; i--) hanoiGame.A->addRing(i); }else if(hanoiGame.diff->getDifficulty() == "medium"){ for(i = 5; i>0; i--) hanoiGame.A->addRing(i); }else if(hanoiGame.diff->getDifficulty() == "hard"){ for(i = 7; i>0; i--) hanoiGame.A->addRing(i); } }
Now heres the part thats puzzling me, If I were to choose option 2 "medium" then according to my setDifficulty function the number of rings should be 5, but instead it seems to add the same number of rings as hard i.e. 7 instead of 5!!!! Am I missing something blatantly obvious???Code:void diffSelect(struct menuStruct hanoiMenus,struct gameStruct hanoiGame){ int choice = 0; cin >> choice; switch(choice){ case 1: if((hanoiGame.diff->setDifficulty("easy")) != OK){ cout << "WE MAY HAVE A PROBLEM"; break; } case 2: if((hanoiGame.diff->setDifficulty("medium")) != OK){ cout << "WE MAY HAVE A PROBLEM"; break; }else{ cout << hanoiGame.diff->getDifficulty(); //TEST PURPOSES break; } case 3: if((hanoiGame.diff->setDifficulty("hard")) != OK){ cout << "WE MAY HAVE A PROBLEM"; break; } case 4: system("CLS"); hanoiMenus.mainMenu->showMenu(); mainSelect(hanoiMenus,hanoiGame); break; default: cout << "Invalid"; } }
Ah I just noticed something, its not just with medium, its with all the options, If I choose easy it sets the number of rings to 7 aswell.
hmmm.... Curioser and Curioser said Alice as she wandered down the rabbit hole.



LinkBack URL
About LinkBacks


