-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaze.cpp
81 lines (68 loc) · 1.49 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
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Maze.h"
Maze::Maze(const std::string &a_path)
{
std::ifstream fin;
fin.open(a_path);
std::string line;
// вычисляем размеры лабиринта
int h = 0, t = 0;
while(std::getline(fin, line))
data.push_back(line);
width = data[0].length();
height = data.size();
fin.close();
}
Map Maze::Next_room(int door_number)
{
bool* doors = new bool[4];
switch(door_number)
{
case 50:
current.y -= 1;
break;
case 60:
current.x -= 1;
break;
case 70:
current.x += 1;
break;
case 80:
current.y += 1;
break;
default:
break;
}
char c = data[current.y][current.x];
if(current.y == 0)
doors[0] = 0;
else
{
if(data[current.y - 1][current.x] != '.')
doors[0] = 1;
else
doors[0] = 0;
}
if(current.x == 0)
doors[1] = 0;
else
{
if(data[current.y][current.x - 1] != '.')
doors[1] = 1;
else
doors[1] = 0;
}
if(data[current.y + 1][current.x] != '.')
doors[3] = 1;
else
doors[3] = 0;
if(data[current.y][current.x + 1] != '.')
doors[2] = 1;
else
doors[2] = 0;
std::string s(1, c);
std::string path = "./resources/maps/" + s;
path += ".txt";
Map res(path, doors);
res.Make_prop();
return res;
}