blob: ab240351d618241645df502f3eeb2b828b3d03da (
plain)
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
|
#include "Maze.h"
Maze::Maze()
:_width(0),
_height(0)
{
}
void Maze::generateMaze(const vector<pair<int,int> >& walls, int maxObjectX, int maxObjectY)
{
//find bounds so that rectangular vector can be generated
int maxX = maxObjectX;
int maxY = maxObjectY;
for (vector<pair<int,int> >::const_iterator iter = walls.begin(); iter!=walls.end(); ++iter)
{
if (iter->first > maxX) maxX = iter->first;
if (iter->second > maxY) maxY = iter->second;
}
_width = maxX+1; //need to convert from highest index to required size
_height = maxY+1;
_wallLocations.clear();
for (int x=0; x<_width; ++x)
{
_wallLocations.push_back(vector<bool>());
for (int y=0; y<_height; ++y)
{
_wallLocations.back().push_back(false);
}
}
for (vector<pair<int,int> >::const_iterator iter = walls.begin(); iter!=walls.end(); ++iter)
{
_wallLocations.at(iter->first).at(iter->second) = true;
}
}
bool Maze::getSolid(const int& x, const int& y) const
{
if (x<0 || y<0) return true;
if (x>=width() || y>=height()) return true;
//bounds have already been checked, can use more efficient, less safe, indexing
return _wallLocations[x][y];
}
int Maze::width() const
{
return _width;
}
int Maze::height() const
{
return _height;
}
Maze::Direction Maze::backwards(Direction forwards)
{
Direction backwards;
switch (forwards)
{
case LEFT:
backwards = RIGHT;
break;
case RIGHT:
backwards = LEFT;
break;
case UP:
backwards = DOWN;
break;
case DOWN:
backwards = UP;
break;
}
return backwards;
}
|