Answered step by step
Verified Expert Solution
Link Copied!

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{10};
bool hasKey{ false };
};
/* GUI Functions */
void clearConsole();
void pauseConsole();
void splashScreen();
displayGameState;
displayGameDone;
displayIllegalMove;
getAction;
/* Engine Functions
std::vector buildMap()
{
std::vector map;
map.push_back(
{
"A small, dark prison cell with doors South and East.",
{Room::Direction::S, Room::Direction::E},
{Room::Name::armory, Room::Name::gate},
false
});
map.push_back(
{
"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.push_back(
{
"A store room with doors North and East.",
{Room::Direction::N, Room::Direction::E},
{Room::Name::cell, Room::Name::jailers},
false
});
map.push_back(
{
"A jailer's barracks with doors West and North.",
{Room::Direction::W, Room::Direction::N},
{Room::Name::armory, Room::Name::gate},
true
});
map.push_back(
{
"YOU FOUND THE KEY AND ESCAPED!",
{},
{},
false
});
return map;
}
void clearConsole(){
system("cls");
}
void pauseConsole(){
system("PAUSE");
}
//randomly place the key in either the cell, the armory, the jailer's barrack, or the gate room.
void randomizeKey(std::vector& map){
// Randomly select a room index to place the key
int keyRoomIndex = rand()% map.size();
// Set hasKey to true for the selected room
map[keyRoomIndex].hasKey = 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 displayGameState(const Player& player, const std::vector& map)
// Display player information
std::cout << "Current Room: "<< static_cast(player.currentRoom)<< 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: "<< map[static_cast(player.currentRoom)].message << std::endl;
std::cout << "Doors: ";
for (const auto& direction : map[static_cast(player.currentRoom)].doors){
std::cout << static_cast(direction)<<"";
}
std::cout << std::endl;
}
//output messages depending on if the player has one or lost.
void displayGameDone(const 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 displayIllegalMove(const 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 player/rooms including picking up the key.
// This function should call other functions in order to display illegal moves and/or 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 changeGameState(Room::Direction action, Player& player, const std::vector& map)
{
// Check if the chosen action is a valid door
auto currentRoomIndex = static_cast(player.currentRoom);
auto& currentRoom = map[currentRoomIndex];
auto doorIt = std::find(currentRoom.doors.begin(), currentRoom.doors.end(), action);
if (doorIt != currentRoom.doors.end()){
// Valid door, update player's current room
auto connectedRoomIndex = static_cast(currentRoom.connectedRoom[doorIt - currentRoom.doors.begin()]);
player.currentRoom = map[connectedRoomIndex].hasKey ? Room::Name::exit : map[connectedRoomIndex].connectedRoom[0];
return true;
}
// Invalid move
return false;
}
//Check the end-of-game conditions. i.e If the player is out
//of health or the player has reached the exit
bool gameIsNotDone(const Player& player)
{
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions