Answered step by step
Verified Expert Solution
Link Copied!

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 TEMPLE_H
#define TEMPLE_H
#include
#include "Nglobals.h"
#include "NUtilities.h"
struct room
{
int Row, Cols, Old_centerR, Old_centerC, centerR, centerC, length, height, symbol;};
class Player;
class Temple
{
public:
// Constructor/destructor
Temple(int nRows, int nCols);
~Temple();
// Accessors
int rows() const; int cols() const;
Player* player() const;
bool isPlayerAt(int r, int c) const;
bool determineNewPosition(int& r, int& c, int dir) const;
void Create_Temple();
void display(); //please create this one
bool addPlayer(int r, int c);//please create this one
bool WallsAreAt(int r, int c);
private:
std::vectorrooms;
std::vector> grid;
int num_ofRooms;
int m_rows;
int m_cols;
Player* m_player;
bool isInBounds(int 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::Temple(int rows, int cols):m_rows(MAXROWS),m_cols(MAXCOLS),m_player(nullptr)
{
grid.assign(m_rows, std::vector(m_cols, '#'));
}
Temple::~Temple()
{
delete m_player;
}
int Temple::rows() const
{
return m_rows;
}
int Temple::cols() const
{
return m_cols;
}
Player* Temple::player() const
{
return m_player;
}
bool Temple::isPlayerAt(int r, int c) const
{
return m_player != nullptr &&
m_player->getRow()== r && m_player->getCols()== c;
}bool Temple::determineNewPosition(int& r, int& c, int dir) const
{
switch (dir)
{
case ARROW_UP:
if (r <=1)
return false;
else r--;
break;
case ARROW_DOWN:
if (r >= rows())
return false;
else r++;
break;
case ARROW_LEFT:
if (c <=1)
return false;
else c--;
break;
case ARROW_RIGHT:
if (c >= cols())
return false;
else c++; break;
default: return false;
}
}
void Temple::Create_Temple()
{
num_ofRooms =0;
for (int r =0; r < m_rows; r++)
for (int c =0; c < m_cols; c++)
grid[r][c]='#';
num_ofRooms =4+ randInt(3); //randomizes the number of rooms 3-4
bool stop = false; //used to stop adding rooms
int rooms_made =0; //keeps track of rooms created
for (int i =0; i < num_ofRooms && stop == false; i++)
{
rooms.push_back(room());
//randomizing the height and length of rooms
rooms[i].height =4+ randInt(5);
rooms[i].length =6+ randInt(13);
//Creating the first room
if (i ==0)
{
rooms[i].Row =1+ randInt((MAXROWS -1)- rooms[i].height);
rooms[i].Cols =1+ randInt((MAXCOLS -1)- rooms[i].length);
rooms_made++;
}
else //Creating the rooms that are not the first.
{
int attemptingToCreate =0;
bool goodPos = false;
bool go_on = true;
while (goodPos == false)
{
go_on = true;
rooms[i].Row =1+ randInt((MAXROWS -1)- rooms[i].height);
rooms[i].Cols =1+ randInt((MAXCOLS -1)- rooms[i].length);
for (int k =0; k < rooms_made && go_on == true;)//Checking for overlap
{
if ((rooms[i].Row + rooms[i].height)<(rooms[k].Row)||
(rooms[i].Row)>(rooms[k].Row + rooms[k].height)||
(rooms[i].Cols + rooms[i].length)<(rooms[k].Cols)||
(rooms[i].Cols)>(rooms[k].Cols + rooms[k].length))
{
k++;
}
else
{
go_on = false;
}
}
if (go_on == true)
{
rooms_made++;
goodPos = true;
}
else
{
attemptingToCreate++;
if (attemptingToCreate ==100000)//number of attempts
{
rooms.pop_back();
rooms_made--;
i--;
stop = true;
break}
}}}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the purpose of an industry analysis.

Answered: 1 week ago

Question

=+what information would you need about the compact disc industry?

Answered: 1 week ago