1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
using namespace std;
const int MAXX = 5000, MAXY = 6600;
struct inmatrix {
int iTerrainType;
int iTile;
bool isObstacle;
};
class zone {
int xsize, ysize;
char cName[16];
inmatrix **matrix;
public:
char *pName;
zone();
~zone();
char *getname() { return pName; };
void setname(char *pN) { pName = pN; }
bool isObstacle(int x, int y) { return matrix[x][y].isObstacle; }
void setObstacle(int x, int y, bool b) { matrix[x][y].isObstacle = b; }
bool init(int iSizeX, int iSizeY, char *pNewName = '\0');
};
zone::zone() {
matrix = new inmatrix *[MAXY];
for (int i = 0; i < MAXY; i++)
matrix[i] = new inmatrix[MAXX];
strcpy(cName, "");
pName = cName;
}
zone::~zone() {
for( int i = 0 ; i < MAXY ; i++ )
delete [] matrix[i];
delete [] matrix;
}
bool zone::init(int iSizeX, int iSizeY, char *pNewName ) {
xsize = iSizeX;
ysize = iSizeY;
if (!xsize || !ysize) return false;
if (pNewName) pName = pNewName;
else if (!pName) pName = "noname";
for (int a = 0; a < ysize; a++)
for (int b = 0; b < xsize; b++) {
matrix[b][a].iTerrainType = 0;
matrix[b][a].iTile = 0;
matrix[b][a].isObstacle = false;
}
cout << "The zone " << &pName << ":" << pName << " was initialized (" << xsize << ", " << ysize << ")\n";
return true;
}
int main( int argc, char *argv[] ) {
zone myzone, myzone2, *pZone;
pZone = &myzone;
pZone->init(50, 50, "myzone");
pZone->setObstacle(0, 0, true);
myzone2.pName = "myzone2\0";
myzone2.init(100, 50);
cout << "\nZone: " << pZone->pName << " Pos: 0, 0 isObstacle: " << (pZone->isObstacle(0, 0)?"true":"false") << "\n";
cout << "Zone: " << pZone->pName << " Pos: 1, 0 isObstacle: " << (pZone->isObstacle(1, 0)?"true":"false") << "\n";
return 0;
}
|