-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (66 loc) · 2.16 KB
/
index.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
function shuffle(array){
for(let i=array.length-1;i>0;i--){
let random = Math.floor(Math.random() * (i + 1));
let tmp = array[i];
array[i] = array[random];
array[random] = tmp;
}
return array;
}
async function rollBingo (number){
console.log(number);
if(!isNaN(number)){
let runAroundMax = 75+number;
const sleep = (ms)=>{
return new Promise((f)=>{
setTimeout(f,ms);
})
};
for(let i =1;i<=runAroundMax+1;i++){
await sleep((Math.pow(i/runAroundMax,4)*200));
$(`#${(i%76).toString()}`).addClass("run-around");
$(`#${i%76 == 1 ? maxBingoNum :i%76-1}`).removeClass("run-around");
}
async function twinkleNumber(number){
await sleep(500);
for(let i=0;i<3;i++){
$(`#${number}`).removeClass("run-around");
await sleep(500);
$(`#${number}`).addClass("run-around");
await sleep(300);
}
};
await twinkleNumber(number);
$(".last-number").addClass("used-number");
$(".last-number").removeClass("last-number");
$(".table-number").removeClass("run-around");
$(`#${number}`).addClass("last-number");
}
}
function generateTable(){
let table="";
const row = 15
const column = 5;
for(let i=0;i<column;i++){
table+="<tr>"
for(let k = 1;k<=row;k++){
let bingoNumber = (i*row+k).toString();
const numberClass ="table-number";
table+=`<th class=" ${numberClass} " id="${bingoNumber}">${bingoNumber}</th>`;
}
table+="</tr>"
}
$("#table").append(table);
}
const maxBingoNum=75;
window.onload=async()=>{
let numbers=[...Array(maxBingoNum).keys()].map(i=>++i);
shuffle(numbers);
generateTable();
$("#start_bingo").click(async()=>{
let n = numbers[0];
numbers.shift();
console.log("clicked");
await rollBingo(n);
});
}