-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaze.cpp
154 lines (137 loc) · 13.1 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <vector>
#include "maze.h"
#include "person.h"
#include "terminal.h"
#include "config.h"
using namespace std;
/* 地图的定义 */
vector< vector< vector<int> > > Maze::mazeMap = {
{{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL},
{ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL},
//{ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD},
{WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD},
{WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL},
{WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL},
{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL}},
{{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL},
{ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL},
//{ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD},
{WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, WALL, WALL},
{WALL, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL},
{WALL, ROAD, ROAD, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL},
{WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD},
{WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL},
{WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, ROAD, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, WALL},
{WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL},
{WALL, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL},
{WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL},
{WALL, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL},
{WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, ROAD, WALL, ROAD, WALL, WALL},
{WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL},
{WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL}},
{{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL},
{ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL},
//{ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD},
{WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL},
{WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL},
{WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, WALL, ROAD, ROAD, WALL},
{WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL},
{WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL},
{WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, WALL},
{WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL},
{WALL, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL},
{WALL, WALL, ROAD, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, ROAD, WALL, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD},
{WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, ROAD, ROAD, WALL, WALL},
{WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, ROAD, ROAD, WALL, ROAD, WALL},
{WALL, WALL, WALL, WALL, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL, WALL, ROAD, WALL, ROAD, WALL, WALL, WALL, WALL, WALL, ROAD, WALL},
{WALL, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL, WALL, ROAD, WALL, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, ROAD, WALL},
{WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL, WALL}}
};
Maze::Maze() {
m_iWallColor = m_iRoadColor = 0;
m_iMap = 0;
m_iWidth = MAZEMAP_WIDTH;
m_iHeight = MAZEMAP_HEIGHT;
}
void Maze::setWallColor(const int _wall_color) {
m_iWallColor = _wall_color;
}
void Maze::setRoadColor(const int _road_color) {
m_iRoadColor = _road_color;
}
void Maze::setMap(const int _map) {
m_iMap = _map;
}
int Maze::getWallColor() const {
return m_iWallColor;
}
int Maze::getRoadColor() const {
return m_iRoadColor;
}
int Maze::getMap() const {
return m_iMap;
}
/* 打印地图 */
void Maze::printSelf() const {
int anchX = getAnch_x();
int anchY = getAnch_y();
for (int row = 0; row < mazeMap[this->m_iMap].size(); row++) {
for (int col = 0; col < mazeMap[this->m_iMap][row].size(); col++) {
Terminal::gotoPoint(col + anchX, row + anchY);
if (mazeMap[this->m_iMap][row][col] == WALL) {
Terminal::colorPrint(" ", m_iWallColor);
} else if (mazeMap[this->m_iMap][row][col] == ROAD) {
Terminal::colorPrint(" ", m_iRoadColor);
}
}
}
}
/* 检查指定坐标在地图上的位置状态 */
int Maze::checkPoint(int _x, int _y) const {
if (_y < 0 || _y >= mazeMap[this->m_iMap].size()
|| _x < 0 || _x >= mazeMap[this->m_iMap][_y].size()) {
return MAP_OUT;
} else if (WALL == mazeMap[this->m_iMap][_y][_x]) {
return MAP_NO;
} else {
return MAP_YES;
}
}
//下一个地图
bool Maze::nextMap() {
m_iMap++;
if (mazeMap.size() == m_iMap) {
m_iMap = 0;
return false;
}
reset();
return true;
}
void Maze::reset() {
for (auto &i : *m_pChilds) {
((Person *)i)->init();
}
}
//地图初始化
void Maze::init() {
reset();
m_iMap = 0;
}