1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
int main() {
constexpr const char* names[5][2] { { "Forest", "You are in a forest.There are paths to the north(2) and east(3)"},
{"River", "You are at a river. There is a bridge to the east (3) and a path to the south (1)"},
{"Cave Entrance", "You are at the entrance of a dark cave. There is a path to the west (2) and a path leading further into the cave (4)" },
{"Inside Cave", "You are inside the dark cave.There is a path leading out of the cave(3) and a path leading deeper into the cave(5)"},
{ "Winning Location", "Congratulations! You have reached the winning location." } };
constexpr unsigned valid[4][2] { {1, 2}, {0, 2}, {1, 3}, {2, 4} };
for (unsigned location {}, next_location {}; (std::cout << "You are at location: " << names[location][0] << '\n' << names[location][1] << ".\n") && location != 4; location = next_location)
do {
std::cout << "Where would you like to go: ";
std::cin >> next_location;
--next_location;
} while ((next_location > 4) || ((valid[location][0] != next_location) && (valid[location][1] != next_location)) && (std::cout << "Invalid location\n"));
}
|