#### Archived

This topic is now archived and is closed to further replies.

# Game difficulty

This topic is 5838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok now i''m getting slightly confused, I''ve defined a difficulty class which should change a few settings of my game.
  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;
}
int getDifficulty(){ return numRings; }
private:
string setting;
int numRings;
};  
The difficulty should determine how many rings there are in the game, set up as follows.
  void createRings(struct gameStruct hanoiGame){
int i;
if(hanoiGame.diff->getDifficulty() == 3){
for(i = hanoiGame.diff->getDifficulty(); i>0; i--)
}else if(hanoiGame.diff->getDifficulty() == 5){
for(i = hanoiGame.diff->getDifficulty(); i>0; i--)
}else if(hanoiGame.diff->getDifficulty() == 7){
for(i = hanoiGame.diff->getDifficulty(); i>0; i--)
}
}  
The user is able to choose the difficulty from the menu set up, I have the following set of actions defined for this.
  void diffSelect(struct menuStruct hanoiMenus,struct gameStruct hanoiGame){
int choice = 0;

cin >> choice;

switch(choice){
case 1:
hanoiGame.diff->setDifficulty("easy");
case 2:
hanoiGame.diff->setDifficulty("medium");
case 3:
hanoiGame.diff->setDifficulty("hard");
case 4:
system("CLS");
break;
default:
cout << "Invalid";
}
}  
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???

##### Share on other sites
Wow, I have no idea! It looks like its about time you do some debugging. Try putting COUT around the code dislplaying the value of the rings so you can see where your going wrong, or you can just print data to the debug screen, good luck!

##### Share on other sites
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.

##### Share on other sites
DO NOT forget to put break in the switch.
Example:

switch(x)
{
case 1 : printf("bla bla bla"); break; <---- HERE
}

Bye.

##### Share on other sites
Problem is if I do the break then the program will exit!!!

EDIT: Never mind I was being dumb with that last comment, I figured it out

[edited by - pdstatha on June 30, 2002 4:52:40 PM]

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 11
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999989
×