Sign in to follow this  

my first rpg

This topic is 3773 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

i have started my first rpg but now i'm stuck maybe someone can help me please the problem is when you pick the option to go to the inn it dosent instead it leaves town and then it gose to the inn after you pic the option for exploring...i am wrighting in c++ and my compiler is dev_c++ here is the code
#include <iostream>
using namespace std;

int main()

{
    //intro and picking a name
      cout <<"\twelcome to my first game!\n";
      char username [100];
      cout <<"enter user name: ";
      cin >>username;
      cout <<"Hello, "<<username<<"!\n\n";
      //picking your race
      cout<<"please pic your race: \n";
      cout<<"1 - human\n";
      cout<<"2 - orc\n";
      cout<<"3 - elf\n";
      cout<<"4 - dwarf\n";
      cout<<"5 - gnome\n";
      int pickRace;
      cout<<"pick your race: ";
      cin >>pickRace;
      
      switch (pickRace)
      
      {
             case 1:
                  cout <<"you picked the human race.\n";
                  break;
             case 2:
                  cout <<"you picked the orc race.\n";
                  break;
             case 3:
                  cout <<"you picked the elf race.\n";
                  break;
             case 4:
                  cout <<"you picked the dwarf race.\n";
                  break;
             case 5:
                  cout <<"you picked the gnome race.\n";
                  break;
             default:
                     cout <<"error - invalid input; only 1,2,3,4, or 5 allowed.\n";
                     }

//picking your charicters class                     


int charclass;
    cout <<"\nPick your charicter class: \n";
    cout <<"1 - Fighter\n";
    cout <<"2 - Mage\n";
    cout <<"3 - Warlock\n";
    cout <<"4 - Priest\n";

    cout <<"Pick your charicter class: ";
    cin >>charclass;
    
    switch (charclass)
    {
           case 1:
                cout <<"You picked Fighter.\n\n";
                break;
           case 2:
                cout <<"You picked Mage.\n\n";
                break;
           case 3:
                cout <<"You picked Warlock.\n\n";
                break;
           case 4:
                cout <<"You picked Priest.\n\n";
                break;
           default:
                   cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
    }


    /*Now the game begins...This is the first town you start in and where you 
    can go in the town... This is where the problem is when you pick the option to go to the inn it dosent it leaves town instead and then it gose to the inn after you pic the option for exploring*/

   
int town1;
    cout <<"\nwhat would you like to do: \n";
    cout <<"1 - leave town\n";
    cout <<"2 - go to inn\n";
    cout <<"3 - go to blacksmith\n";
    cout <<"4 - go to shop\n";

    cout <<"what would u like to do: ";
    cin >>town1;
    
    switch (town1)
    {
           case 1:
                cout <<"u picked leave town.\n\n";
                break;
           case 2:
                cout <<"You picked go to inn.\n\n";
                break;
           case 3:
                cout <<"You picked go to blacksmith.\n\n";
                break;
           case 4:
                cout <<"You picked shop.\n\n";
                break;
           default:
                   cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
    }
    

    //option 1 leaving the town and exploring the surrondings
    //and the directions you can go


 int leavetown;
    cout <<"\nwhere would you like to go: \n";
    cout <<"1 -north\n";
    cout <<"2 -east\n";
    cout <<"3 -south\n";
    cout <<"4 -west\n";

    cout <<"where would you like to go: ";
    cin >>leavetown;
    
    switch (leavetown)
    {
           case 1:
                cout <<"\nyou picked to go north\n";
                break;
           case 2:
                cout <<"\nyou picked to go east\n";
                break;
           case 3:
                cout <<"\nyou picked to go south\n";
                break;
           case 4:
                cout <<"\nyou picked to go west\n";
                break;
           default:
                   cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
    }


    //this is option 2 the inn and what you can do here

    
 int inn;
    cout <<"\nwelcome to the inn. What would you like to do: \n";
    cout <<"1 - rest\n";
    cout <<"2 - eat\n";
    cout <<"3 - buy food\n";
    cout <<"4 - leave\n";

    cout <<"welcome to the inn. What would you like to do: ";
    cin >>inn;
    
    switch (inn)
    {
           case 1:
                cout <<"\nrest\n";
                break;
           case 2:
                cout <<"\neat\n";
                break;
           case 3:
                cout <<"\nbuy food\n";
                break;
           case 4:
                cout <<"\nleave\n";
                break;
           default:
                   cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
    }
 
  system("PAUSE");
    return 1;
}


