Hi there,
I'm trying to teach a few students how to create a text adventure game. In the past, I've generally gone about the route of using nested if-statements because it seems a bit easier to visualize. Here's what one has done in the past, and ignore the crazy code-formatting problems:
int main()
{
cout << "The Bishop\n\n";
cout << "Press 'x' to begin.\n\n";
bool door1Loop = false;
cin >> start;
if(start == 'x')
{
wakingUp();
cin >> answer;
if(answer == 'a') //
{
investigateDarkOnes();
cin >> answer;
if(answer == 'a')
{
doSomething();
}
if(answer == 'b')
{
thinking();
cin >> answer;
if(answer == 'a')
doSomething();
}
}
else if(answer == 'b')
{
doSomething();
}
else if(answer == 'c')
{
panicAttack();
cin >> answer;
if(answer == 'a')
{
sobbingMess();
}
if(answer == 'b')
{
doSomething();
}
}
system("pause");
}
}
void doSomething()
{ bool beast1Loop = false;
investigateDoor1();
cin >> answer;
if(answer == 'a')
{
thinking();
cin >> answer;
if(answer == 'a')
{
beast1();
cin >> answer;
if(answer == 'a')
{
beast1Smack();
cin >> answer;
if(answer == 'a')
{
meetArchdemon();
}
else if(answer == 'b')
{
fallToYourDeath();
system("exit");
}
}
else if(answer == 'b')
{
beast1Negotiate();
}
else if(answer == 'c')
{
beast1Bolt();
}
}
}
if(answer == 'b')
{
panicAttack();
cin >> answer;
if(answer == 'a')
{
sobbingMess();
}
if(answer == 'b')
{
doSomething();
}
}
if(answer == 'c')
{
beast1();
cin >> answer;
if(answer == 'a')
{
beast1Smack();
cin >> answer;
if(answer == 'a')
{
meetArchdemon();
}
if(answer == 'b')
{
fallToYourDeath();
system("exit");
}
}
else if(answer == 'b')
{
beast1Negotiate();
}
else if(answer == 'c')
{
beast1Bolt();
}
}
}
However, another instructor has also suggested using a multidimensional array, such as a 2D Array to have more of a grid structure in a text game. Let me know if you need clarification, but I was wondering if any of you have any ideas on which would be more efficient, and which would bring about the concepts of programming easier to students with less than a week of experience under their belts! If it is 2D arrays, do you think you could explain it a bit, I'm having trouble wrapping my head around it. Thanks for the help!