-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaze.html
More file actions
213 lines (206 loc) · 5.74 KB
/
maze.html
File metadata and controls
213 lines (206 loc) · 5.74 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>迷宫</title>
<link rel="stylesheet" type="text/css" href="css/maze.css">
<link rel="stylesheet" type="text/css" href="font/iconfont.css">
<script type="text/javascript" src="js/maze/maze.js"></script>
<script type="text/javascript" src="js/maze/maze-map.js"></script>
<style type="text/css">
.action-bar{
display: flex;
width: 100%;
height: 30px;
border-top: 1px solid #0d859d;
border-bottom: 1px solid #0d859d;
}
.action-bar > div{
display: flex;
align-items: center;
}
.button{
cursor: pointer;
margin: 0 5px;
color: #00D5FF;
}
.bar-left{
flex: 1;
}
.bar-right{
justify-content: center;
width: 50px;
}
.button:active{
color: #0A98B4;
}
.action-filter{
height: 60px;
font-size: 12px;
transition: all 0.2s linear;
}
.filter-column{
display: flex;
align-items: baseline;
cursor: pointer;
margin: 3px 5px;
}
.column-title{
padding: 3px 5px;
background-color: #00D5FF;
color: #FFF;
font-weight: 700;
border-radius: 2px;
}
.column-item{
margin: 0 5px;
}
.active > .iconfont{
color: #00D5FF;
}
.split-line{
width: 1px;
height: 15px;
background-color: #aeaeae;
}
</style>
</head>
<body>
<div class="box">
<div class="action">
<div class="action-bar">
<div class="bar-left">
<div class="button iconfont icon-play"></div>
<div class="button iconfont icon-refresh"></div>
<div class="button iconfont icon-clear"></div>
<div class="split-line"></div>
<div class="button iconfont icon-sub"></div>
<div class="button iconfont icon-add"></div>
<div class="split-line"></div>
<div class="button iconfont icon-find"></div>
</div>
<div class="bar-right">
<div class="button iconfont icon-filter" style="color: #759095"></div>
</div>
</div>
<div class="action-filter">
<div class="filter-column source-type">
<div class="column-title">数据生成</div>
<div class="column-item active" data-value="1">
<span class="iconfont icon-radio"></span>
<span>增强随机</span>
</div>
<div class="column-item" data-value="2">
<span class="iconfont icon-radio"></span>
<span>随机</span>
</div>
<div class="column-item" data-value="3">
<span class="iconfont icon-radio"></span>
<span>栈</span>
</div>
<div class="column-item" data-value="4">
<span class="iconfont icon-radio"></span>
<span>队列</span>
</div>
<div class="column-item" data-value="5">
<span class="iconfont icon-radio"></span>
<span>文件</span>
</div>
</div>
<div class="filter-column solve-type">
<div class="column-title">迷宫求解</div>
<div class="column-item active" data-value="1">
<span class="iconfont icon-radio"></span>
<span>递归-深度优先</span>
</div>
<div class="column-item" data-value="2">
<span class="iconfont icon-radio"></span>
<span>非递归-深度优先</span>
</div>
<div class="column-item" data-value="3">
<span class="iconfont icon-radio"></span>
<span>广度优先</span>
</div>
</div>
</div>
</div>
<div class="maze">
<canvas id="mazeCanvas">浏览器不支持canvas</canvas>
</div>
</div>
<input id="fileSelector" hidden="" style="width:200px" type="file" name="file" value="导入迷宫数据">
<script type="text/javascript">
var maze = new Maze('fileSelector');
var mazeMap = new MazeMap(101,101);
let icon_play = document.querySelector('.icon-play'),
actives = document.querySelectorAll('.column-item'),
icon_find = document.querySelector('.icon-find'),
canvas = document.querySelector('#mazeCanvas'),
filter = document.querySelector('.icon-filter'),
action_filter = document.querySelector('.action-filter'),
fileInput = document.querySelector('#fileSelector'),
icon_file = document.querySelector('.icon-file'),
filter_columns = document.querySelectorAll('.filter-column'),
dataType = 1,
solveType = 1;
// 迷宫绑定画布对象
maze.bindCanvas(mazeMap.n,mazeMap.m,canvas);
actives.forEach((elem,index) => {
elem.onclick = (event) => {
let current = event.currentTarget;
let item = current;
while(item !== null){
item.classList.remove('active');
item = item.nextElementSibling;
}
item = current;
while(item !== null){
item.classList.remove('active');
item = item.previousElementSibling;
}
current.classList.add('active');
if (current.parentElement.classList.contains('source-type')) {
dataType = current.attributes['data-value'].nodeValue;
} else if (current.parentElement.classList.contains('solve-type')) {
solveType = current.attributes['data-value'].nodeValue;
}
dataType = parseInt(dataType);
solveType = parseInt(solveType);
}
});
fileInput.onchange = (event) => {
let files = event.target.files;
let reader = new FileReader();
reader.readAsText(files[0],'UTF-8');
reader.onloadend = (target) => {
maze.mazeText = reader.result
maze.parse2Array();
// 开始绘制地图
maze.createMazeMap();
}
}
filter.onclick = () => {
let height = action_filter.style.height;
if (height === '') {
action_filter.style.height = '0px';
} else {
action_filter.style.height = '';
}
}
icon_play.onclick = () => {
if (dataType === 5) {
fileInput.click();
} else {
// 判断要生成的迷宫的随机性
mazeMap.setRandom(dataType);
mazeMap.draw(canvas);
let data = mazeMap.map;
maze.initMazeData(mazeMap.n,mazeMap.m,data);
}
}
icon_find.onclick = () => {
maze.solveMaze(solveType);
}
</script>
</body>
</html>