so what am i doing wrong...any advice is helpfull. [Edited by - Emmanuel Deloget on August 13, 2007 9:40:53 AM]

Share this post


Link to post
Share on other sites
First, you don't say what your problem is.

Second, from what I understand, Dev-C++ is no longer supported, so pick up a more modern IDE like Code::Blocks or MSVS2005C++EE if you want a free one.

Third, I'm not a C++ programmer.

Fourth, use source tags to enclose your source code. I'll go ahead and do it for future posters trying to respond.


#include <iostream>
using namespace std;

int main()
{
//intro and picking a name
cout <<"\twelcome to my first game!\n";
char username [100];
cout <<"enter user name: ";
cin >>username;
cout <<"Hello, "<<username<<"!\n\n";
//picking your race
cout<<"please pic your race: \n";
cout<<"1 - human\n";
cout<<"2 - orc\n";
cout<<"3 - elf\n";
cout<<"4 - dwarf\n";
cout<<"5 - gnome\n";
int pickRace;
cout<<"pick your race: ";
cin >>pickRace;

switch (pickRace)
{
case 1:
cout <<"you picked the human race.\n";
break;
case 2:
cout <<"you picked the orc race.\n";
break;
case 3:
cout <<"you picked the elf race.\n";
break;
case 4:
cout <<"you picked the dwarf race.\n";
break;
case 5:
cout <<"you picked the gnome race.\n";
break;
default:
cout <<"error - invalid input; only 1,2,3,4, or 5 allowed.\n";
}

//picking your charicters class


int charclass;
cout <<"\nPick your charicter class: \n";
cout <<"1 - Fighter\n";
cout <<"2 - Mage\n";
cout <<"3 - Warlock\n";
cout <<"4 - Priest\n";

cout <<"Pick your charicter class: ";
cin >>charclass;

switch (charclass)
{
case 1:
cout <<"You picked Fighter.\n\n";
break;
case 2:
cout <<"You picked Mage.\n\n";
break;
case 3:
cout <<"You picked Warlock.\n\n";
break;
case 4:
cout <<"You picked Priest.\n\n";
break;
default:
cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
}


/*Now the game begins...This is the first town you start in and where you
can go in the town... This is where the problem is when you pick the option to go to the inn it dosent it leaves town instead and then it gose to the inn after you pic the option for exploring*/



int town1;
cout <<"\nwhat would you like to do: \n";
cout <<"1 - leave town\n";
cout <<"2 - go to inn\n";
cout <<"3 - go to blacksmith\n";
cout <<"4 - go to shop\n";

cout <<"what would u like to do: ";
cin >>town1;

switch (town1)
{
case 1:
cout <<"u picked leave town.\n\n";
break;
case 2:
cout <<"You picked go to inn.\n\n";
break;
case 3:
cout <<"You picked go to blacksmith.\n\n";
break;
case 4:
cout <<"You picked shop.\n\n";
break;
default:
cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
}


//option 1 leaving the town and exploring the surrondings
//and the directions you can go


int leavetown;
cout <<"\nwhere would you like to go: \n";
cout <<"1 -north\n";
cout <<"2 -east\n";
cout <<"3 -south\n";
cout <<"4 -west\n";

cout <<"where would you like to go: ";
cin >>leavetown;

switch (leavetown)
{
case 1:
cout <<"\nyou picked to go north\n";
break;
case 2:
cout <<"\nyou picked to go east\n";
break;
case 3:
cout <<"\nyou picked to go south\n";
break;
case 4:
cout <<"\nyou picked to go west\n";
break;
default:
cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
}


//this is option 2 the inn and what you can do here


int inn;
cout <<"\nwelcome to the inn. What would you like to do: \n";
cout <<"1 - rest\n";
cout <<"2 - eat\n";
cout <<"3 - buy food\n";
cout <<"4 - leave\n";

cout <<"welcome to the inn. What would you like to do: ";
cin >>inn;

switch (inn)
{
case 1:
cout <<"\nrest\n";
break;
case 2:
cout <<"\neat\n";
break;
case 3:
cout <<"\nbuy food\n";
break;
case 4:
cout <<"\nleave\n";
break;
default:
cout <<"Error - Invalid input; only 1,2,3 or 4 allowed.\n";
}

system("PAUSE");
return 1;
}





