-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
401 lines (384 loc) · 18.6 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
原网址: https://camuskit-bonustime.netlify.com/
感谢作者把代码写得如此清晰而通用. 所有写出整洁代码的人都值得尊敬.
BearDic, 2018-10-29.
*/
$(document).ready(function () {
console.log('%c原网址: https://camuskit-bonustime.netlify.com/', 'color:blue;font-size:1.5em');
console.log('%c感谢原作者把代码写得如此清晰而通用. 所有写出整洁代码的人都值得尊敬.', 'color:blue;font-size:1.5em');
console.log('%cBearDic, 2018-10-29. ', 'color:black;font-size:1.2em');
var getConfig = function () {
const url = new URL(window.location.href);
var minNum = 1, maxNum = 999, size = 4, hasBackground = false, cardBackground = false, showMode = 0;
minNum = parseInt(url.searchParams.get("min") || "0");
maxNum = parseInt(url.searchParams.get("max") || "779");
if (maxNum<1000) {
$("#num4").parent().remove();
$(".col-xs-4").css("width","33.333333333%");
size=3;
if (maxNum < 100) {
$("#num3").parent().remove();
$(".col-xs-4").css("width", "50%");
size=2;
if (maxNum<10) {
$("#num2").parent().remove();
$(".col-xs-4").css("width", "100%");
$(".container").css("max-width", "400px");
size=1;
}
}
}
else size = 4;
const customBackground = url.searchParams.get("bg_url");
cardBackground = false;
showMode = 1;
return [minNum, maxNum, size, customBackground, cardBackground, showMode];
};
// Add special background
var addBackground = function (bgUrl) {
$('body').css('background-image', `url(${bgUrl})`);
};
var addCardBackground = function () {
for (var i = 0; i < 10; i++) {
$('#card' + i).css('background', 'url(\'images/' + i + '.jpg\') no-repeat center 200px').text('');
}
};
// Get a random number, and return as a string array
// 三等奖:抽一个数0~9
// 二等奖:先抽取4大家族之一(0~3)(老师线下手抽,手动切换背景),再抽一个数
// 一等奖:抽取键合奇偶(0~1),抽颜色(0~7),抽数
// 特等奖:抽键合(0~7),抽颜色(0~7),抽数(0~9),三步
// 因此,仍然抽一个三位数,自高位到低位分别是键合、颜色、数
var getRandomNum = function (usedNum, minNum, maxNum, size) {
//0~779,且十位不能大于7
var randomNum = Math.round(Math.random() * (maxNum - minNum + 1) + minNum-0.5);
while(randomNum%100 > 79)
randomNum = Math.round(Math.random() * (maxNum - minNum + 1) + minNum-0.5);
usedNum.push(randomNum);
var str = randomNum.toString();
while (str.length < size) str = '0' + str;
//str = str.substr(0,1) + '&' + str.substr(1,1);
//str = '??' + str;
return str.split('');
};
// Toggle between Cube and Ring
var toggleShape = function () {
$('#shape').toggleClass('ring').toggleClass('cube');
};
// Open ring and show num, or inversely
var toggleBetweenNumAndCube = function (ringNum, cubeNum) {
var $shape = $('#shape');
$shape.toggleClass('ringShow_' + ringNum).toggleClass('cubeShow_' + cubeNum);
$shape.css('-webkit-transform', 'rotateY(' + (-36 * ringNum) + 'deg)');
};
// Let card jump
var toggleCardJump = function (num) {
$('#card' + num).toggleClass('jump' + num);
};
// Write the number into num block
var displayNum = function (cardNum, showNum) {
$('#num' + cardNum).text(showNum);
};
// Let the number jump
var toggleNumJump = function (num) {
$('#num' + num).toggleClass('jumpDown');
};
// The whole lottery process with one num
var showNumByTurn = function (times, targetNum, originNum) {
toggleShape();
toggleBetweenNumAndCube(targetNum, originNum);
setTimeout(function () {
toggleCardJump(numArr[times]);
setTimeout(function () {
displayNum(times + 1, numArr[times]);
toggleNumJump(times + 1);
toggleShape();
toggleBetweenNumAndCube(targetNum, targetNum);
toggleCardJump(numArr[times]);
}, 1100);
}, 3300);
};
// Show all num once
var showNumOnce = function (numArr) {
for (var i = 0; i < numArr.length; i++) {
displayNum(i + 1, numArr[i]);
toggleNumJump(i + 1);
}
};
// clear numbers
var clearNum = function (arr) {
for (var i = 0; i < arr.length; i++) {
toggleNumJump(i + 1);
$('#num' + (i + 1)).text('');
}
};
// 0: minNum, 1: maxNum, 2: numLength, 3: hasBackground.
var config = getConfig();
// Add background
if (config[3])
addBackground(config[3]);
if (config[4])
addCardBackground();
var toggleSingleFrame = function () {
$("#num3").parent().remove();
$("#num2").css("display", "none");
$(".col-xs-4").css("width", "100%");
$(".container").css("max-width", "380px");
$(".showNum").toggleClass("numUndicided");
}
var toggleDoubleFrame = function(){
$("#num3").parent().remove();
$("#num2").css("display", "inherit");
$(".container").css("max-width", "730px");
$(".col-xs-4").css("width", "50%");
}
// Lottery
var usedArr = [];
var numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
var pressTimes = 0, preNum = 0;
var prize = 3;
$('body').keydown(function (event) {
if (event.which === 51) {// press key 3
prize = 3;
toggleThirdPrize();
pressTimes = 0;
} else if(event.which === 50) {// press key 2
prize = 2;
toggleSecondPrize();
pressTimes = 0;
} else if(event.which === 49) {// press key 1
prize = 1;
toggleFirstPrize();
pressTimes = 0;
} else if(event.which === 48) {// press key 0
prize = 0;
toggleSpecialPrize();
pressTimes = 0;
}
if (config[5] === 0) {
if (event.which === 32) {
if (pressTimes < numArr.length) {
showNumByTurn(pressTimes, numArr[pressTimes], preNum);
preNum = numArr[pressTimes];
pressTimes++;
} else {
pressTimes = 0;
clearNum(numArr);
numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
}
}
} else if (config[5] === 1) {
if (prize === -1){
if (event.which === 32 && pressTimes === 0) {
toggleShape();
pressTimes++;
} else if (event.which === 32 && pressTimes === 1) {
toggleShape();
showNumOnce(numArr);
pressTimes++;
} else if (event.which === 32 && pressTimes === 2) {
clearNum(numArr);
numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
pressTimes = 0;
}
} else if(prize === 3){
if(event.which === 32 && pressTimes === 0){
// 旋转变形
toggleExpand();
pressTimes++;
} else if(event.which === 32 && pressTimes === 1){
// 抽出数字
toggleResult(numArr[2])
pressTimes++;
} else if(event.which === 32 && pressTimes === 2){
// 重置
toggleExpand();
toggleThirdPrize();
numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
pressTimes = 0;
}
} else if(prize === 2){
if(pressTimes === 0){
// 抽出家族
if(event.which === 80){ // press P :高分子
$("#bg0").parent().parent().css("transform", "translateY(-1000px)");
$("#bond0").parent().parent().css("transform", "translateY(-1000px)");
$("#card0").parent().parent().css("transform", "translateY(-1000px)");
$("#result1").parent().css("transform", "translateY(0px)");
$("#2p1").css("background-image", "url(抽奖软件UI/底色/高分子/高分子1.png)");
$("#2p2").css("background-image", "url(抽奖软件UI/底色/高分子/高分子2.png)");
// $(".NumRolling").children("ul").children("li").children("img").css("filter", "drop-shadow(50px, 50px, #9d7a11)");
// $(".bondbg2").css("filter", "dropshadow(50px, 50px ,#9d7a11)");
pressTimes ++;
} else if(event.which === 77) { // press M: 金属
$("#bg0").parent().parent().css("transform", "translateY(-1000px)");
$("#bond0").parent().parent().css("transform", "translateY(-1000px)");
$("#card0").parent().parent().css("transform", "translateY(-1000px)");
$("#result1").parent().css("transform", "translateY(0px)");
$("#2p1").css("background-image", "url(抽奖软件UI/底色/金属/金属1.png)");
$("#2p2").css("background-image", "url(抽奖软件UI/底色/金属/金属2.png)");
pressTimes ++;
} else if(event.which === 78) { // press N: 非金
$("#bg0").parent().parent().css("transform", "translateY(-1000px)");
$("#bond0").parent().parent().css("transform", "translateY(-1000px)");
$("#card0").parent().parent().css("transform", "translateY(-1000px)");
$("#result1").parent().css("transform", "translateY(0px)");
$("#2p1").css("background-image", "url(抽奖软件UI/底色/非金/非金1.png)");
$("#2p2").css("background-image", "url(抽奖软件UI/底色/非金/非金2.png)");
pressTimes ++;
} else if(event.which === 67) { // press C: 复合
$("#bg0").parent().parent().css("transform", "translateY(-1000px)");
$("#bond0").parent().parent().css("transform", "translateY(-1000px)");
$("#card0").parent().parent().css("transform", "translateY(-1000px)");
$("#result1").parent().css("transform", "translateY(0px)");
$("#2p1").css("background-image", "url(抽奖软件UI/底色/复合/复合1.png)");
$("#2p2").css("background-image", "url(抽奖软件UI/底色/复合/复合2.png)");
pressTimes ++;
}
} else if(event.which === 32 && pressTimes === 1) {
// 抽出数字
$("#result1").toggleClass("jumpDown");
$("#result2").toggleClass("jumpDown");
$(".NumRolling").children("ul").css("display", "none");
$(".NumRolling").children("img").css("display", "inherit");
$(".NumRolling").children("img").attr("src", "抽奖软件UI/数字/"+numArr[2]+".png");
pressTimes++;
} else if(event.which === 32 && pressTimes === 2) {
// 重置
$("#result1").toggleClass("jumpDown");
$("#result2").toggleClass("jumpDown");
numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
toggleSecondPrize();
pressTimes = 0;
}
} else if(prize === 1){
if(event.which === 32 && pressTimes === 0){
// 扩张,出现卡池
toggleExpand();
$(".row").css("transform", "translateY(0px)");
$("#bg0").parent().parent().css("transform", "translateY(-100px) translateZ(-500px)");
$("#bond0").parent().parent().css("transform", "translateY(-100px) translateZ(-500px) rotateZ(45deg)");
$("#card0").parent().parent().css("transform", "translateY(-100px) translateZ(-760px)");
pressTimes++;
} else if(event.which === 32 && pressTimes === 1) {
// 抽键合奇偶
if(numArr[0] % 2 === 0){// 偶数
$("#br1").attr("src", "抽奖软件UI/键和方式/2-水.png");
$("#b11l").attr("src", "抽奖软件UI/键和方式/2-水.png");
$("#b11r").attr("src", "抽奖软件UI/键和方式/2-水.png");
$("#br2").attr("src", "抽奖软件UI/键和方式/4-正四面体.png");
$("#b12l").attr("src", "抽奖软件UI/键和方式/4-正四面体.png");
$("#b12r").attr("src", "抽奖软件UI/键和方式/4-正四面体.png");
$("#br3").attr("src", "抽奖软件UI/键和方式/6-丙炔.png");
$("#b13l").attr("src", "抽奖软件UI/键和方式/6-丙炔.png");
$("#b13r").attr("src", "抽奖软件UI/键和方式/6-丙炔.png");
$("#br4").attr("src", "抽奖软件UI/键和方式/8-BCC.png");
$("#b14l").attr("src", "抽奖软件UI/键和方式/8-BCC.png");
$("#b14r").attr("src", "抽奖软件UI/键和方式/8-BCC.png");
} else {
$("#br1").attr("src", "抽奖软件UI/键和方式/1-H2.png");
$("#b11l").attr("src", "抽奖软件UI/键和方式/1-H2.png");
$("#b11r").attr("src", "抽奖软件UI/键和方式/1-H2.png");
$("#br2").attr("src", "抽奖软件UI/键和方式/3-乙炔.png");
$("#b12l").attr("src", "抽奖软件UI/键和方式/3-乙炔.png");
$("#b12r").attr("src", "抽奖软件UI/键和方式/3-乙炔.png");
$("#br3").attr("src", "抽奖软件UI/键和方式/5-石墨.png");
$("#b13l").attr("src", "抽奖软件UI/键和方式/5-石墨.png");
$("#b13r").attr("src", "抽奖软件UI/键和方式/5-石墨.png");
$("#br4").attr("src", "抽奖软件UI/键和方式/7-简单立方.png");
$("#b14l").attr("src", "抽奖软件UI/键和方式/7-简单立方.png");
$("#b14r").attr("src", "抽奖软件UI/键和方式/7-简单立方.png");
}
$("#num1").toggleClass("jumpDown");
pressTimes++;
} else if(event.which === 32 && pressTimes === 2) {
// 抽底色
if(numArr[1] === '0'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/金属/金属1.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/金属/金属1.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '1'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/金属/金属2.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/金属/金属2.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '2'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/复合/复合1.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/复合/复合1.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '3'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/复合/复合2.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/复合/复合2.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '4'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/非金/非金1.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/非金/非金1.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '5'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/非金/非金2.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/非金/非金2.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '6'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/高分子/高分子1.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/高分子/高分子1.png)");
// $("#num2").css("background-size", "contain");
} else if(numArr[1] === '7'){
$("#num2").css("background-image", "url(抽奖软件UI/底色/高分子/高分子2.png)");
$("#result11").parent().children().children(".showNum").css("background-image", "url(抽奖软件UI/底色/高分子/高分子2.png)");
// $("#num2").css("background-size", "contain");
}
$("#num2").toggleClass("jumpDown");
pressTimes++;
} else if(event.which === 32 && pressTimes === 3) {
// 抽数字
$("#num3").children("img").attr("src", "抽奖软件UI/数字/"+numArr[2]+".png");
$(".prize1").attr("src", "抽奖软件UI/数字/"+numArr[2]+".png");
$("#num3").toggleClass("jumpDown");
pressTimes++;
} else if(event.which === 32 && pressTimes === 4) {
// 生成最终卡片
$("#result11").parent().css("transform", "translateY(0px)");
$(".row").css("transform", "translateY(2500px)");
$("#bg0").parent().parent().css("transform", "translateY(-1000px)");
$("#bond0").parent().parent().css("transform", "translateY(-1000px) rotateZ(45deg)");
$("#card0").parent().parent().css("transform", "translateY(-1000px) ");
pressTimes++;
} else if(event.which === 32 && pressTimes === 5) {
// 清空,重置
$("#num1").toggleClass("jumpDown");
$("#num2").toggleClass("jumpDown");
$("#num3").toggleClass("jumpDown");
numArr = getRandomNum(usedArr, config[0], config[1], config[2]);
toggleExpand()
toggleFirstPrize();
pressTimes = 0;
}
} else if(prize === 0){
if(event.which === 32 && pressTimes === 0){
// 扩张,出现卡池
toggleExpand();
$(".row").css("transform", "translateY(0px)");
$("#bg0").parent().parent().css("transform", "translateY(-100px) translateZ(-500px)");
$("#bond0").parent().parent().css("transform", "translateY(-100px) translateZ(-500px) rotateZ(45deg)");
$("#card0").parent().parent().css("transform", "translateY(-100px) translateZ(-760px)");
pressTimes++;
} else if(event.which === 32 && pressTimes === 1){
// 抽键合
pressTimes++;
} else if(event.which === 32 && pressTimes === 2){
// 抽背底
pressTimes++;
} else if(event.which === 32 && pressTimes === 3){
// 抽数字
pressTimes++;
} else if(event.which === 32 && pressTimes === 4){
// 最终卡片
pressTimes++;
} else if(event.which === 32 && pressTimes === 5){
// 清空,重置
toggleSpecialPrize();
pressTimes = 0;
}
}
}
})
});