-
Notifications
You must be signed in to change notification settings - Fork 3
/
tetris.html
85 lines (67 loc) · 1.63 KB
/
tetris.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
<html>
<head>
<title>Tetris</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var websocket;
function start() {
websocket = new WebSocket('ws://192.168.29.161:81/');
websocket.onopen = function(evt) { console.log('websocket open'); websocket.send("new"); };
websocket.onclose = function(evt) { console.log('websocket close'); };
websocket.onerror = function(evt) { console.log(evt); };
}
</script>
</head>
<body>
<center><h1>Tetris</h1></center>
<button id="new">NEW Game</button>
<button id="left">Left (Cursor Left)</button>
<button id="right">Right (Cursor Right)</button>
<button id="turnl">Rotate Left (Down)</button>
<button id="turnr">Rotate Right (Up)</button>
<script>
$("#new").click(function(){
websocket.send("new");
});
$("#left").click(function(){
websocket.send("left");
});
$("#right").click(function(){
websocket.send("right");
});
$("#new").click(function(){
websocket.send("new");
});
$("#turnr").click(function(){
websocket.send("turnr");
});
$("#turnl").click(function(){
websocket.send("turnl");
});
$( document ).ready(function(){
console.info("Ready");
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
// up arrow
websocket.send("turnr");
}
else if (e.keyCode == '40') {
// down arrow
websocket.send("turnl");
}
else if (e.keyCode == '37') {
// left arrow
websocket.send("left");
}
else if (e.keyCode == '39') {
// right arrow
websocket.send("right");
}
}
start();
} );
</script>
</body>
</html>