I'm working on a simple text based adventure. I curently have the game tell you the coordinates you're at, then it checks a long list of if statements for what room you're in. In each of those statements I'll need another 2, or more if statements to check for actions, and movement. I currently only have the first room done. It says I'm missing "expected Primary functions" when I compile it though. If someone could help sort it out, I'd be very pleased.
#include <iostream>
usingnamespace std;
int main ()
{
int axisx;
int axisy;
axisy = 0;
axisx= 0;
char direction [6];
char action [10];
cout << "####################################################";
cout << "\n";
cout << "# #";
cout << "\n";
cout << "# =Text Based Adventure= #";
cout << "\n";
cout << "# #";
cout << "\n";
cout << "####################################################";
cout << "\n";
cout << "\n";
cout << "You're at the coordinates "; cout << axisx; cout << ","; cout << axisy; cout << ".";
{
if(axisx == 0, axisy == 0)
cout << "\nYou're in a room. You can go east, and north. \nThere's a table next to you.\n";
cout << "What do you want to do?\nI want to ";
cin >> action;
{ if (action == "move");
cout << "Where do you want to move?\n";
cin >> direction;
}
{ if (direction == "north")
axisx+=1;
elseif (direction == "east")
axisy+=1;
}
elseif(axisx == 0, axisy == 1)
cout << "You're in a room. You can go east and south. \n There's nothing in here.\n";
elseif(axisx == 1, axisy == 0)
cout << "You're in a room. You can go west and north. \n There's a plant in the corner.\n";
elseif(axisx == 1, axisy == 1)
cout << "You're in a room. You can go south, east, and west. \n There's a corridor to your right.\n";
elseif(axisx == 2, axisy == 1)
cout << "You're in a hallway. You can go east, and west. \n The light above you is flickering.\n";
}
cin.get();
cin.get();
return 0;
}
if (axisx == 0 && axisy == 0 )
{
cout << "There's nothing around you. You can go north, and east.";
cout << "What are you going to do?\nI'm going to ";
cin >> action;
if (action == "move" )
{
cout << "Where would you like to move?";
cin >> direction;
}
if (direction == "north" )
{axisy+=1;
}
elseif (direction == "east" )
axisx+=1;
else
{cout << "Invalid input";
}
}
I'm unsure of what you're trying to do. I'm not sure of your indenting style, but I've tried to move things around a little so the individual blocks are more clear.
if (axisx == 0 && axisy == 0 )
{
cout << "There's nothing around you. You can go north, and east.";
cout << "What are you going to do?\nI'm going to ";
cin >> action;
if (action == "move" )
{
cout << "Where would you like to move?";
cin >> direction;
}
if (direction == "north" )
{
axisy+=1;
}
elseif (direction == "east" )
axisx+=1;
else
{
cout << "Invalid input";
}
}
I think what you want to do is nest the third "if" inside the second? I'm not sure...
*sigh* Well, I thank you for the re-organization of my coding, but it seems to have done nothing. I believe what is wrong, is the char action isn't being changed.
I didn't mean the re-organization to actually help directly; I'm quite a new programmer myself -- merely I was hoping it would help others to help you.
What are the symptoms of your code? If you tell me what needs fixing, maybe I can help.
Is action a char? It should be a string.
Are you getting compile-time or runtime errors; and what are they?
Yes, action is a char, so is my direction code.
No compiling errors.
I didn't know to use strings.
I shall change that right away then.
Thank you for finally clearing this up.