-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
143 lines (131 loc) · 4 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
const icon_width = 104;
const icon_height = 104;
const num_icons = 5;
const time_per_icon = 500;
// let Mycase = Math.floor(Math.random() * 10); // 0 - 9
const randomNum = Math.floor(Math.random() * 5) + 4;
const roll = (reel, offset = 0, Mycase) => {
const delta = 2 * Math.floor(Math.random() * 10);
const style = getComputedStyle(reel);
const bgPosY = parseFloat(style["background-position-y"]);
const tarBgPosY = bgPosY + delta * icon_height;
const normTarBgPosY = tarBgPosY % bgPosY * (num_icons * icon_height);
// console.log(backgroundPositionY);
return new Promise((resolve, reject) =>{
// console.log("123:" + offset);
reel.style.transition = `background-position-y ${8 + delta * time_per_icon}ms cubic-bezier(.41,-0.01,.63,1.09)`;
switch (Mycase){
case 0:
if(offset == 0){
reel.style.backgroundPositionY =`${ 104 * 6 + (1014 * randomNum)}px`;
}
else {
reel.style.backgroundPositionY =`${ 104 * 4 + (1014 * randomNum)}px`;
}
break;
case 1:
if(offset == 0 || offset == 1){
reel.style.backgroundPositionY =`${ 104 * 6 + (1014 * randomNum)}px`;
}
else {
reel.style.backgroundPositionY =`${ 104 * 4 + (1014 * randomNum)}px`;
}
break;
case 2:
case 3:
case 4:
reel.style.backgroundPositionY =`${ 104 * 6 + (1014 * randomNum)}px`;
break;
case 5:
case 6:
case 7:
reel.style.backgroundPositionY =`${ 104 * 8 + (1014 * randomNum)}px`;
break;
case 8:
reel.style.backgroundPositionY =`${ 104 * 2 + (1014 * randomNum)}px`;
break;
case 9:
reel.style.backgroundPositionY =`${ 104 * 0 + (1014 * randomNum)}px`;
break;
case 10:
reel.style.backgroundPositionY =`${ 104 * 4 + (1014 * randomNum)}px`;
break;
default:
break;
}
setTimeout(() => {
reel.style.transition = `none`;
// reel.style.backgroundPositionY = `${normTarBgPosY}px`;
resolve(delta % num_icons)
}, 8 + delta * time_per_icon)
})
};
function rollAll() {
let Mycase = Math.floor(Math.random() * 10); // 0 - 9
const random_sm = Math.floor(Math.random() * 100); // 0 - 99
if(random_sm ===99 || random_sm === 69 || random_sm === 89 || random_sm === 79){
Mycase = 10;
}
const reelList = document.querySelectorAll('.slot > .bor_reel > .reel');
console.log(Mycase);
// console.log(Math.floor(Math.random() * 10)); // 0 - 9
Promise
.all( [...reelList].map((reel, i) => roll(reel, i, Mycase)))
.then((delta) => {
let money_str = 0;
switch (Mycase){
case 0:
money_str = "-2 代幣";
break;
case 1:
money_str = "-10 代幣";
break;
case 2:
case 3:
case 4:
money_str = "+1 代幣";
break;
case 5:
case 6:
case 7:
money_str = "+3 代幣";
break;
case 8:
money_str = "+5 代幣";
break;
case 9:
money_str = "+8 代幣";
break;
case 10:
money_str = "彩蛋!!(+1pt)";
break;
default:
break;
}
document.querySelector(".say").innerHTML = money_str;
const body_animation = document.querySelector('body');
body_animation.classList.add("win2");
setTimeout(() =>{
body_animation.classList.remove("win2");
}, 2500);
})
}
function init_slot(){
const reelList = document.querySelectorAll('.slot > .bor_reel > .reel');
document.querySelector(".say").innerHTML = "點我開始";
[...reelList].map((reel) => {
reel.style.backgroundPositionY = 0;
});
}
const start_btn = document.querySelector('.say');
start_btn.addEventListener("click", (e) => {
init_slot();
document.querySelector(".say").innerHTML = "請稍候...";
// console.log(e.target);
setTimeout("rollAll()", 0);
})
// const start = document.querySelector(".say");
// start.addEventListener("click", function(e){
// // console.log("test");
// rollAll();
// });