-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.html
More file actions
131 lines (117 loc) · 2.93 KB
/
controller.html
File metadata and controls
131 lines (117 loc) · 2.93 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no, minimal-ui">
<title>Clean Controls</title>
<style>
body {
margin: 0;
color: white;
font-size: xx-large;
font-weight: bold;
font-family: sans-serif;
}
.card {
width: 30vw;
height: 30vh;
margin-top: 10vh;
margin-bottom: 10vh;
margin-left: 10vw;
margin-right: 10vw;
float: left;
}
#blue {
background-color: rgb(28,0,128);
}
#red {
background-color: rgb(128,12,0);
}
#yellow {
background-color: rgb(128,108,0);
}
#grey {
background-color: DarkGray
}
</style>
</head>
<body>
<input type="text" id="name">Name here </input>
<div class="card" id="blue">
</div>
<div class="card" id="red">
</div>
<div class="card" id="yellow">
</div>
<div class="card" id="grey">
</div>
</body>
<!--
The following script line includes happyfuntimes which defines HFT.
You could also use require.js or webpack etc...
-->
<script src="/node_modules/happyfuntimes/dist/hft.js"></script>
<script>
// Connect to the game
const client = new HFT.GameClient();
client.on('connect', handleConnect);
client.on('disconnect', handleDisconnect);
client.on('color', handleColor);
client.on('dead', handleDead);
client.on('turn', handleTurnGiven);
let points = 0;
let hand = []
let turn = true;
function handleConnect() {
// nothing to do here though maybe we don't want to
// send any touch events until we've connected for example.
}
function handleDisconnect() {
touchArea.textContent = "...disconnected...";
}
function handleColor(color) {
document.body.style.backgroundColor = color;
}
function handleTurnGiven() {
turn = true;
}
function handleDead() {
//you're dead
}
const blueButton = document.querySelector('#blue');
const redButton = document.querySelector('#red');
const greyButton = document.querySelector('#grey');
const yellowButton = document.querySelector('#yellow');
const nameInput = document.querySelector('#name');
nameInput.addEventListener('change', (event) => sendName(event))
blueButton.addEventListener('touchstart', () => sendColor('blue'))
redButton.addEventListener('touchstart', () => sendColor('red'))
greyButton.addEventListener('touchstart', () =>sendColor('grey'))
yellowButton.addEventListener('touchstart',() => sendColor('yellow'))
function sendColor(color) {
if (turn){
turn = false;
switch (color) {
case 'blue' :
client.sendCmd('pickColor', 0)
break;
case 'red' :
client.sendCmd('pickColor', 1)
break;
case 'yellow' :
client.sendCmd('pickColor', 2)
break;
case 'grey' :
client.sendCmd('pickColor', 3)
break;
}
}
}
function sendEvent(event) {
client.sendCmd('clickEvent', event.type)
}
function sendName(event) {
client.sendCmd('setName', event.target.value);
}
</script>
</html>