-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbingo.html
289 lines (237 loc) · 10.1 KB
/
bingo.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!--
There's no place like ~
Authors: Saloni Goel & Abhinav Nair, 2020
Previous Author: Werner Stoop, 2012
-->
<html>
<head>
<!-- icons -->
<script src="https://kit.fontawesome.com/39896120a5.js" crossorigin="anonymous"></script>
<!-- Font & Website logo -->
<link href='https://fonts.googleapis.com/css?family=Playfair+Display' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=DM+Mono' rel='stylesheet'>
<link rel="icon" href="https://img.icons8.com/flat_round/64/000000/whale--v1.png">
<!-- css -->
<link rel="stylesheet" type="text/css" href="data/bingo.css">
<!-- bingo data -->
<script src="data/bingo.txt"></script>
<!-- Disable right click http://www.spacegun.co.uk -->
<script language=JavaScript>
var message = "Haha, really?";
function rtclickcheck(keyp) {
if (navigator.appName == "Netscape" && keyp.which == 3) {
alert(message);
return false;
}
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
alert(message);
return false;
}
}
document.onmousedown = rtclickcheck;
</script>
<title>Birthday Bingo</title>
<script type="text/javascript">
var N = N1;
var M = M1;
var data = data1;
var wrong_guess_max = wrong_guess_max1;
var wrong_guesses = new Array(N * M).fill(0);
var correct_guesses = 0;
function start() {
document.getElementById("heading").innerHTML = bingo_heading;
document.getElementById("specificInstructions").innerHTML = specific_instructions1;
}
// generate/restart game
function generate() {
document.getElementById("player").innerHTML = "";
var grid = document.getElementById("grid");
wrong_guesses = new Array(N * M).fill(0);
correct_guesses = 0;
var used_id = [];
var table_obj = "";
// TEST: Check if num(data) = N*M
if (data.length != N * M) {
var error = "<h3>JSON ARRAY LENGTH = " + data.length + " DOES NOT MATCH N*M = " + (N * M) + "</h3>";
grid.innerHTML = error;
console.log(error)
return;
}
if (grid.innerHTML && !confirm("Are you sure you want to regenerate?"))
return;
var html = '<table border="0">';
for (var y = 0; y < M; y++) {
html += "<tr>"
for (var x = 0; x < N; x++) {
var obj = data[x + y * N];
var i;
do {
i = Math.round(Math.random() * (N * M - 1));
} while (used_id.indexOf(i) >= 0);
used_id.push(i);
document.getElementById("player").innerHTML += '<li id="player_' + i + '">' + data[i].friend + '</li>';
// index table obj start
table_obj = '<td id="cell_' + x + '_' + y + '" >';
// adding guess function
table_obj += '<span id="chk-cell_' + x + '_' + y + '" onclick="cellClicked(\'cell_' + x + '_' + y + '\')">';
// adding clickable dice icon
if (obj.type == "quote" || obj.type == "song")
table_obj += '<i class=\"fas fa-dice\"></i>';
// adding clickable image
if (obj.type == "photo")
table_obj += '<img src ="' + obj.photo_cropped + '" alt="cropped photo here" />';
// close guess function
table_obj += '</span>';
// add song name and artist
if (obj.type == "song") {
table_obj += "\t" + obj.song + " - " + obj.artist;
table_obj += "<br>" + '<span onClick="openPlayer(\'cell_' + x + '_' + y + "')\"><i class=\"fab fa-youtube\"></i></span>";
}
// quote
if (obj.type == "quote" || obj.type == "song")
table_obj += "\t" + obj.quote;
// end table object
table_obj += "</td>";
html += table_obj;
}
html += "</tr>"
}
html += "</table>";
grid.innerHTML = html;
}
function cellClicked(id) {
var temp = id.split("_");
var i = Number(temp[1]) + Number(temp[2]) * N;
var person = prompt("Enter the name of the friend").trim();
if (person != null) {
if (person.toLowerCase() == data[i].friend.toLowerCase().trim()) {
correctGuess(id, i);
} else {
wrongGuess(id, i, person);
}
}
}
function correctGuess(id, i) {
correct_guesses++;
var d = document.getElementById(id);
// Change content in box
if (data[i].type == "photo") {
var popupModal = document.getElementById("popupModal");
var modalImage = document.getElementById("modalImage");
popupModal.style.display = "block";
modalImage.src = data[i].photo_full;
}
d.innerHTML = data[i].friend.toUpperCase();
d.style.backgroundColor = correct_guess_color;
// Strike out player
var player = document.getElementById("player_" + i);
player.innerHTML = "<s>" + player.innerHTML + "</s>";
// Check for BINGO
if (correct_guesses == N * M) {
onBingo();
}
}
function wrongGuess(id, i, person) {
wrong_guesses[i]++;
// Add name of wrong guess to tile
var d = document.getElementById(id);
d.style.backgroundColor = wrong_guess_color;
if (!d.innerHTML.endsWith(", ")) {
d.innerHTML += "<br> Wrong guess: ";
}
d.innerHTML += person + ", ";
// Offer an escape
if (wrong_guesses[i] >= wrong_guess_max) {
if (confirm("Cheat code activated. Would you like to know the answer?")) {
alert("The correct answer is " + data[i].friend);
correctGuess(id, i);
}
}
}
function onBingo() {
// Clear page & start loading taskbar
document.getElementById("playerList").innerHTML = "";
document.getElementById("grid").innerHTML = '<h1 style="background:#0A7328"> Congratulations! Your prize is loading ...</h1>';
var elem = document.getElementById("progressBar");
elem.innerHTML = '<h1 style="background:white"> </h1>';
var width = 1;
var id = setInterval(frame, 100);
function frame() {
if (width >= 100) {
// On loaded, move to prize page
clearInterval(id);
if (prize_link)
window.location.replace(prize_link);
else
window.location.replace("prize.html");
} else {
width++;
elem.style.width = width + '%';
}
}
}
// open YouTube embedded
function openPlayer(id) {
var temp = id.split("_");
var i = Number(temp[1]) + Number(temp[2]) * N;
var youTubeCode = data[i].link;
document.getElementById("youtubePlayer").src = "https://www.youtube.com/embed/" + youTubeCode;
toggle("embeddedPlayer");
}
function toggle(id) {
var elem = document.getElementById(id);
if (elem.style.display == "block")
elem.style.display = "none";
else
elem.style.display = "block";
}
function closeModal() {
var modal = document.getElementById("popupModal");
modal.style.display = "none";
}
</script>
</head>
<body onLoad="start()">
<h1 id="heading"></h1>
<p>An exciting game for your quarantine birthday!<a href="javascript:toggle('instructions');"> Instructions...</a>
</p>
<noscript>
<div class="error">
<strong>Problem:</strong>
<p><em>
You do not have JavaScript enabled. JavaScript must be enabled for this application to work.
</em></p>
</div>
</noscript>
<div id="instructions">
<h2>Instructions</h2>
<ol>
<noscript>
<li>Enable JavaScript</li>
</noscript>
<li>Click <strong>Refresh</strong> to create your Bingo board.</li>
<li id="specificInstructions"></li>
<li>If your guess is right, the box will change color and display the name of the person (: </li>
<li>If your guess is wrong, the box will show you your incorrect guess to help you narrow your search </li>
<li>HINT: The roster on the left of the grid has names of the people who participated! Hit refresh if it hasn't been populated yet </li>
<li>Good luck, maybe time yourself? May the force be with you</li>
</ol>
</div>
<div id="embeddedPlayer">
<iframe id="youtubePlayer" width="560" height="315" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>;
</div>
<div style="float:left" id="playerList">
<h2 style="margin-bottom:0">Roster</h2>
<ul id="player"></ul>
</div>
<form>
<input type="button" value="Refresh" onClick="generate();" />
</form>
<div id="popupModal" class="modal" style="display: none;">
<span class="close" onclick="closeModal()">×</span>
<img class="modal-content" id="modalImage">
</div>
<div id="grid"></div>
<div id="progressBar"></div>
</body>
</html>