Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
void to() //first territory
{
cout<<"You can move south or east. type h for help.";
}
int main(int argc, char *argv[])
{
char namen[100];
int initial;
int strength;
int agility;
int defense;
char command;
char direction;
char n,s,e,w;
int xco=0;
int yco=0;
cout<<"What would you like to do?";
cout<<"\n1.New game\n2.Load game\n3.Exit\n"; //Menu
cin>>initial;
switch(initial){ //menu switch statment
case 1:
cout<<"Enter your name:"; //ask for name
cin>>namen;
cout<<namen<<" is it. Alright then\n";
cout<<"Enter your strength agility and defense again(must=20):\n";
cin>>strength>>agility>>defense;
while(strength+agility+defense!=20){ //loop if str ag and def not 20
cout<<"Enter strength, agility, and defense(must=20):";
cin>>strength>>agility>>defense;
}
break;
case 2: //loading game
cout<<"Not availiable yet";
system("PAUSE");
break;
case 3: //exit
return 0;
break;
default:
cout<<"error"; //default
system("PAUSE");
}
//intro
cout<<" Welcome to naushmien\n\n*Dramatic Music*\n\n";
to();
for(int loop=0;loop<100;loop++){ //main loop
cin>>command;
switch(command){
case 'm': //movement
cout<<"which way would you like to move?";
cin.get();
cin>>direction;
if (direction=n)
yco++;
cout<<"Y="<<yco<<" X="<<xco;
if (direction=s)
yco--;
cout<<"Y="<<yco<<" X="<<xco;
if (direction=e)
xco++;
cout<<"Y="<<yco<<" X="<<xco;
if (direction=w)
xco--;
cout<<"Y="<<yco<<" X="<<xco;
break;
default:
cout<<"messed";
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
How do I put all of the stuff in red in a function? or how can I do something to it so the switch changes for each region your in?