int main()
{
char direction;
string directionerror = "Invalid direction. Please choose again.";
cout << "Welcome to the movement tutorial." << endl
<< "You are in Area 1." << endl
<< "Go North to Area 2." << endl;
cin >> direction;
for(;;)
{
if (direction == 'n' || direction == 'N')
{
cout << "Good you made it to Area 2." << endl;
break;
}
elseif (direction == 's' || direction == 'S' || direction == 'e' || direction == 'E' || direction == 'w' || direction == 'W')
{
cout << "No you imbecile the only way out of Area 1 is to go North."
<< endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
cout << "Now, to further your experience with moving, go east to Area 3." << endl;
cin >> direction;
for (;;)
{
if (direction == 'e' || direction == 'E')
{
cout << "Congratulations! You have made it one step further to completeing your goal." << endl;
break;
}
elseif (direction == 's' || direction == 'S')
{
cout << "Opps wrong way. You are now in Area 1 again."<<endl;
cout << "Go back to Area 2 by heading North." << endl;
cin >> direction;
for (;;)
{
if (direction == 'n' || direction == 'N')
{
cout << "Good job now go to Area 3 (which is East)." << endl;
cin >> direction;
break;
}
elseif (direction == 'e' || direction == 'E' || direction == 's' || direction == 'S' || direction == 'w' || direction == 'W')
{
cout << "*Donk* Hey there is a wall there." << endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
}
elseif (direction == 'n' || direction == 'N' || direction == 'e' || direction == 'E')
{
cout << "Am I talking to just hear myself?" << endl
<< "Listen to what I am telling you and go East." << endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
cout << "Alrigt just one more room to go." << endl
<< "Now you must go South to enter Area 4 and finish the movement tutorial." << endl;
cin >> direction;
for (;;)
{
if (direction == 's' || direction == 'S')
{
cout << "Do do do doo doo doo do doo dooo! You have completed the movement tutorial!"
<< "Please open the next application to continue with the tutorials.";
break;
}
elseif (direction == 'w' || direction == 'W')
{
cout << "Now you are back tracking. You have just reentered Area2." << endl
<< "You need to head back to Area 3 (Which is East)." << endl;
cin >> direction;
if (direction == 'e' || direction == 'E')
{
cout << "Welcome back to Area 3. Now finish the tutorial by going south." << endl;
cin >> direction;
}
elseif (direction == 's' || direction == 'S')
{
cout << "I give up. You are incompetent of following orders." << endl;
cin >> direction;
for (;;)
{
if (direction == 'n' || direction == 'N')
{
cout << "Good you are finally starting to listen." << endl;
cin >> direction;
if (direction == 'e' || direction == 'E')
{
cout << "Finally you are in Area 3 again. Go south to leave me alone." << endl;
cin >> direction;
break;
}
elseif (direction == 'n' || direction == 'N' || direction == 'w' || direction == 'W' || direction == 'e' || direction == 'E')
{
cout << "Enough!!! Come back when you learn to follow orders!!!" << endl;
system("PAUSE");
return 0;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
elseif (direction == 's' || direction == 'S' || direction == 'w' || direction == 'W' || direction == 'e' || direction == 'E')
{
cout << "Dumbass." << endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
}
elseif (direction == 'n' || direction == 'N' || direction == 'w' || direction == 'W')
{
cout << "Hey there is a wall there." << endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
elseif (direction == 'n' || direction == 'N' || direction == 'e' || direction == 'E')
{
cout << "For crying out loud I told you to listen to what I tell you. Why do you insist on walking into walls!" << endl;
cin >> direction;
}
else
{
cout << directionerror << endl;
cin >> direction;
}
}
system("PAUSE");
return 0;
}
I know it is very sloppy right now but it works (for the most part). My next question is what can i do to shorten the code so it looks neater? Any help would be greatly appreciated.
Yes it helped with shortening the If statements but what I was really asking for was is there an easy way to shorten the If parameters? Or do you think it is fine as is?
Edited:
Or really to not use as many if statements all together but still keep the same effect. I can't see any way to do it but hey I am new lol.
You can simplify this quite a lot if you use game-state-management techniques. It's worth reading up on it but it can be done fairly simply here by tables which would show where you are currently in the game and then lookup where you can go from that position with appropriate messages and responses.
Thank you for the response do you happen to have a reference that you can link to me? If not that is fine I just want to have a good source to look into.
You could start with this site to get the idea of how to organise your game in a different but more manageable way. Your game will be fairly easily adapted once you get into it.