Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish the object header & class ( update function in object.cpp ) , base code and specification provided below Specification: public: Must overload in the
Finish the object header & class update function in object.cpp base code and specification provided below
Specification:
public:
Must overload in the Guard and Player classes
update
For randomness
static std::randomdevice seed;
static std::defaultrandomengine engine;
add getterssetters AS NEEDED!
protected:
Room::Name currentRoom Room::Name::cell ;
Room.h
#ifndef ROOMH
#define ROOMH
#include
#include
#include
class Room
public:
enum class Name exit cell, closet, pantry, NW gate, NE E SE S SW W numHallwayRooms ;
enum class Direction N S E W none ;
Room;
~Room;
bool exitRoomDirection direction, Name& nextRoom;
void addDoorDirection direction, Name room;
bool pickupKey;
void dropKey;
private:
Name name Name::NW ;
std::map doorways;
bool hasKey false ;
;
#endif ROOMH
Room.cpp
#include "Room.h
Room::Room
Room::~Room
bool Room::exitRoomDirection direction, Name& nextRoom
auto it doorways.finddirection;
if it doorways.end
nextRoom itsecond;
return true;
return false;
void Room::addDoorDirection direction, Name room
doorwaysdirection room;
bool Room::pickupKey
if hasKey
hasKey false;
return true;
return false;
void Room::dropKey
hasKey true;
Player.h
#ifndef PLAYERH
#define PLAYERH
#include "Object.h
#include "Room.h
class Player:public Object
public:
Player;
void updateRoom::Name currentRoom;
private:
void changeGameState;
void displayIllegalMove;
void getAction;
int health;
bool hasKey false ;
;
#endif PLAYERH
Player.cpp
#include "Player.h
#include
Player::Player
void Player::updateRoom::Name currentRoom
thiscurrentRoom currentRoom;
void Player::changeGameStateRoom::Direction action, std::map& dungeonMap
Pick up the key if it is in this room
if dungeonMapcurrentRoomhasKey
hasKey true;
dungeonMapcurrentRoomhasKey false;
std::cout "You picked up the key.
;
If we are trying to go to the exit but don't have the key, display illegal move
if currentRoom Room::Name::gate && hasKey && action Room::Direction::E
displayIllegalMovethis action;
return;
Check for door
auto& exits dungeonMapcurrentRoomdoorways;
auto doorway exits.findaction;
if doorway exits.end
currentRoom doorwaysecond;
health;
return;
If there is not a connected room in that direction, it is illegal
displayIllegalMovethis action;
void Player::displayIllegalMoveconst Player& player, Room::Direction action
if playercurrentRoom Room::Name::gate && player.hasKey && action Room::Direction::E
std::cout "The door is locked. Perhaps if you had a key???
;
else
std::cout "You cannot go that way.
;
Room::Direction Player::getAction
char action;
std::cout std::endl;
std::cout "Select action: ;
std::cin action;
switch action
case w: return Room::Direction::N;
case a: return Room::Direction::W;
case d: return Room::Direction::E;
case s: return Room::Direction::S;
default: return Room::Direction::none;
Object.h
#ifndef OBJECTH
#define OBJECTH
#include
#include "Room.h
class Object
public:
virtual void update;
static std::randomdevice seed;
static std::defaultrandomengine engine;
protected:
Room::Name currentRoom Room::Name::cell ;
;
#endif OBJECTH
Object.cpp
#include "Object.h
std::randomdevice Object::seed;
std::defaultrandomengine Object::engine;
Object::Object
currentRoom Room::Name::cell;
void Object::update
Guard.h
#ifndef GUARDH
#define GUARDH
#include "Object.h
class Guard: public Object
public:
Guard;
void update;
private:
bool clockwise true ;
;
#endif GUARDH
Guard.cpp
#include "Guard.h
#include
Guard::Guard
Initialize current room randomly within the circular hallway
std::uniformintdistribution distributionstaticcastRoom::Name::NW staticcastRoom::Name::W;
currentRoom staticcastdistributionObject::engine;
Randomly determine clockwise movement
std::uniformintdistribution boolDistribution;
clockwise boolDistributionObject::engine;
updates guards position
void Guard::update
Calculate next room based on current room and direction
int currentRoomIndex staticcastcurrentRoom;
int numRooms staticcastRoom::Name::numHallwayRooms;
Determine next room index based on movement direction
int nextRoomIndex;
if clockwise
nextRoomIndex currentRoomIndex numRooms;
else
nextRoomIndex currentRoomIndex numRooms numRooms;
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