I am in a c++ programming class in my High School, and I am having some trouble with the final I was assigned. We were assigned to make a video game, so I decided to make a text adventure. My code is basically a bunch of if statements telling the program what to display when a user moves from room to room by typing in a different direction. I have 2 "worlds" with 6 rooms to each. The program works for the most part, but after typing in directions 3 or 4 times or repeating a direction (I'm still having trouble figuring out what exactly is the determining factor), the program terminates. I'm not sure if there is a hidden function out there to help me, but I am pretty inexperienced in c++ coding (I only take the course for 18 weeks), so if this could be answered in the simplest terms as possible, that would be great, but if there is some complicated procedure I have to follow, I can. This is the entire code I have so far: (the ShellExecute function is a little Visual Basic map I am experimenting with and also the dialogue is very minimal; I'm planning on polishing the dialogue and room descriptions later. I just wanted to get the code working first)
//Final
#include <iostream.h>
#include <string.h>
#include <windows.h>
#include <stdio.h>
#include <fstream.h>
//map code
void showMap();
//code to begin world 1
void startWorld1();
// code to begin world 2
void startWorld2();
//Intro code
void main()
{
char start[6] = "";
cout << "Dungeon Master v1.1" << endl;
cout << " " << endl;
cout << "Welcome to the Dungeon Master video game" << endl;
cout << " " << endl;
cout << "How to play: " << endl;
cout << "To move, type in North(Up), South(Down), East(Right), West(Left)" << endl;
cout << "Type 'map' at any time to view a visual map to view your location" << endl;
cout << " " << endl;
cout << "Type 'world1' to begin World 1 or 'world2' to begin World 2 (password required)" << endl;
cin >> start;
if(stricmp(start, "world1") == 0)
{
startWorld1();
}
if(stricmp(start, "world2") == 0)
{
startWorld2();
}
}
//Code to launch Visual Basic map
void showMap()
{
HWND handle1;
ShellExecute(handle1, "open", "H:\\test.exe", NULL, NULL, SW_SHOWNORMAL);
}
//Code for World 1
void startWorld1()
{
char direction[5] = "";
int room;
char item[10] = "";
int item1;
int item2;
int item3;
int item4;
int item5;
int item6;
cout << "*****************************************************************************" << endl;
cout << "Type 'yes' to enter the dungeon or 'no' to chicken out and flee the dungeon: ";
cin >> direction;
if(stricmp(direction, "yes") == 0)
{
room = 1;
cout << "You are in room A1" << endl;
cout << " " << endl;
cout << "Your vision returns as you slowly open your eyes. You don't remember much" << endl;
cout << "except for being kidnapped on the street. You come to your senses as you" << endl;
cout << "realize that you are in a damp, dark dungeon. You see a door behind" << endl;
cout << "you and a door to the right of you." << endl;
cout << " " << endl;
cout << "Available movements: South and East" << endl;
cout << " " << endl;
cout << "What will you do: ";
cin >> direction;
}
if(stricmp(direction, "no") == 0)
{
cout << "Session terminated" << endl;
}
if((room == 1) && (stricmp(direction, "North") == 0))
{
room = 1;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 1) && (stricmp(direction, "East") == 0))
{
room = 2;
cout << "You are in room 2" << endl;
cout << "Available movements: 'West', 'East', and 'South'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 1) && (stricmp(direction, "South") == 0))
{
room = 4;
cout << "You are in room 4" << endl;
cout << "Available movements: 'North' and 'East'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 1) && (stricmp(direction, "West") == 0))
{
room = 1;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 2) && (stricmp(direction, "North") == 0))
{
room = 2;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 2) && (stricmp(direction, "East") == 0))
{
room = 3;
cout << "You are in room 3" << endl;
cout << "Available movements: 'South' and 'West'" << endl;
cout << "What will you do : ";
cin >> direction;
cout << " " << endl;
}
if((room == 2) && (stricmp(direction, "South") == 0))
{
room = 5;
cout << "You are in room 5" << endl;
cout << "Available movements: 'North', 'East', and 'West'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 2) && (stricmp(direction, "West") == 0))
{
room = 1;
cout << "You are in room 1" << endl;
cout << "Available movements: 'South' and 'East'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 3) && (stricmp(direction, "North") == 0))
{
room = 3;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 3) && (stricmp(direction, "East") == 0))
{
room = 3;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 3) && (stricmp(direction, "South") == 0))
{
room = 6;
cout << "You are in room 6" << endl;
cout << "Available movements: 'North' and 'West'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 3) && (stricmp(direction, "West") == 0))
{
room = 2;
cout << "You are in room 2" << endl;
cout << "Available movements: 'East', 'West' and 'South'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 4) && (stricmp(direction, "North") == 0))
{
room = 1;
cout << "You are in room 1" << endl;
cout << "Available movements: 'South' and 'East'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 4) && (stricmp(direction, "East") == 0))
{
room = 5;
cout << "You are in room 5" << endl;
cout << "Available movements: 'North', 'East' and 'West'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 4) && (stricmp(direction, "South") == 0))
{
room = 4;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 4) && (stricmp(direction, "West") == 0))
{
room = 4;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 5) && (stricmp(direction, "North") == 0))
{
room = 2;
cout << "You are in room 2" << endl;
cout << "Available movements: 'East' and 'West'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 5) && (stricmp(direction, "East") == 0))
{
room = 6;
cout << "You are in room 6" << endl;
cout << "Available movements: 'West' and 'North'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 5) && (stricmp(direction, "South") == 0))
{
room = 5;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 5) && (stricmp(direction, "West") == 0))
{
room = 4;
cout << "You are in room 4" << endl;
cout << "Available movements: 'North' and 'East'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 6) && (stricmp(direction, "North") == 0))
{
room = 3;
cout << "You are in room 3" << endl;
cout << "Available movements: 'West' and 'South'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 6) && (stricmp(direction, "East") == 0))
{
room = 6;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 6) && (stricmp(direction, "South") == 0))
{
room = 6;
cout << "Invalid command" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
if((room == 6) && (stricmp(direction, "West") == 0))
{
room = 5;
cout << "You are in room 5" << endl;
cout << "Available movements: 'North', 'East' and 'West'" << endl;
cout << "What will you do: ";
cin >> direction;
cout << " " << endl;
}
}
void startWorld2()
{
}