forked from whatisnuclear/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo.html
259 lines (235 loc) · 8.6 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
---
layout: default
title: Bingo Card Generator
description: Play Bingo for nuclear discussions, or make your own bingo card and play
author: nick
image: /img/bingo.png
---
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900%7CMaterial+Icons" rel="stylesheet" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.prod.css" rel="stylesheet" type="text/css">
<div id="q-app">
<q-dialog v-model="openEditor" >
<q-card style="min-width: 350px">
<q-card-section>
<div class="text-h6">Phrases</div>
</q-card-section>
<q-card-section class="q-pt-none">
<q-input type="textarea" v-model="wordsText" autofocus></q-input>
</q-card-section>
<q-card-actions align="right" class="text-primary">
<q-btn flat label="Cancel" v-close-popup></q-btn>
<q-btn flat label="Update Phrases" @click="updatePhrases()"></q-btn>
</q-card-actions>
</q-card>
</q-dialog>
<div class="q-pa-md" >
<div v-for="row in 5" :key="row" class="row ">
<div v-for="col in 5" :key="col" class="col q-pa-xs">
<q-btn class="q-pa-xs fit text-center" no-caps :label="words[5*(row-1)+col-1]"
:color="getColor(row, col)" @click="woo(row, col)"></q-btn>
</div>
</div>
</div>
<div class="row q-pa-md">
<div class="col">
<q-btn class="q-pa-md fit" label="Remake card" color="red"
@click="shuffle()"></q-btn>
</div>
<div class="col">
<h5 v-if="bingo" class="text-center q-ma-xs">BINGO!</h5>
<h5 v-else class="text-center q-ma-xs">No bingo</h5>
</div>
<div class="col items-end">
<q-btn class="q-pa-md fit" label="Clear card" color="blue"
@click="clear()"></q-btn>
</div>
</div>
<div class="q-pa-md q-gutter-sm">
<q-btn label="Change options" color="blue" @click="edit()"></q-btn>
<q-btn label="Reset options" color="blue" @click="resetPhrases()"></q-btn>
<q-btn label="Share options" color="blue" @click="sharePhrases()"></q-btn>
</div>
</div>
<!-- Add the following at the end of your body tag -->
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.umd.prod.js"></script>
<script>
/*
Example kicking off the UI. Obviously, adapt this to your specific needs.
Assumes you have a <div id="q-app"></div> in your <body> above
*/
const app = Vue.createApp({
setup () {
Vue.onMounted(() => {
loadPhrases();
shuffle();
})
const originalWords= [
"Small Modular Reactor",
"HALEU",
"Onkalo Repository",
"Air pollution kills 8M/yr",
"Low carbon",
"Material footprint",
"Saved 1.8M lives",
"Fukushima",
"Chernobyl",
"Three Mile Island",
"What about the waste?",
"Our world in data",
"Gummy bears",
"Proliferation",
"It's recyclable",
"Breeder reactors",
"Thorium",
"Molten Salt",
"Floating reactors",
"Uranium miners",
"Fusion",
"Germany",
"France",
"China",
"RBMK",
"PWR",
"BWR",
"Hanford",
"Radiation on flights",
"Banana",
"Jenkins firm low-carbon",
"Sun doesn't always shine",
"Birds",
"Wind doesn't always blow",
"LCOE",
"Economics",
"Vogtle",
];
const words = Vue.ref(originalWords);
const wordsText = Vue.ref("");
const openEditor = Vue.ref(false);
const selected = Vue.ref([[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]);
const bingo = Vue.ref(false);
function woo(row, col) {
let val = selected.value[row-1][col-1];
selected.value[row-1][col-1]= val? 0:1;
bingo.value = checkBingo()
if (bingo.value) {
Quasar.Notify.create({message:"BINGO!", caption:
"Congrats!",type: "positive", timeout: 1000})
}
}
function getColor(row, col) {
return selected.value[row-1][col-1]==0 ? 'primary' : 'deep-orange';
}
function clear() {
for(let row=0;row<5;row++) {
for(let col=0;col<5;col++) {
selected.value[row][col]=0;
}
}
bingo.value=false;
}
function shuffle() {
let array = words.value;
var currentIndex = array.length, randomIndex;
// While there remain elements to shuffle...
while (currentIndex != 0) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
clear();
return array;
}
function checkBingo() {
for(let row=0;row<5;row++) {
let sum = 0;
for(let col=0;col<5;col++) {
sum += selected.value[row][col];
}
if (sum==5) {
return true;
}
}
for(let col=0;col<5;col++) {
let sum = 0;
// check cols
for(let row=0;row<5;row++) {
sum += selected.value[row][col];
}
if (sum==5) {
return true;
}
}
// check diagonals
let sum1=0;
let sum2=0;
for(let row=0;row<5;row++) {
sum1 += selected.value[row][row];
sum2 += selected.value[row][4-row];
}
if (sum1==5 || sum2==5) {
return true;
}
return false;
}
function edit() {
wordsText.value = words.value.join("\n");
openEditor.value = true;
}
function updatePhrases() {
words.value = wordsText.value.split(/\r?\n/)
openEditor.value = false;
}
function loadPhrases() {
// allow passing phrases in on URL
let urlParams = new URLSearchParams(window.location.search);
if(urlParams.has('p')) {
words.value = decodeURIComponent(atob(urlParams.get('p'))).split('|');
}
}
function sharePhrases() {
// build sharable URLs with custom choices
let phrases= words.value.join("|");
// strip off the existing search terms out of the location
let path=window.location.origin + window.location.pathname + "?p=" +
encodeURIComponent(btoa(phrases));
Quasar.copyToClipboard(path).then(() => {
Quasar.Notify.create({
message:"Copied sharable URL to clipboard",
type:"positive"
})
})
}
function resetPhrases() {
words.value = originalWords;
}
return {
words,
getColor,
woo,
selected,
shuffle,
clear,
bingo,
checkBingo,
edit,
wordsText,
openEditor,
updatePhrases,
sharePhrases,
resetPhrases
}
},
methods: {
}
})
app.use(Quasar)
app.mount('#q-app')
</script>