-
Notifications
You must be signed in to change notification settings - Fork 1
/
maze.cpp
68 lines (60 loc) · 1.51 KB
/
maze.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
#include "maze.h"
#include <iostream>
Point::Point(int x_, int y_)
: x(x_), y(y_)
{}
Point Point::operator +(const Point &right)
{
return Point(x + right.x, y+right.y);
}
Maze::Maze():
maxWidth(0)
{
}
void Maze::addLine(std::string str)
{
map.push_back(str);
maxWidth = max(maxWidth, str.size());
}
bool Maze::getValue(Point position)
{
if (position.x < 0 || position.x > maxWidth)
return false;
if (position.y < 0 || position.y > map.size())
return false;
return map[position.y][position.x] != ' ';
}
bool floatEqual(float value, float reference)
{
return fabs(value-reference) < 0.1;
}
void Maze::printMaze(Point mark, float direction)
{
for (unsigned int i =0; i< map.size();i++)
{
if (i != mark.y)
cout << map[i].c_str() << endl;
else
{
for (unsigned int j =0; j < map[i].size(); j++)
{
if (j!=mark.x)
cout << map[i][j];
else
{
if (floatEqual(direction, 0))
cout << 'v';
else if (floatEqual(direction, M_PI/2))
cout << '>';
else if (floatEqual(direction, M_PI))
cout << '^';
else if (floatEqual(direction, M_PI*3/2))
cout << '<';
else
cout << '*';
}
}
cout << endl;
}
}
}