-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
137 lines (118 loc) · 3 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>PathFinder.js | j8n.github.io</title>
<style>
*{
padding: 0;
margin: 0;
font-weight: 400;
}
body {
overflow: hidden;
}
.bar {
margin: 2px 0;
height: auto;
}
#find-path-button {
position: fixed;
right: 0;
bottom: 0;
padding: 15px 45px;
margin: 8px;
cursor: pointer;
display: inline-block;
background-color: #808080;
font-size: 20px;
z-index: 50;
color: #ffffff;
}
#panel {
position: fixed;
width: auto;
height: auto;
background-color: #808080;
z-index: 50;
margin: 8px;
color: #ffffff;
padding: 5px;
}
</style>
<script type="text/javascript" src="src/PathFinder.js"></script>
<script type="text/javascript" src="src/PathModeller.js"></script>
<script type="text/javascript" src="src/Box.js"></script>
<script type="text/javascript" src="src/Map.js"></script>
</head>
<body>
<div id="find-path-button" onclick="Find();">Find Path</div>
<div id="panel">
Right click on a white grid to place wall.<br>
Left click to set <span style="color: #ff0000;">start position</span> <br>
and <span style="color: #00f050;">end position</span>.<br>
<div id="info"></div>
</div>
<script>
function printInfoBox(x, y, w){
//return;
theInfoBox.innerHTML = "";
theInfoBox.innerHTML += "x: "+x;
theInfoBox.innerHTML += "<br>";
theInfoBox.innerHTML += "y: "+y;
theInfoBox.innerHTML += "<br>";
theInfoBox.innerHTML += "is wall: "+!w;
theInfoBox.innerHTML += "<br>";
return;
if(startBox === null){return}
theInfoBox.innerHTML += "startBox x: "+startBox.x;
theInfoBox.innerHTML += "<br>";
theInfoBox.innerHTML += "startBox y: "+startBox.y;
theInfoBox.innerHTML += "<br>";
if(endBox === null){return}
theInfoBox.innerHTML += "endBox x: "+endBox.x;
theInfoBox.innerHTML += "<br>";
theInfoBox.innerHTML += "endBox y: "+endBox.y;
theInfoBox.innerHTML += "<br>";
}
function Find(){
if(startBox === null || endBox === null){
return;
}
var path = thePathFinder.FindPath([startBox.x, startBox.y], [endBox.x, endBox.y]);
thePathModeller.showPathOnMap(path);
startBox = null;
endBox = null;
}
var RightIsDown = false;
var _BoxSide = 30;
var theMap = null;
var theInfoBox = null;
var thePathFinder = null;
var thePathModeller = null;
var findPathButton = null;
var startBox = null;
var endBox = null;
window.onload = function(){
var w = window.innerWidth / _BoxSide + 1;
var h = window.innerHeight / _BoxSide + 1;
theInfoBox = document.getElementById("info");
theMap = new Map(w, h);
thePathFinder = new PathFinder(theMap.boxes);
thePathModeller = new PathModeller(thePathFinder);
}
document.body.oncontextmenu = function(e){
e.preventDefault();
}
document.body.onmousedown = function(e){
if(e.button === 2){
RightIsDown = true;
}
}
document.body.onmouseup = function(e){
if(e.button === 2){
RightIsDown = false;
}
}
</script>
</body>
</html>