c++ - How can I convert from a class with a 2D vector of chars to a 2D vector of another obj with a char variable? -
i'm still new apologies in advance if provide or not enough information problem.
the run down
this question isn't rogue game related question, little background of program does.. similar rogue game.
ok, had class had member 2d char vector (the chars manipulated represent "dungeon"). worked seamlessly. wanted expand program decided create new class replace 2d vector of chars char visual representation of new class , other variables can stored along char.
for simplistic sake, tried remove isn't necessary question. new class called tile - represents space being used dungeon level. tile has:
a char variable called displaychar.. defaults ' ' changes represent contains
(other variables..)
the problems / poor guesses
i'm not best @ understanding concepts of programming syntax/implementation, please don't judge.
- the way filled vector of chars, resized width of game board, , set ' ' since values chars
i think need fill new, tile objects , push them 2d tile vector?
my other methods manipulated char values giving errors.
i think should change methods take pointer tile object , use setdisplaychar(' ') method change value?
my at(int, int) method used return char @ location
- i thought change "return m_vvtiles[y][x].getdisplaychar()" error
i'm bad @ changing how works , end making mess out of code. i'll post code relevant this. i'd appreciate can offer. , please let me know if need add more. (i'll try keep code minimized related methods). thanks!
dungeonlevel.h
#include "tile.h" #include <vector> #include <random> class dungeonlevel { public: dungeonlevel(int iwidth, int iheight, std::mt19937 & mt); ~dungeonlevel(void); void dump(); char at(int x, int y); int getwidth(); int getheight(); private: std::vector<std::vector<tile>> m_vvtiles; //tile char };
dungeonlevel.cpp
#include <iostream> #include <random> #include "dungeonlevel.h" using namespace std; dungeonlevel::dungeonlevel(int iwidth, int iheight, std::mt19937 & mt){ // initialize blank vector m_vvtiles.resize(iheight); for(auto = m_vvtiles.begin(); != m_vvtiles.end(); it++ ){ // tile temptile = new;? (*it).resize(iwidth,' '); } // divide level 4x2 chunks int ichunkwidth = iwidth / 4; int ichunkheight = iheight / 2; // taking easy way out, , generating // loop of tunnels first drop rooms on for( int x = (ichunkwidth/2); x <= ((3 * ichunkwidth) + (ichunkwidth/2)$ m_vvtiles[ichunkheight/2][x] = '#'; m_vvtiles[ichunkheight + (ichunkheight/2)][x] = '#'; } for( int y = (ichunkheight/2); y <= (ichunkheight + (ichunkheight/2)); $ m_vvtiles[y][ichunkwidth/2] = '#'; m_vvtiles[y][(3 * ichunkwidth) + (ichunkwidth/2)] = '#'; } void dungeonlevel::dump(){ for( auto itouter = m_vvtiles.begin(); itouter != m_vvtiles.end(); itou$ for( auto itinner = (*itouter).begin(); itinner != (*itouter).e$ cout << *itinner.getdisplaychar(); ///updated:: causing error// } cout << endl; } } //several irrelevant lines problem.. } char dungeonlevel::at(int x, int y){ return m_vvtiles[y][x].getdisplaychar(); //return m_vvtiles[y][x]; worked before }
tile.h
#include "entity.h" #include <vector> class tile : public entity { public: tile(void); virtual ~tile(void); //void setentity(entity * entitytoset); both irrelevant //entity * getentity(); void setdisplaychar(char displaychartoset); char getdisplaychar(); //virtual void dumpobjectdata(); irrelevant @ time private: char displaychar; //entity * theentity; irrelevant @ time };
tile.cpp
#include "tile.h" #include "entity.h" using namespace std; tile::tile(void){ displaychar = '.'; //theentity = null; } tile::~tile(void){ } void tile::setdisplaychar(char displaychartoset){ displaychar = displaychartoset; } char tile::getdisplaychar(){ return displaychar; }
*heres existing error: *
for method dump() in dungeonlevel.cpp,
some of questions answers
i think need fill new, tile objects , push them 2d tile vector?
no need resize , fill tile objects. pretty did when char array. new doesn't come it.
i think should change methods take pointer tile object , use setdisplaychar(' ') method change value?
i use reference.
i thought change return m_vvtiles[y][x].getdisplaychar()
error.
that sounds right me, error did get?
everything redesign sounds motivated me. idea make before going on major reorganization however.
Comments
Post a Comment