-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
141 lines (124 loc) · 3.42 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
138
139
140
141
<html>
<head>
<link rel="stylesheet" href="files/css/style.css"/>
<script src="files/js/jquery.js"></script>
<script>
isWumpusDead = false;
isShooting = false;
</script>
<script src="files/js/cell.js"></script>
<script src="files/js/wumpus.js"></script>
</head>
<body>
<table class="pboard">
<tbody>
<tr class="row4">
<td class="cell14"></td>
<td class="cell24"></td>
<td class="cell34"></td>
<td class="cell44"></td>
</tr>
<tr class="row3">
<td class="cell13"></td>
<td class="cell23"></td>
<td class="cell33"></td>
<td class="cell43"></td>
</tr>
<tr class="row2">
<td class="cell12"></td>
<td class="cell22"></td>
<td class="cell32"></td>
<td class="cell42"></td>
</tr>
<tr class="row1">
<td class="cell11"></td>
<td class="cell21"></td>
<td class="cell31"></td>
<td class="cell41"></td>
</tr>
</tbody>
</table>
<table class="mboard">
<tbody>
<tr class="row4">
<td class="cell14"></td>
<td class="cell24"></td>
<td class="cell34"></td>
<td class="cell44"></td>
</tr>
<tr class="row3">
<td class="cell13"></td>
<td class="cell23"></td>
<td class="cell33"></td>
<td class="cell43"></td>
</tr>
<tr class="row2">
<td class="cell12"></td>
<td class="cell22"></td>
<td class="cell32"></td>
<td class="cell42"></td>
</tr>
<tr class="row1">
<td class="cell11"></td>
<td class="cell21"></td>
<td class="cell31"></td>
<td class="cell41"></td>
</tr>
</tbody>
</table>
<div style="position: absolute; top: 440px;">
<button onclick="location.reload();">Restart Game</button>
</div>
<div style="position: absolute; top: 470px;">
<button id="startGame">Start Game</button>
</div>
<div style="position: absolute; top: 500px;">
<p id="points">Points: 0</p>
</div>
<div style="position: absolute; top: 530px; color: red;">
<p id="status"></p>
</div>
</body>
<script>
$(document).ready(function () {
wumpus = new Wumpus();
wumpus.reStart();
$(window).keypress(function (e) {
if (e.keyCode === 0 || e.keyCode === 32) {
e.preventDefault();
//console.log(JSON.stringify(wumpus));
var dir = wumpus.move();
wumpus.handMove(dir);
}
});
var timer = function () {
if (!wumpus.gameOver) {
var dir = wumpus.move();
wumpus.handMove(dir);
}
};
$("#startGame").click(function () {
setInterval(timer, 800);
});
});
$(document).keydown(function (e) {
switch (e.which) {
case 37: // left
wumpus.handMove(wumpus.Moves.Left);
break;
case 38: // up
wumpus.handMove(wumpus.Moves.Up);
break;
case 39: // right
wumpus.handMove(wumpus.Moves.Right);
break;
case 40: // down
wumpus.handMove(wumpus.Moves.Down);
break;
default:
return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
</script>
</html>