Question: Finish the functions in player.cpp . Update function is a copy paste from last assignments displayGameState function, however it also calls the changeGameState function. Add
Finish the functions in player.cpp Update function is a copy paste from last assignments displayGameState function, however it also calls the changeGameState function. Add getters and setters as needed. The rest of the functions are an exact copy paste from previous assignment but with modification for being in a class. The only addition is in changeGameState outputting the proper message when a key other than w a s d is pressed, displayIllegalMove is called rather than returning true or false.
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
Player::Player
update player position
void Player::updateRoom::Name currentRoom
changes game state
void Player::changeGameState
illegal move message
void Player::displayIllegalMove
gets player action
void Player::getAction
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
Guard::Guard
updates 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 randomizeKeystd::map& dungeonMap;
bool gameIsNotDoneconst Player& player, const Guard& guard;
void displayGameDoneconst Player& player, const Guard& guard, const std::map& dungeonMap;
int main
Splash Screen
systemCLR;
splashScreen;
set up game
std::map dungeonMap buildMap;
Player player;
Guard guard;
Until Game Termination Condition Do:
while gameIsNotDoneplayer guard
Display Game State
systemCLS;
std::cout P:intplayergetCurrentRoom std::endl;
std::cout G:intguardgetCurrentRoom std::endl;
player.updatedungeonMap;
guard.updatedungeonMap;
Display Termination Game State
displayGameDoneplayer guard, dungeonMap;
return ;
std::map buildMap
enum class Name cell, gate, armory, jailers, exit ;
std::map dungeonMap;
std::ifstream fin;
fin.opendungeonLayouttxt;
if finisopen
int name;
int numDoors;
while name intRoom::Name::numHallwayRooms
fin name numDoors;
for int i; i numDoors; i
int direction;
int room;
fin direction room;
dungeonMapRoom::NamenameaddDoorRoom::DirectiondirectionRoom::Nameroom;
randomizeKeydungeonMap;
return dungeonMap;
void randomizeKeystd::map& dungeonMap
std::bernoullidistribution closetVsPantry;
if closetVsPantryObject::engine
dungeonMapRoom::Name::closetdropKey;
else
dungeonMapRoom::Name::pantrydropKey;
void clearConsole
systemcls;
void pauseConsole
systemPAUSE;
void displayGameDoneconst Player& player, const Guard& guard, const std::map& dungeonMap
clearConsole;
if playergetHealth
if playergetCurrentRoom 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 in cell!" std::endl;
else
std::cout "You Died... RIP." std::endl;
std::cout std::endl;
pauseConsole;
check end of game conditions if the player out of health or reached exit then game is over
bool gameIsNotDoneconst Player& player, const Guard& guard
return playergetHealth
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
