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
|
Line | |
---|
1 | #include "WorldMap.h"
|
---|
2 |
|
---|
3 | using namespace std;
|
---|
4 |
|
---|
5 | WorldMap::WorldMap(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 | WorldMap::~WorldMap()
|
---|
23 | {
|
---|
24 | for (int x=0; x<width; x++)
|
---|
25 | delete (*vctMap)[x];
|
---|
26 |
|
---|
27 | delete vctMap;
|
---|
28 | }
|
---|
29 |
|
---|
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)
|
---|
36 | {
|
---|
37 | (*(*vctMap)[x])[y] = t;
|
---|
38 | }
|
---|
39 |
|
---|
40 | WorldMap* WorldMap::createDefaultMap()
|
---|
41 | {
|
---|
42 | WorldMap* m = new WorldMap(12l, 12);
|
---|
43 |
|
---|
44 | for(int x=0; x<12; x++)
|
---|
45 | {
|
---|
46 | for(int y=0; y<12; y++)
|
---|
47 | {
|
---|
48 | if (x ==0 || y == 0 || x == 11 || y == 11)
|
---|
49 | m->setElement(x, y, TERRAIN_OCEAN);
|
---|
50 | else
|
---|
51 | m->setElement(x, y, TERRAIN_GRASS);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | m->setElement(5, 5, TERRAIN_ROCK);
|
---|
56 |
|
---|
57 | return m;
|
---|
58 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.