-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
124 lines (107 loc) · 3.74 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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Such a maze</title>
<style>
body {
margin: 10px;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<!-- width/height of 500 = 25x25 grid with 20 px cell widths. -->
<canvas id="mazeCanvas" width="500" height="590"></canvas>
<script src="mazeCreator.js"></script>
<script>
var canvas = document.getElementById('mazeCanvas');
var ctx = canvas.getContext('2d');
var cellWidth = 20;
var amaze = MazeCreator(25, 25);
amaze.create();
amaze.drawMazeGrid(ctx, cellWidth);
drawInstructions();
canvas_arrow(ctx, 0, 0, 100, 100);
window.addEventListener('keydown',processKeyDown,true);
function processKeyDown(event) {
// up arrow
if (event.keyCode == 38) {
console.log("move up");
amaze.moveNorth();
// right arrow
} else if (event.keyCode == 39) {
amaze.moveEast();
console.log("move right")
// down arrow
} else if (event.keyCode == 40) {
amaze.moveSouth();
console.log("move down");
// left arrow
} else if (event.keyCode == 37) {
amaze.moveWest();
console.log("move left");
// spacebar
} else if (event.keyCode == 32) {
amaze.resetStart();
// 'b'
} else if (event.keyCode == 66) {
console.log("adding breadcrumb");
amaze.toggleBreadcrumb();
// 'g'
} else if (event.keyCode == 71) {
console.log("toggling ghost mode");
amaze.toggleGhostMode();
// 'h'
} else if (event.keyCode == 72) {
console.log("toggling hint mode");
amaze.toggleHintMode();
// 'n'
} else if (event.keyCode == 78) {
console.log("new map");
amaze.create();
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (!amaze.solved()) {
amaze.drawMazeGrid(ctx, cellWidth);
drawInstructions();
} else {
var x = canvas.width / 2 - 30;
var y = 40;
ctx.font = '30pt Helvetica';
ctx.textAlign = 'center';
ctx.fillStyle = 0xCC6600;
ctx.fillText('Such amaze!', x, y);
var imageObj = new Image();
imageObj.src = 'doge_20store_original.jpg';
imageObj.onload = function() {
ctx.drawImage(imageObj, 40, 50, 350, 500);
};
}
};
function canvas_arrow(ctx, fromx, fromy, tox, toy) {
var headlen = 10; // length of head in pixels
var angle = Math.atan2(toy - fromy, tox - fromx);
ctx.moveTo(fromx, fromy);
ctx.lineTo(tox, toy);
ctx.lineTo(tox - headlen * Math.cos(angle - Math.PI / 6),
toy - headlen * Math.sin(angle - Math.PI / 6));
ctx.moveTo(tox, toy);
ctx.lineTo(tox - headlen * Math.cos(angle + Math.PI / 6),
toy - headlen * Math.sin(angle + Math.PI / 6));
}
function drawInstructions() {
var x = canvas.width / 2;
var y = canvas.height - 50;
ctx.font = '12pt Helvetica';
ctx.textAlign = 'center';
ctx.fillStyle = 'black';
ctx.fillText("Bring the ball to the square.", x, y);
ctx.fillText("Press \'space\' to reset location.", x, y + 20);
ctx.fillText("n: new, h: hint, b: breadcrumb", x, y + 40);
};
</script>
</body>
</html>