Last change
on this file since 60b77d2 was 60b77d2, checked in by dportnoy <dmp1488@…>, 12 years ago |
Added a Map class
|
-
Property mode
set to
100644
|
File size:
904 bytes
|
Rev | Line | |
---|
[60b77d2] | 1 | #include "Map.h"
|
---|
| 2 |
|
---|
| 3 | using namespace std;
|
---|
| 4 |
|
---|
| 5 | Map::Map(int width, int height)
|
---|
| 6 | {
|
---|
| 7 | this->width = width;
|
---|
| 8 | this->height = height;
|
---|
| 9 |
|
---|
| 10 | vctMap = new vector<vector<TerrainType>*>(width);
|
---|
| 11 |
|
---|
| 12 | for (int x=0; x<width; x++) {
|
---|
| 13 | vector<TerrainType>* newVector = new vector<TerrainType>(height);
|
---|
| 14 |
|
---|
| 15 | for (int y=0; y<height; y++)
|
---|
| 16 | (*newVector)[y] = TERRAIN_NONE;
|
---|
| 17 |
|
---|
| 18 | (*vctMap)[x] = newVector;
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | Map::~Map()
|
---|
| 23 | {
|
---|
| 24 | for (int x=0; x<width; x++)
|
---|
| 25 | delete (*vctMap)[x];
|
---|
| 26 |
|
---|
| 27 | delete vctMap;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void Map::setElement(int x, int y, TerrainType t)
|
---|
| 31 | {
|
---|
| 32 | (*(*vctMap)[x])[y] = t;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | Map* Map::createDefaultMap()
|
---|
| 36 | {
|
---|
| 37 | Map* m = new Map(20l, 20);
|
---|
| 38 |
|
---|
| 39 | for(int x=0; x<20; x++)
|
---|
| 40 | {
|
---|
| 41 | for(int y=0; y<20; y++)
|
---|
| 42 | {
|
---|
| 43 | if (x ==0 || y == 0 || x == 19 || y == 19)
|
---|
| 44 | m->setElement(x, y, TERRAIN_OCEAN);
|
---|
| 45 | else
|
---|
| 46 | m->setElement(x, y, TERRAIN_GRASS);
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | return m;
|
---|
| 51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.