simple text maze game
I have a programming project that i need help on. I have to create a text maze game using function calling. Following the code that I have written so far:
The problem is that I dont know how to connect the room together using function. can any one please help me with this.
Thank You
CODE:
#include <iostream>
using namespace std;
float room1(int answer);
float room2(int answer);
float room3(int answer);
float room4(int answer);
float room5(int answer);
float room6(int answer);
float room7(int answer);
float room8(int answer);
int main(void)
{
char answer;
int treasure = 0;
cout <<"You have Enter the Maze.\n"
<<"You are in the first room.\n"
<<"There are 3 exits: West, East, and South.\n"
<<"Have Fun " <> answer;
if(answer == ''W'')
{
cout << room5(answer);
}
if(answer == ''S'')
{
cout << room2(answer);
}
if(answer == ''E'')
{
cout << room1(answer);
}
return 0;
}
float room1(int answer)
{
cout <<"You have enter the first room of the maze!!!" << endl;
cout <<"There are 2 exits in this room: West and South." <<endl;
return 0;
}
float room2(int answer)
{
cout <<"You have enter the second room of the maze!!!" << endl;
cout <<"There are 2 exits in this room: South and East." <<endl;
return 0;
}
float room3(int answer)
{
cout <<"You have enter the third room of the maze!!!" << endl;
cout <<"There are 3 exits in this room: West, South and East." <<endl;
return 0;
}
float room4(int answer)
{
cout <<"You have enter the endless pit room of the maze!!!" << endl;
cout <<"There are no exits in this room." <<endl;
cout <<"You have fallen into a pit.\n"
<<"Better luck next time." <<endl;
return 0;
}
float room5(int answer)
{
cout <<"You have enter the fifth room of the maze!!!" << endl;
cout <<"There are 2 exits in this room: North and East." <<endl;
return 0;
}
float room6(int answer)
{
cout <<"You have enter the sixth room of the maze!!!" << endl;
cout <<"There are 1 exits in this room: North." <<endl;
return 0;
}
float room7(int answer)
{
cout <<"You have enter the seventh room of the maze!!!" << endl;
cout <<"There are 2 exits in this room: West and East." <<endl;
return 0;
}
float room8(int answer)
{
cout <<"You have enter the eight room of the maze!!!" << endl;
cout <<"There are 2 exits in this room: North and South." <<endl;
return 0;
}
u are doing it all wrong...
You will never finish it that way!
create a map.
eg
struct MapInfo {
int eastConnection
int westConnection
int northConnection
int southConnection
};
MapInfo Map(100);
Basically you store all your variables of the map , including connections etc in an array.
Then depending on your position you look at the array.
and see if there are any connecting rooms
like if there arnt any other rooms, make them equal null or something
You will never finish it that way!
create a map.
eg
struct MapInfo {
int eastConnection
int westConnection
int northConnection
int southConnection
};
MapInfo Map(100);
Basically you store all your variables of the map , including connections etc in an array.
Then depending on your position you look at the array.
and see if there are any connecting rooms
like if there arnt any other rooms, make them equal null or something
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement