Jump to content
• Advertisement

Archived

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

Game difficulty

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

If you intended to correct an error in the post then please contact us.

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--)
hanoiGame.A->addRing(i);
}else if(hanoiGame.diff->getDifficulty() == 5){
for(i = hanoiGame.diff->getDifficulty(); i>0; i--)
hanoiGame.A->addRing(i);
}else if(hanoiGame.diff->getDifficulty() == 7){
for(i = hanoiGame.diff->getDifficulty(); i>0; i--)
hanoiGame.A->addRing(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");
hanoiMenus.mainMenu->showMenu();
mainSelect(hanoiMenus,hanoiGame);
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 this post

Share on other sites
Advertisement
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 this post

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 this post

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 this post

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]

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
14
5. 5
• Advertisement

• 10
• 9
• 16
• 9
• 9
• Forum Statistics

• Total Topics
632594
• Total Posts
3007304

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!