Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am creating a rougelike can that creates a radomized grid with corridors connecting them. I am having trouble adding the player and also making
I am creating a rougelike can that creates a radomized grid with corridors connecting them. I am having trouble adding the player and also making sure they cannot walk on walls. For add the player I want to store the grid as a char vector and then have another vector that is used to carve the rooms out. Should I use the room or grid vector to store the open space coords to add the player? Could you fix my code of the temple class to ensure that it runs how it is intended, assume other functions from other classes are implemented.
#ifndef TEMPLEH
#define TEMPLEH
#include
#include "Nglobals.h
#include "NUtilities.h
struct room
int Row, Cols, OldcenterR, OldcenterC, centerR, centerC, length, height, symbol;;
class Player;
class Temple
public:
Constructordestructor
Templeint nRows, int nCols;
~Temple;
Accessors
int rows const; int cols const;
Player player const;
bool isPlayerAtint r int c const;
bool determineNewPositionint& r int& c int dir const;
void CreateTemple;
void display; please create this one
bool addPlayerint r int c;please create this one
bool WallsAreAtint r int c;
private:
std::vectorrooms;
std::vector grid;
int numofRooms;
int mrows;
int mcols;
Player mplayer;
bool isInBoundsint r int c const; please make this
#include "NTemple.h
#include "Nglobals.h
#include "NPlayer.h
#include "NUtilities.h
#include "Tooter.h
#include
#include
#include
Temple::Templeint rows, int cols:mrowsMAXROWSmcolsMAXCOLSmplayernullptr
grid.assignmrows, std::vectormcols, #;
Temple::~Temple
delete mplayer;
int Temple::rows const
return mrows;
int Temple::cols const
return mcols;
Player Temple::player const
return mplayer;
bool Temple::isPlayerAtint r int c const
return mplayer nullptr &&
mplayergetRow r && mplayergetCols c;
bool Temple::determineNewPositionint& r int& c int dir const
switch dir
case ARROWUP:
if r
return false;
else r;
break;
case ARROWDOWN:
if r rows
return false;
else r;
break;
case ARROWLEFT:
if c
return false;
else c;
break;
case ARROWRIGHT:
if c cols
return false;
else c; break;
default: return false;
void Temple::CreateTemple
numofRooms ;
for int r ; r mrows; r
for int c ; c mcols; c
gridrc#;
numofRooms randInt; randomizes the number of rooms
bool stop false; used to stop adding rooms
int roomsmade ; keeps track of rooms created
for int i ; i numofRooms && stop false; i
rooms.pushbackroom;
randomizing the height and length of rooms
roomsiheight randInt;
roomsilength randInt;
Creating the first room
if i
roomsiRow randIntMAXROWS roomsiheight;
roomsiCols randIntMAXCOLS roomsilength;
roomsmade;
else Creating the rooms that are not the first.
int attemptingToCreate ;
bool goodPos false;
bool goon true;
while goodPos false
goon true;
roomsiRow randIntMAXROWS roomsiheight;
roomsiCols randIntMAXCOLS roomsilength;
for int k ; k roomsmade && goon true;Checking for overlap
if roomsiRow roomsiheightroomskRow
roomsiRowroomskRow roomskheight
roomsiCols roomsilengthroomskCols
roomsiColsroomskCols roomsklength
k;
else
goon false;
if goon true
roomsmade;
goodPos true;
else
attemptingToCreate;
if attemptingToCreate number of attempts
rooms.popback;
roomsmade;
i;
stop true;
break
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