-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cpp
71 lines (58 loc) · 1.52 KB
/
Map.cpp
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
#include "Map.h"
Map::Map()
{
//Tile test;
//test.setExplored(true);
// MapArray[0][0] = test;
tileptr= getTilePtr(0,0);
createMap();
}
void Map::createMap()
{
//setTop and Bottom
//Directions north(true, false, false, false);
//Directions south(false, true, false,false);
//Directions east(false, false, true,false);
//Directions west(false, false, false,true);
for (int i = 0; i< MAP_SIZE; i++)
{
//setNorth
tileptr= getTilePtr(i,0);
tileptr->setNorth(true);
//setSouth
tileptr= getTilePtr(i , MAP_SIZE-1);
tileptr->setSouth(true);
//setEast
tileptr= getTilePtr(0,i);
tileptr->setWest(true);
//setWest
tileptr= getTilePtr(MAP_SIZE-1, i);
tileptr->setEast(true);
}
Point p;
for (short i=0; i<MAP_SIZE; i++){
//saved here to save on function call and cpu usage....
p.setX(i);
for(short j =0; j<MAP_SIZE; j++){
tileptr =getTilePtr(i, j);
p.setY(j);
tileptr->setLocation(p);
}
}
}
Tile* Map::getTilePtr(Point p)
{
//pass back address of element
tileptr= &MapArray[p.getX()][p.getY()];
return tileptr;
}
Tile* Map::getTilePtr(short x, short y)
{
if (x <0) x=0;
if (y<0) y =0;
if (x>MAP_SIZE) x=MAP_SIZE;
if (y>MAP_SIZE) y=MAP_SIZE;
//pass back address of element
tileptr= &MapArray[x][y];
return tileptr;
}