Good luck.

[edit]

Another thing I noticed is that you're very inconsistent. Sometimes you declare the integer that will hold the user's choice before the switch statement, and sometimes you declare it after the switch. There are other things, too, but that's just an example. Consistency = good.

[/edit]
[edit 2]

After reading your code, I saw where you described the problem. In the future, you should describe the problem before you post the source.

Now, the reason you exit the town before you go to the inn is because you're not using anything to tell the program that it needs to go to the inn. You just tell the user he goes to the inn. You need to write a function or something that makes the user go to the inn. Not sure if C++ has it, but AVOID THE GOTO STATEMENT. It has its (rare) uses, but it's generally the devil.

Your best bet is to totally refactor your code and arrange it into classes et al. That's the benefit of OO languages like C++.

You should also use loops.
[/edit]

Share this post


Link to post
Share on other sites
What I am having problems grasping is how you go from picking a direction(Inn, Leave Town, Blacksmith, etc.) to the actual actions themselves? It would appear that the switch statements run in a row, so that LeaveTown will always be first and Inn will always be second and so forth.

Maybe you should use an if statement, for example (pseudo-code):

Switch Statement
CHOICE ONE: Leave Town
CHOICE TWO: Inn
cin userschoice

if userschoice == 1
LeaveTown()
elif userschoice == 2
Inn()
else
'No silly, you can't go to' userschoice

Share this post


Link to post
Share on other sites
Quote:
Original post by Gallivan
Maybe you should use an if statement, for example (pseudo-code):

Switch Statement
CHOICE ONE: Leave Town
CHOICE TWO: Inn
cin userschoice

if userschoice == 1
LeaveTown()
elif userschoice == 2
Inn()
else
'No silly, you can't go to' userschoice


so where would i put it in the code...i just stared to learning this stuff on friday so bare with me for a bit

Share this post


Link to post
Share on other sites
Ideally you'll probably want your game to look like this:

# Functions go here, this is where you describe all your locations and what will
# happen if you call them.

Town()
cout Welcome to the town.
cout etc.

Inn()
cout Welcome to the inn.
cout etc.

# You should also define a menu here. This will allow you to revert back to the
# menu at any time.

Menu()
switch
choices

# Then you'll want to start your game. Up to now you've just defined things
# which won't actually show up unless you call them. To start your game you
# probably want an intro and then your menu to come up.

cout Welcome to my game. I hope you have fun!
Menu()

# This (besides for stating variables) is pretty much it. Once you call your
# menu it will go up to where you defined what your menu should do and run that.
# From inside the menu you'll run the if statement, where if user choice == 1
# then Town() or Inn() or whatever.

--

In short:

Menu()
Town()
Inn()
Woodlands()
Forest()

cout introduction
Menu()

Share this post


Link to post
Share on other sites
Gallivan is correct. However, that also doesn't touch on OOD/OOP, which you should learn about. I can't explain OOD/OOP, and I can't recommend a resource for it. Just Google it. It's a difficult concept for some. I'm still trying to grasp the more advanced aspects.

The best way to learn is to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by draco_18_69
oh...Any ideas on what i should use???


A C++ compiler and IDE? If you're using the full version of MSVS 2005, this is included (assuming you didn't choose not to install it at install time).

If you're using the free Express Edition, then don't worry, you just clicked the wrong link. It's available here (direct link to net install exe at Microsoft).

Share this post


Link to post
Share on other sites
Hiya, just been looking at your code. What you need to do is set up a function for each of the area's that you have. Then when you do the Switch Statement for what you would like to do, perform this function before the break statement.

Also just wondering what the point is of picking a race or class in this game as I cannot see it having any advantage. If you want to do this, you will probably have to create a class for the player, that has private members for a set of stats. That way the Priest will have different stats to say strength than the fighter.

Share this post


Link to post
Share on other sites

This topic is 3773 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this