N
Numeron
This is part of my first ever largish project, a tile based game. I
havent got a lot of experience with c++ so be nice
this is all within Tile.h, a lot has been taken out or simplified for
the sake of...er simplicity lol.
class Tile{
private:
int locationX;
int locationY;
public:
Tile(int inLocX, int inLocY){
setLocX(inLocX);
setLocY(inLocY); }
void setLocX(int inLocX){ locationX = inLocX; }
void setLocY(int inLocY){ locationY = inLocY; }
int getLocX(){ return locationX; }
int getLocY(){ return locationY; }
}//end of Tile class
class FloorTile : public Tile{
private:
int roomID;
public;
FloorTile(int inLocX, int inLocY, int inRoomID):Tile(inLocX, inLocY)
{
setRoomID(roomID); }
void setRoomID(int inRoomID){ roomID = inRoomID; }
int getRoomID(){ return roomID; }
}//end of FloorTile class
the idea is that i have a 2d array called map which holds tiles of
various kinds inlcuding wall, void and as seen above, floor. All of
that works fine, but when i look up, for example the tile at position
10,10 and i *know* that it is a floor tile, calling setRoomID() doenst
work. Origional code looks somthing like this:
map[10][10].setRoomID(15);
ive been shotgun programming it all afternoon, the best idea ive had
is pretty ugly, but still wont work because FloorTile is non-scalar
and cant be cast like thus:
FloorTile tempTile = map[10][10];
tempTile.setRoomID(15);
I guess what i need is some way to get it recognising the difference
between the types of tiles, once theyre pulled out of the array,
thereby opening the possibility of accessing the methods of the
subclass, but i have no idea...
sorry for noobing it up, im pretty sure this is a stupid thing to get
stuck on
-Numeron
havent got a lot of experience with c++ so be nice
this is all within Tile.h, a lot has been taken out or simplified for
the sake of...er simplicity lol.
class Tile{
private:
int locationX;
int locationY;
public:
Tile(int inLocX, int inLocY){
setLocX(inLocX);
setLocY(inLocY); }
void setLocX(int inLocX){ locationX = inLocX; }
void setLocY(int inLocY){ locationY = inLocY; }
int getLocX(){ return locationX; }
int getLocY(){ return locationY; }
}//end of Tile class
class FloorTile : public Tile{
private:
int roomID;
public;
FloorTile(int inLocX, int inLocY, int inRoomID):Tile(inLocX, inLocY)
{
setRoomID(roomID); }
void setRoomID(int inRoomID){ roomID = inRoomID; }
int getRoomID(){ return roomID; }
}//end of FloorTile class
the idea is that i have a 2d array called map which holds tiles of
various kinds inlcuding wall, void and as seen above, floor. All of
that works fine, but when i look up, for example the tile at position
10,10 and i *know* that it is a floor tile, calling setRoomID() doenst
work. Origional code looks somthing like this:
map[10][10].setRoomID(15);
ive been shotgun programming it all afternoon, the best idea ive had
is pretty ugly, but still wont work because FloorTile is non-scalar
and cant be cast like thus:
FloorTile tempTile = map[10][10];
tempTile.setRoomID(15);
I guess what i need is some way to get it recognising the difference
between the types of tiles, once theyre pulled out of the array,
thereby opening the possibility of accessing the methods of the
subclass, but i have no idea...
sorry for noobing it up, im pretty sure this is a stupid thing to get
stuck on
-Numeron