Answered step by step
Verified Expert Solution
Link Copied!

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 (gameIsNotDone(player))
{
/*Display Game State*/
clearConsole();
displayGameState(player, map);
/*Collect Player Action*/
Room::Direction action{ getAction()};
/*Update Game State*/
if (!changeGameState(action, player, map))
{
displayIllegalMove(player, action);
}
}
/*Display Termination Game State*/
displayGameDone(player, map);
return 0;
}
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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

In Exercises 103114, factor completely. 7x 4 + 34x 2 - 5

Answered: 1 week ago