1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
#include <string>
class Room
{
private:
public:
std::string name;
int index;
std::string text;
int openExits;
int nextRoom[10];
bool pathVisible[10];
};
enum TheRooms {
ROOM_START,
ROOM_CORRIDOR,
ROOM_W_CELL,
ROOM_E_CELL,
ROOM_STAIRS,
ROOM_HALL,
ROOM_COURTYARD, };
// create the room data
Room world[] =
{
{// Room 0
"Prison Cell",
ROOM_START,
"You are in a Prison Cell",
1,
{ROOM_CORRIDOR},
{true}
},
{ // Room 1
"The Corridor",
ROOM_CORRIDOR,
"\nYou are in the corridor.\n",
4,
{ROOM_W_CELL, ROOM_E_CELL, ROOM_STAIRS, ROOM_START},
{false, true, true, true}
},
{ // Room 2
"The West Cell",
ROOM_W_CELL,
"The West Cell.\n",
1,
{ROOM_CORRIDOR},
{true}
},
{ // Room 3
"The East Cell",
ROOM_E_CELL,
"The East Cell.\n",
1,
{ ROOM_CORRIDOR },
{true}
},
{ // Room 4
"The Stairs",
ROOM_STAIRS,
"You are on the stairs leading up to the Courtyard.\n",
2,
{ROOM_HALL, ROOM_CORRIDOR},
{true, true}
},
{ // Room 5
"The Asylum Hall",
ROOM_HALL,
"You are in The Great Hall of The Asylum\n",
2,
{ROOM_COURTYARD, ROOM_STAIRS},
{true, true}
},
{
// Room 6
"The Courtyard",
ROOM_COURTYARD,
"You are in the Asylum Courtyard\n",
1,
{ROOM_HALL},
{true}
}
};
void clearScreen();
int doRoom(int room);
int main()
{
bool alive = true;
while (alive)
{
int currentRoom = ROOM_START;
while (currentRoom >= 0)
{
currentRoom = doRoom(currentRoom);
}
}
std::cout << "I do believe you just died.";
return 0;
}
void clearScreen()
{
std::cout << std::endl;
system("cls");
}
int doRoom(int room)
{
std::cout << world[room].text;
if (world[room].openExits < 0)
{
return -1;
}
bool valid = false;
int selection = 0;
while (!valid)
{
//clearScreen();
std::cout << "\nYour choices are:\n\n";
for (int i = 0; i < world[room].openExits; ++i)
{
std::cout << i + 1 << ". " << world[world[room].nextRoom[i]].name << "\n";
}
std::cin >> selection;
if(world[world[room].nextRoom[selection]].pathVisible[world[world[room].nextRoom[selection]].index] == true) // :D
{
if (selection<1 || selection>world[room].openExits)
{
std::cout << "There is no path that way. Unless you like banging\n"
"your head against walls.\n\n" << std::endl;
std::cin.ignore(32767, '\n');
}
else
{
valid = true;
}
}
else
{
std::cout << "(Path exists, but not visible)\n" << std::endl;
std::cin.ignore(32767, '\n');
//std::cin.get();
}
}
return world[room].nextRoom[selection - 1];
}
|