-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRockPaperScissorsJS.html
More file actions
99 lines (83 loc) · 2.89 KB
/
RockPaperScissorsJS.html
File metadata and controls
99 lines (83 loc) · 2.89 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
<!DOCTYPE html>
<!------------------------------------------------------------------------------
| Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. |
| Leap Motion proprietary and confidential. Not for distribution. |
| Use subject to the terms of the Leap Motion SDK Agreement available at |
| https://developer.leapmotion.com/sdk_agreement, or another agreement |
| between Leap Motion and you, your company or other organization. |
------------------------------------------------------------------------------->
<html>
<head>
<title>Rock Paper Scissors Demo</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Montserrat:700">
<link rel="stylesheet" type="text/css" href="main.css">
<script type="text/javascript" src="LeapHelper.js"></script>
<script type="text/javascript" src="RockPaperScissors.js"></script>
<script>
var ws;
// Support both the WebSocket and MozWebSocket objects
if ((typeof(WebSocket) == 'undefined') &&
(typeof(MozWebSocket) != 'undefined')) {
WebSocket = MozWebSocket;
}
// Create the socket with event handlers
function init() {
//Create and open the socket
ws = new WebSocket("ws://localhost:6437/");
// On successful connection
ws.onopen = function(event) {
document.getElementById("main").style.visibility = "visible";
document.getElementById("connection").innerHTML = "WebSocket connection open!";
// init RPS engine
rps.init();
};
// On message received
ws.onmessage = function(event) {
var obj = JSON.parse(event.data);
var str = JSON.stringify(obj, undefined, 2);
// pass the actual frame to the helper
if( rps )
{
rps.lh.setFrame( obj );
}
/*
// debug data
lh.log( 'Hands count', lh.getHandscount() );
lh.log( 'Pointable count', lh.getPointablecount() );
lh.log( 'Pointable count by hand', JSON.stringify( lh.getPointableCountByHand(), undefined, 2 ) );
lh.log( 'Raw frame', str );
*/
};
// On socket close
ws.onclose = function(event) {
ws = null;
document.getElementById("main").style.visibility = "hidden";
document.getElementById("connection").innerHTML = "WebSocket connection closed";
}
//On socket error
ws.onerror = function(event) {
alert("Received error");
};
}
rps = new RockPaperScissors();
RockPaperScissors.ANSWER_TIME_OUT = 900;
RockPaperScissors.NEXTROUND_TIME_OUT = 4000;
RockPaperScissors.MOVEMENT_CATCH_COUNT = 4;
// forms
RockPaperScissors.ROCK = 0;
RockPaperScissors.PAPER = 1;
RockPaperScissors.SCISSORS = 2;
// State machine controls
RockPaperScissors.MODE_READY = 0;
RockPaperScissors.MODE_321 = 1;
RockPaperScissors.MODE_LISTEN = 2;
RockPaperScissors.MODE_EVALUATE = 3;
</script>
</head>
<body onload="init();">
<div id="connection" style="display:block;">WebSocket not connected</div>
<div id="main" style="visibility:hidden">
<div id="output"></div>
</div>
</body>
</html>