Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on a project to create a roguelike game, So far I am focusing on the grid and player movement. So far I
I am working on a project to create a roguelike game, So far I am focusing on the grid and player movement. So far I have gotten the grid to display and I believe movement logic. However, sometimes the player will be created and sometimes it won't. When it is the player symbol @ trails and make duplicates, the player also runs into walls which is not suppose to happen. Could you eveluate the code implemented so far and fix the issue? Thank you!
Gameh runs the game
#ifndef GAMEINCLUDED
#define GAMEINCLUDED
You may add data members and other member functions to this class.
class Temple;
class Game
public:
Gameint goblinSmellDistance;
~Game;
void display const;
void statusbool& over, bool& win const;
void playerInput;
void play;
private:
Temple mtemple;
Gamecpp
;Game::Gameint goblinSmellDistance
int rows MAXROWS;
int cols MAXCOLS;
mtemple new Templerowscols;
int rPlayer randInt cols;
int cPlayer randInt rows;
mtempleaddPlayerrPlayer cPlayer;
Game::~Game
delete mtemple;
void Game::play
mtempleCreateTemple;
mtempledisplay;
Player p mtempleplayer;
if p nullptr
std::cout "player not made" std::endl;
return;
while pisDead
std::cout "Level:" Hit points: Armor:
;
char command getCharacter;
switch command
default: if bad move, nobody moves
cout a; beep
continue;
case q:
return;
case h:
case j:
case k:
case l:
pmovecommand;
break;
mtempledisplay;
std::cout "game runs" endl;
#define TEMPLEH grid and player display
#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;
void isPlayerAtint r int c const;
bool determineNewPositionint& r int& c int dir const;
void CreateTemple;
void displayPlayerPlayer player;
void display;
bool isInBoundsint r int c const;
bool addPlayerint r int c;
private:
std::vectorrooms;
char gridMAXROWSMAXCOLS;
int numofRooms;
int mrows;
int mcols;
Player mplayer;
;#include "NTemple.h
#include "Nglobals.h
#include "NPlayer.h
#include "NUtilities.h
Temple::Templeint rows, int cols:mrowsMAXROWSmcolsMAXCOLSmplayernullptr
numofRooms ;
for int r ; r mrows; r
for int c ; c mcols; c
gridrc#;
Temple::~Temple
delete mplayer;
int Temple::rows const
return mrows;
int Temple::cols const
return mcols;
Player Temple::player const
return mplayer;
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;
return true;
void Temple::CreateTemplecreates rooms and corridors that connectvoid Temple::displaydisplay map only
clearScreen;
if mplayer nullptr
Set the char to @ unless there's also a Tooter there
which should never happen in which case set it to
char& gridChar gridmplayergetRowmplayergetCols;
if gridChar
gridChar @;
for int r ; r rows; r
for int c ; c cols; c
std::cout gridrc;
std::cout std::endl;
bool Temple::addPlayerint r int c
if isInBoundsr c
return false;
Don't add a player if one already exists
if mplayer nullptr
return false;
go through for monsters
mplayer new Playerthis r c;
return true;
bool Temple::isInBoundsint r int c const
return r && r mrows && c && c mcols;
class Playerlayer implementation
public:
PlayerTemple t int r int c:mTempletmrowrmcolcsymbolsymbol
~Player
char getSymbol const return symbol;
char setSymbol const
get and set Coords
int getRow const return mrow;
int getCols const return mcol;
track movement
int Tracker const return track;
bool isDead return hp ;
void moveint dir for movement ssume all private member are there
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