Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am creating a roguelike game and Having trouble creating the player and making sure it prints in the empty spaces of a random dungeon.
I am creating a roguelike game and Having trouble creating the player and making sure it prints in the empty spaces of a random dungeon. I also am having trouble with the player symbol @ duplicating and trailing behind it what changes to my code do i need to make so that I can fix these issues
grid and display header
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;
void displayPlayerPlayer player;
bool determineNewPositionint& r int& c int dir const;
void display;
bool isInBoundsint r int c const;
bool addPlayerint r int c;
bool WallsAreAtint r int c;
private:
std::vectorrooms;
char gridMAXROWSMAXCOLS;
int numofRooms;
int mrows;
int mcols;
Player mplayer;
;
grid and display cpp
Temple::Templeint rows, int cols:mrowsMAXROWSmcolsMAXCOLSmplayernullptr
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;
numofRooms roomsmade;
for int i ; i numofRooms; i
for int r roomsiRow; r roomsiRow roomsiheight; r
for int c roomsiCols; c roomsiCols roomsilength; c
gridrc;
Create and Connect Corridors
updating room centers
for int i ; i rooms.size; i
roomsiOldcenterR roomsicenterR;
roomsiOldcenterC roomsicenterC;
roomsicenterR roomsiRow roomsiheight ;
roomsicenterC roomsiCols roomsilength ;
Generate corridors between rooms
for int i ; i rooms.size; i
int startc roomsicenterC;
int startr roomsicenterR;
int endc roomsi centerC;
int endr roomsi centerR;
Generate horizontal corridor
for int x std::minstartc endc; x std::maxstartc endc; x
gridstartrx;
Generate vertical corridor
for int y std::minstartr endr; y std::maxstartr endr; y
gridyendc
Temple::~Temple
delete mplayer;
int Temple::rows const
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