Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish the displayGameDone and displayIllegalMove functions. #include #include #include struct Room { enum class Name { cell, gate, armory, jailers, exit } ; enum class
Finish the displayGameDone and displayIllegalMove functions.
#include
#include
#include
struct Room
enum class Name cell, gate, armory, jailers, exit ;
enum class Direction N S E W none ;
std::string message; the message displayed when in the room.
std::vector doors; the directions in which there are doors.
std::vector connectedRoom; the name of the room in which the corresponding door leads.
NOTE:: these two vectors will eventually become a std::map after the STL level.
bool hasKey false ; whether or not the player has picked up the key.
;
struct keeps track of the room the player is in their health, and rather or not they have picked up the key.
struct Player
Room::Name currentRoom Room::Name::cell ;
int health;
bool hasKey false ;
;
GUI Functions
void clearConsole;
void pauseConsole;
void splashScreen;
displayGameState;
displayGameDone;
displayIllegalMove;
getAction;
Engine Functions
std::vector buildMap
std::vector map;
map.pushback
"A small, dark prison cell with doors South and East.",
Room::Direction::S Room::Direction::E
Room::Name::armory, Room::Name::gate
false
;
map.pushback
"A large, torchlit room with doors West, South, and East.
There is daylight entering under the door to the East.",
Room::Direction::W Room::Direction::S Room::Direction::E
Room::Name::cell, Room::Name::jailers, Room::Name::exit
false
;
map.pushback
"A store room with doors North and East.",
Room::Direction::N Room::Direction::E
Room::Name::cell, Room::Name::jailers
false
;
map.pushback
"A jailer's barracks with doors West and North.",
Room::Direction::W Room::Direction::N
Room::Name::armory, Room::Name::gate
true
;
map.pushback
"YOU FOUND THE KEY AND ESCAPED!",
false
;
return map;
void clearConsole
systemcls;
void pauseConsole
systemPAUSE;
randomly place the key in either the cell, the armory, the jailer's barrack, or the gate room.
void randomizeKeystd::vector& map
Randomly select a room index to place the key
int keyRoomIndex rand map.size;
Set hasKey to true for the selected room
mapkeyRoomIndexhasKey true;
output information as demonstrated in the instructions.
You will need to deal with display changes that depend on the key.
NOTE:: NO game variables such as the player or rooms should be modified in this function!!!
void displayGameStateconst Player& player, const std::vector& map
Display player information
std::cout "Current Room: staticcastplayercurrentRoom std::endl;
std::cout "Health: player.health std::endl;
std::cout "HasKey: std::boolalpha player.hasKey std::endl;
Display information about the current room
std::cout "Current Room Message: mapstaticcastplayercurrentRoommessage std::endl;
std::cout "Doors: ;
for const auto& direction : mapstaticcastplayercurrentRoomdoors
std::cout staticcastdirection;
std::cout std::endl;
output messages depending on if the player has one or lost.
void displayGameDoneconst Player& player, const std::vector& map
output illegal move messages depending if player tries to exit without the key
or the player tries to exit the wrong way out of a room.
void displayIllegalMoveconst Player& player, Room::Direction action
ask for user input, convert char to Room::Direction
Room::Direction getAction
char userInput;
std::cout "Choose direction N S E W: ;
std::cin userInput;
return Room::Direction::userInput;
This function is the only one that should make modifications to the playerrooms including picking up the key.
This function should call other functions in order to display illegal moves andor move the player to a new room.
If the player moves to a new room, health needs to be decremented.
Look at int main to decide on return type.
bool changeGameStateRoom::Direction action, Player& player, const std::vector& map
Check if the chosen action is a valid door
auto currentRoomIndex staticcastplayercurrentRoom;
auto& currentRoom mapcurrentRoomIndex;
auto doorIt std::findcurrentRoomdoors.begin currentRoom.doors.end action;
if doorIt currentRoom.doors.end
Valid door, update player's current room
auto connectedRoomIndex staticcastcurrentRoomconnectedRoomdoorIt currentRoom.doors.begin;
player.currentRoom mapconnectedRoomIndexhasKey Room::Name::exit : mapconnectedRoomIndexconnectedRoom;
return true;
Invalid move
return false;
Check the endofgame conditions. ie If the player is out
of health or the player has reached the exit
bool gameIsNotDoneconst Player& player
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started