Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish writing the functions displayGameDone and displayIllegalMove. Please actually write the code and do not just explain it . Go off what is already written.
Finish writing the functions displayGameDone and displayIllegalMove. Please actually write the code and do not just explain it Go off what is already written.
#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.
s
Engine Functions
std::vector buildMap;
randomizeKey;
changeGameState;
gameIsNotDone;
int main
Splash Screen
clearConsole;
splashScreen;
set up game
std::vector map buildMap;
Player player;
Until Game Termination Condition
while gameIsNotDoneplayer
Display Game State
clearConsole;
displayGameStateplayer map;
Collect Player Action
Room::Direction action getAction;
Update Game State
if changeGameStateaction player, map
displayIllegalMoveplayer action;
Display Termination Game State
displayGameDoneplayer map;
return ;
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