-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.html
162 lines (156 loc) · 6.65 KB
/
host.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<title>Host | Buzzer</title>
<link rel='stylesheet' href='css/host.css' />
<script src='bower_components/jquery/dist/jquery.min.js'></script>
<script src='node_modules/socket.io-client/socket.io.js'></script>
<script src='modernizr-custom.js'></script>
<script>
var socket = io('/host');
var guessingPlayer;
var ready = false;
var chosenButton;
var wrongPlayers = [];
$(document).ready(function() {
if(!Modernizr.inputtypes.color){
$('#colorChooser, label[for="colorChooser"]').hide();
}
$('body').on('submit', '#settings', function(e){
e.preventDefault();
chosenButton = {
class: $('input[name="type"]:checked + label > .choice > div').attr('class').split(' ')[0],
color: $('#colorChooser').val()
};
$('#settings').fadeOut().promise().then(function(){
$('#roomContainer, #startButton').fadeIn();
}).then(function(){
$('#playerList').show();
});
return false;
});
$('body').on('click', '#startButton', function(){
$('#roomContainer').css({
'font-size': '1em',
'top': '0', //20
'right': '0', //50
'transform': 'translate(0,0)'
});
$('#startButton').css('visibility','hidden');
ready = true;
});
$('body').on('click', '.responseButton', function() {
$("#buttons").hide();
$("#continueButton").show();
$('.active').removeClass('active')
var p = $(document.getElementById(guessingPlayer));
if ($(this).attr('id') == 'correct') {
socket.emit('success', guessingPlayer);
p.addClass('success');
p.children('.cScore').text(parseInt(p.children('.cScore').text())+1);
} else {
socket.emit('failure', guessingPlayer);
p.addClass('failure');
p.children('.iScore').text(parseInt(p.children('.iScore').text())+1);
if($('.failure').length < $('#playerList .player').length) $('#guessAgainButton').show();
}
});
$('body').on('click', '#continueButton', function() {
$("#continueButton").hide();
$("#guessAgainButton").hide();
$('#playerList .player').removeClass('success').removeClass('failure');
ready = true;
wrongPlayers = [];
guessingPlayer = '';
socket.emit('continue', true);
});
$('body').on('click', '#guessAgainButton', function() {
$("#continueButton").hide();
$("#guessAgainButton").hide();
wrongPlayers.push(guessingPlayer);
ready = true;
guessingPlayer = '';
});
$('#colorChooser').on('change', function(){
$('.dot, .square').css('background-color', $(this).val());
});
socket.on('playerJoin', function(id, name) {
$('#playerList').append('<tr class="player" id='+id+'><td>'+name+'</td><td class="cScore">0</td><td class="iScore">0</td></tr>')
socket.emit('setButton', chosenButton);
});
socket.on('playerLeave', function(id) {
$(document.getElementById(id)).remove();
if (id == guessingPlayer) {
$("#buttons").hide();
$("#continueButton").hide();
ready = true;
}
});
socket.on('playerGuess', function(id) {
if (ready && wrongPlayers.indexOf(id) == -1) {
$(document.getElementById(id)).addClass('active');
$('#buttons').show();
guessingPlayer = id;
socket.emit('acceptedGuess', id);
ready = false;
}
});
socket.on('roomID', function(room) {
$('#room').text(room);
});
});
//give host ability to customize buttons and sound
//body background semitransparent when room number is over it
//clicking room in corner puts it large in the center
// with the body background semitransparent
</script>
</head>
<body>
<div class='content'>
<div id='roomContainer'>
<span id='room'></span>
<button id='startButton'>Start Game</button>
</div>
<form id='settings' class='center' target="_blank">
<fieldset>
<legend>Button Type:</legend>
<input type='radio' name='type' id='dot' checked/>
<label for='dot'><div class='choice'>
<div class='dot center'></div>
</div>Circle</label>
<input type='radio' name='type' id='square'/>
<label for='square'><div class='choice'>
<div class='square center'></div>
</div>Square</label>
<input type='radio' name='type' id='bell'/>
<label for='bell'><div class='choice'>
<div class='bell center'></div>
</div>Bell</label>
<input type='radio' name='type' id='full'/>
<label for='full'><div class='choice'>
<div class='screen'></div>
</div>Screen</label>
<br />
<label class='checkInput' for='colorChooser'>Choose Color:</label>
<input class='checkInput' type='color' value='#7F007F' name='colorChooser' id='colorChooser'/>
</fieldset>
<input type='submit' value='Create Room' />
</form>
<div id="buttons">
<button id="correct" class='responseButton'>Correct</button>
<button id="incorrect" class='responseButton'>Incorrect</button>
</div>
<button id='continueButton'>Continue</button>
<button id='guessAgainButton'>Allow More Guesses</button>
<table id='playerList'>
<tr>
<th>Name</th>
<th>Correct</th>
<th>Incorrect</th>
</tr>
</table>
</div>
</body>
</html>