Question: Finish the functions in Room.h based on the comments. Make sure to fix any errors. Room.H #ifndef ROOM _ H #define ROOM _ H #include

Finish the functions in Room.h based on the comments. Make sure to fix any errors.
Room.H
#ifndef ROOM_H
#define ROOM_H
#include
#include
#include
class Room
{
public:
enum class Name { exit =-4, cell, closet, pantry, NW, gate, NE, E, SE, S, SW, W, numHallwayRooms };
enum class Direction { N, S, E, W, none };
Room();
~Room;
//Uses the find_if algorithm to see if the action matches any direction in the doorways map. The method needs to indicate a valid move and which room the player would then be entering
bool exitRoom(Direction direction, Name& nextRoom);
//Uses passed in values to add a door to the map
void addDoor(Direction direction, Name room);
//Checks to see if the key is in the room. If it is, change hasKay to false and return true, otherwise just return false
bool pickupKey();
//A setter that simply changes hasKey to true. Used in randomizeKey function.
void dropKey();
private:
Name name{ Name::NW };
std::map doorways;
bool hasKey{ false };
};
#endif //!ROOM_H
Room.cpp
#include "Room.h"
Room::Room(){}
Room::~Room(){}
bool Room::exitRoom(){
return name == Name::exit;
}
void Room::addDoor(Direction direction, Name room){
doorways[direction]= room;
}
bool Room::pickupKey(){
if (hasKey){
hasKey = false;
return true;
}
return false;
}
void Room::dropKey(){
hasKey = true;
}
Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include "Object.h"
#include "Room.h"
class Player:public Object
{
public:
void update();
private:
void changeGameState();
void displayIllegalMove();
getAction();
int health{10};
bool hasKey{ false };
};
#endif //!PLAYER_H
Player.cpp
#include "Player.h"
Player::Player(){}
void Player::update(Room::Name currentRoom){
}
void Player::changeGameState(){
}
void Player::displayIllegalMove(){
}
void Player::getAction(){
}
Object.h
#ifndef OBJECT_H
#define OBJECT_H
#include
#include "Room.h"
class Object
{
public:
virtual void update()=0;
static std::random_device seed;
static std::default_random_engine engine;
protected:
Room::Name currentRoom{ Room::Name::cell };
};
#endif //!OBJECT_H
Object.cpp
#include "Object.h"
std::random_device Object::seed;
std::default_random_engine Object::engine;
Object::Object(){
currentRoom = Room::Name::cell;
}
void Object::update(){
}
Guard.h
#ifndef GUARD_H
#define GUARD_H
#include "Object.h"
class Guard: public Object
{
public:
Guard();
void update();
private:
bool clockwise{ true };
};
#endif //!GUARD_H
Guard.cpp
#include "Guard.h"
Guard::Guard(){}
//updates the guards position
void Guard::update(){
}
Source.cpp
#include
#include
#include
#include
#include
#include
#include "Room.h"
#include "Player.h"
#include "Guard.h"
//Bigger map
//guard chasing.
//find key and exit.
//bonus:guard moves towards player.
/* GUI Functions */
void splashScreen();
/* Engine Functions*/
std::map buildMap();
void randomizeKey(std::map& dungeonMap);
bool gameIsNotDone(const Player& player, const Guard& guard);
void displayGameDone(const Player& player, const Guard& guard, const std::map& dungeonMap);
int main(){
/*Splash Screen*/
system("CLR");
splashScreen();
/*set up game*/
std::map dungeonMap{ buildMap()};
Player player;
Guard guard;
/*Until Game Termination Condition Do: */
while (gameIsNotDone(player, guard))
{
/*Display Game State*/
system("CLS");
std::cout <<"P:"<<(int)player.getCurrentRoom()<< std::endl;
std::cout <<"G:"<<(int)guard.getCurrentRoom()<< std::endl;
player.update(dungeonMap);
guard.update(dungeonMap);
}
/*Display Termination Game State*/
displayGameDone(player, guard, dungeonMap);
return 0;
}
std::map buildMap()
{
//enum class Name { cell, gate, armory, jailers, exit };
std::map dungeonMap;
std::ifstream fin;
fin.open("dungeonLayout.txt");
if (fin.is_open())
{
int name{0};
int numDoors{0};
while (name <(int)Room::Name::numHallwayRooms-1)
{
fin >> name >> numDoors;
for (int i{0}; i < numDoors; i++)
{
int direction;
int room;
fin >> direction >> room;
dungeonMap[(Room::Name)name].addDoor((Room::Direction)direction,(Room::Name)room);
}
}
randomizeKey(dungeonMap);
}
return dungeonMap;
}
void randomizeKey(std::map& dungeonMap)
{
std::bernoulli_distribution closetVsPantry(.5);
if (closetVsPantry(Object::engine))
{
dungeonMap[Room::Name::closet].dropKey();
}
else
{
dungeonMap[Room::Name::pantry].dropKey();
}
}
void clearConsole(){
system("cls");
}
void pauseConsole(){
system("PAUSE");
}
void displayGameDone(const Player& player, const Guard& guard, const std::map& dungeonMap)
{
clearConsole();
if (player.getHealth()>0)
{
if (player.getCurrentRoom()== Room::Name::exit)
{
std::cout << "You found the key and escaped!" << std::endl;
}
else if(player.getCurrentRoom()== guard.getCurrentRoom())
{
std::cout << "The guard caught you and you are thrown back in your cell!" << std::endl;
}
}
else
{
std::cout << "YOU DIED...RIP." << std::endl;
}
std::cout << std::endl;
pauseConsole();
}
//Check the end-of-game conditions. If the player is out
//of health or the player has reached the exit
//then the game is over.
bool gameIsNotDone(const Player& player, const Guard& guard)
{
return !(
player.getHealth()<=0
|| player.getCurrentRoom()== Room::Name::exit
|| player.getCurrentRoom()== guard.getCurrentRoom()
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!