-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbingo.js
133 lines (119 loc) · 3.84 KB
/
bingo.js
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
const bingo = (function () {
const bingos = [
'Everybody (except Vojta) trying to stay the heck away from the start arrow at the fireplace.',
'"Waiting for Vojta to start!"',
'Vojta says he will go first',
'"I’m fine. Next."',
'"That’s the perfect channel name!"',
'Someone asking "What did I miss" in regards to our channel name.',
'Someone has a bad case of FOMO because they missed 2 minutes of a meeting',
'Someone calls the unit wholesome.',
'Divorce rate is mentioned.',
'Someone is corrected that we don’t have "awkward" but "comfortable" silence.',
'Coffee is mentioned.',
'The lack of coffee is mentioned.',
'Some confusion is happening about type / version / configuration and what’s an integration anyways?',
'Unprompted long silence.',
'There are _possible_ squirrels!',
'People posting how they are emotionally stunted because there are no blob cat emojis in zoom.',
'"LET ME IINNNNNN" in slack.',
'"I’m happy to see you all!"',
"Mural gets more check-in circle decorations then yellow notes.",
"Suddenly we talk about books and half of us get sci-fi FOMO.",
"More communication happens in the zoom chat than in the actual call.",
"There's a mention of good skin.",
"Peter has written a blog post about something.",
"Implementation ended in tragedy.",
'"Good meeting"',
'We about that we are the most awesome unit.',
'We about why we are the most awesome unit.',
'_Someone_ is showing of dolphins they saw that morning.',
'"Do you think we annoy others by always mentioning how we are the most awesome unit?"',
]
const winner = [
[0,1,2,3],
[4,5,6,7],
[8,9,10,11],
[12,13,14,15],
[0,5,10,15],
[3, 6, 9, 12],
[0,4,8,12],
[1,5,9,13],
[2,6,10,14],
[3,7,11,15],
[0,4,8,12],
[1,5,9,13],
[2,6,10,14],
[3,7,11,15],
]
const hitBingos = [];
function shuffle(list) {
const listToReorder = [...list]
for (let i = listToReorder.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = listToReorder[i];
listToReorder[i] = listToReorder[j];
listToReorder[j] = temp;
}
return listToReorder
}
function addContentToCells(cells) {
const randomBingos = shuffle(bingos)
for (let i = 0; i < cells.length; i++) {
cells[i].setAttribute('data-cell-id', i)
cells[i].innerHTML = randomBingos[i]
}
}
function toggleClass(cell) {
if(cell.classList.contains('bingod')) {
cell.classList.remove("bingod")
} else {
cell.classList.add("bingod")
}
}
function updateBingoList(cellId) {
const index = hitBingos.indexOf(cellId)
if(index >= 0) {
hitBingos.splice(index, 1);
} else {
hitBingos.push(cellId)
}
}
function checkHits(hitsNeeded, currentHits) {
return hitsNeeded.every( entry => {
return currentHits.includes(entry)
})
}
function checkForBingo() {
if(hitBingos.length < 4) return
const weHaveAWinner = winner.some( winnerList => {
const list = winnerList.map( entry => entry.toString())
return checkHits(list, hitBingos)
})
if(weHaveAWinner) {
showOverlay()
}
}
function registerEventListeners() {
addEventListener('click', function(event) {
const cellId = event.target.getAttribute('data-cell-id')
if(!cellId) return
toggleClass(event.target)
updateBingoList(cellId)
checkForBingo()
});
}
function showOverlay() {
document.querySelector('.overlay--hidden').classList.remove('overlay--hidden')
}
return {
start: function() {
const cells = document.querySelectorAll('[data-cell-id="0"]')
addContentToCells(cells)
registerEventListeners()
},
restart: function() {
location.reload();
}
};
})();