-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.html
140 lines (131 loc) · 5.81 KB
/
admin.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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Jeopardy Admin</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="main">
<div id="jeopardy-table" style="height: 70%;"></div>
<div class="admin-controls">
<button id="correct-answer">Correct answer</button>
<button id="wrong-answer">Wrong answer</button>
<button id="pass">Pass</button>
<button id="play">Play music</button>
<button id="test">Start beeper test</button>
<button id="double" style="float: right; display: none;">Double Jeopardy!</button>
<button id="final" style="float: right; display: none;">Final Jeopardy!</button>
</div>
<div class="admin-controls">
<p id="question" class="admin-question"></p>
<p id="answer" class="admin-answer"></p>
</div>
</div>
<script src="socket.io.min.js"></script>
<script src="jquery-3.3.1.min.js"></script>
<script src="main.js"></script>
<script>
$(function () {
var socket = io();
var last_status;
var questions;
createTable("#jeopardy-table");
for (let cat = 0; cat < 6; cat++) {
$("#cell-cat-" + cat).click(function () {
socket.emit('admin', { cmd: 'show-category', category: cat});
});
for (let row = 0; row < 5; row++) {
let question = row + "-" + cat;
$("#question-" + question).click(function () {
socket.emit('admin', { cmd: 'select-question', question: question });
});
}
}
for (let player = 0; player < 3; player++) {
$("#player-cell-" + player).click(function (event) {
if (last_status == null) {
return;
}
if (last_status.dailyDoubles.includes(last_status.phase + "-" + last_status.activeQuestion) ||
last_status.phase == 3 && !last_status.alreadyAnswered[player]) {
let score = prompt("Please type the selected bet!", "");
if (score != null && score != "") {
socket.emit('admin', { cmd: 'select-player', player: player, amount: score });
}
}
if (event.altKey) {
let score = prompt("Change " + last_status.players[player] +"'s score to: ", "");
if (score != null && score != "") {
socket.emit('admin', { cmd: 'change-score', player: player, score: score });
}
}
});
}
$.get('/questions', function(data) {
questions = JSON.parse(data);
});
$("#correct-answer").click(function () {
socket.emit('admin', { cmd: 'answer', correct: true });
});
$("#wrong-answer").click(function () {
socket.emit('admin', { cmd: 'answer', correct: false });
});
$("#pass").click(function () {
socket.emit('admin', { cmd: 'pass' });
});
$("#play").click(function () {
socket.emit('sound', 'jeopardy');
})
$("#test").click(function () {
socket.emit('admin', { cmd: 'test' });
})
$("#double").click(function () {
socket.emit('admin', { cmd: 'double' })
});
$("#final").click(function () {
socket.emit('admin', { cmd: 'final' })
});
socket.on('status', function (status) {
last_status = status;
updateTable(status);
$("#correct-answer").prop('disabled', status.answeringPlayer == null);
$("#wrong-answer").prop('disabled', status.answeringPlayer == null);
$("#pass").prop('disabled', status.activeQuestion == null || status.answeringPlayer != null);
$("#test").prop('disabled', status.answeredQuestions.length != 0 || status.activeQuestion != null);
if (status.test) {
$("#test").text('End beeper test');
} else {
$("#test").text('Start beeper test');
}
if (status.phase == 1) {
$("#double").show();
$("#final").hide();
} else if (status.phase == 2) {
$("#double").hide();
$("#final").show();
} else {
$("#double").hide();
$("#final").hide();
}
var question = null;
if (status.activeQuestion) {
let row = status.activeQuestion[0];
let cat = status.activeQuestion[2];
question = questions[status.phase - 1][cat][row];
} else if (status.phase == 3) {
var question = questions[status.phase - 1];
}
try {
$("#question").text(question[0]);
$("#answer").text(question[1]);
} catch (err) {
$("#question").text('');
$("#answer").text('');
}
});
});
</script>
</body>
</html>