Last change
on this file since 60017fc was 62ee2ce, checked in by dportnoy <dmp1488@…>, 12 years ago |
The client shows the map and converts between screen and map coordinates
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[62ee2ce] | 1 | #include "WorldMap.h"
|
---|
[60b77d2] | 2 |
|
---|
| 3 | using namespace std;
|
---|
| 4 |
|
---|
[62ee2ce] | 5 | WorldMap::WorldMap(int width, int height)
|
---|
[60b77d2] | 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 |
|
---|
[62ee2ce] | 22 | WorldMap::~WorldMap()
|
---|
[60b77d2] | 23 | {
|
---|
| 24 | for (int x=0; x<width; x++)
|
---|
| 25 | delete (*vctMap)[x];
|
---|
| 26 |
|
---|
| 27 | delete vctMap;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[62ee2ce] | 30 | WorldMap::TerrainType WorldMap::getElement(int x, int y)
|
---|
| 31 | {
|
---|
| 32 | return (*(*vctMap)[x])[y];
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | void WorldMap::setElement(int x, int y, TerrainType t)
|
---|
[60b77d2] | 36 | {
|
---|
| 37 | (*(*vctMap)[x])[y] = t;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[62ee2ce] | 40 | WorldMap* WorldMap::createDefaultMap()
|
---|
[60b77d2] | 41 | {
|
---|
[62ee2ce] | 42 | WorldMap* m = new WorldMap(12l, 12);
|
---|
[60b77d2] | 43 |
|
---|
[62ee2ce] | 44 | for(int x=0; x<12; x++)
|
---|
[60b77d2] | 45 | {
|
---|
[62ee2ce] | 46 | for(int y=0; y<12; y++)
|
---|
[60b77d2] | 47 | {
|
---|
[62ee2ce] | 48 | if (x ==0 || y == 0 || x == 11 || y == 11)
|
---|
[60b77d2] | 49 | m->setElement(x, y, TERRAIN_OCEAN);
|
---|
| 50 | else
|
---|
| 51 | m->setElement(x, y, TERRAIN_GRASS);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[62ee2ce] | 55 | m->setElement(5, 5, TERRAIN_ROCK);
|
---|
| 56 |
|
---|
[60b77d2] | 57 | return m;
|
---|
| 58 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.