-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.cpp
63 lines (56 loc) · 1.28 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
#include "map.hpp"
Map::Map()
: ofs_num(0), space_num(0), wall_num(0), width(0), height(0)
{
}
bool Map::isOutOfSpace(int x, int y)
{
for (int i = 0; i < ofs_num; i++)
{
if (out_of_space[i].getX() == x && out_of_space[i].getY() == y) return true;
}
return false;
}
bool Map::isSpace(int x, int y)
{
for (int i = 0; i < space_num; i++)
{
if (space[i].getX() == x && space[i].getY() == y) return true;
}
return false;
}
bool Map::isWall(int x, int y)
{
for (int i = 0; i < wall_num; i++)
{
if (wall[i].getX() == x && wall[i].getY() == y) return true;
}
return false;
}
bool Map::isDeadEnd(int x, int y)
{
if (isWall(x - 1, y) && isWall(x, y - 1)) return true;
if (isWall(x - 1, y) && isWall(x, y + 1)) return true;
if (isWall(x + 1, y) && isWall(x, y - 1)) return true;
if (isWall(x + 1, y) && isWall(x, y + 1)) return true;
return false;
}
int Map::checkType(int x, int y)
{
if (isOutOfSpace(x, y)) return 0;
else if (isWall(x, y)) return 1;
else return 2;
}
void Map::print()
{
int type;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
type = checkType(i, j);
cout << type << " ";
}
cout << endl;
}
}