-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotterySystem.html
More file actions
479 lines (406 loc) · 15.4 KB
/
LotterySystem.html
File metadata and controls
479 lines (406 loc) · 15.4 KB
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>简约抽奖系统</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #2c3e50, #4a6491);
color: #fff;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
max-width: 800px;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
text-align: center;
margin-bottom: 30px;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
font-size: 2.5rem;
color: #ecf0f1;
}
.subtitle {
text-align: center;
margin-bottom: 40px;
color: rgba(236, 240, 241, 0.8);
font-size: 1.2rem;
max-width: 600px;
}
.lottery-container {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 40px;
}
.lottery-box {
width: 300px;
height: 200px;
background: #7f8c8d;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 30px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
overflow: hidden;
position: relative;
border: 2px solid #95a5a6;
}
.lottery-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
transition: all 0.3s;
}
.item-icon {
font-size: 4rem;
margin-bottom: 15px;
transition: transform 0.3s;
}
.item-name {
font-size: 1.5rem;
font-weight: 600;
text-align: center;
margin-bottom: 5px;
}
.item-rarity {
font-size: 1rem;
padding: 5px 15px;
border-radius: 15px;
background: rgba(0, 0, 0, 0.3);
}
.controls {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 30px;
}
button {
background: linear-gradient(90deg, #3498db, #2980b9);
color: white;
border: none;
border-radius: 50px;
padding: 15px 40px;
font-size: 1.2rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}
button:active {
transform: translateY(1px);
}
button:disabled {
background: #95a5a6;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.result {
text-align: center;
font-size: 1.5rem;
margin-top: 20px;
min-height: 80px;
display: flex;
align-items: center;
justify-content: center;
}
.result-prize {
display: flex;
align-items: center;
gap: 20px;
background: rgba(52, 152, 219, 0.3);
padding: 20px 40px;
border-radius: 10px;
border: 2px solid rgba(52, 152, 219, 0.5);
}
.probability-table {
width: 100%;
background: rgba(0, 0, 0, 0.3);
border-radius: 15px;
padding: 30px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.probability-table h2 {
text-align: center;
margin-bottom: 20px;
color: #3498db;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px 15px;
text-align: center;
border: 1px solid rgba(255, 255, 255, 0.1);
}
th {
background-color: rgba(52, 152, 219, 0.3);
font-weight: 600;
}
tr:nth-child(even) {
background-color: rgba(255, 255, 255, 0.05);
}
.highlight-row {
background-color: rgba(52, 152, 219, 0.2) !important;
}
.rarity-common {
color: #bdc3c7;
}
.rarity-uncommon {
color: #2ecc71;
}
.rarity-rare {
color: #3498db;
}
.rarity-epic {
color: #9b59b6;
}
.rarity-legendary {
color: #f39c12;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
.pulsing {
animation: pulse 1s infinite;
}
@keyframes glow {
0% { box-shadow: 0 0 10px rgba(52, 152, 219, 0.5); }
50% { box-shadow: 0 0 20px rgba(52, 152, 219, 0.8); }
100% { box-shadow: 0 0 10px rgba(52, 152, 219, 0.5); }
}
.glowing {
animation: glow 1.5s infinite;
}
</style>
</head>
<body>
<div class="container">
<h1>简约抽奖系统</h1>
<p class="subtitle">点击开始按钮,奖项将随机切换并逐渐减速,最终停在获得的奖品上</p>
<div class="lottery-container">
<div class="lottery-box" id="lotteryBox">
<div class="lottery-item" id="currentItem">
<!-- 当前显示的奖品将在这里 -->
</div>
</div>
<div class="controls">
<button id="startBtn">开始抽奖</button>
</div>
<div class="result" id="result">
<!-- 抽奖结果将显示在这里 -->
</div>
</div>
<div class="probability-table">
<h2>奖池概率分布</h2>
<table id="probabilityTable">
<!-- 概率表格将由JavaScript生成 -->
</table>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// ========== 请在此处配置抽奖奖池 ==========
// 每个奖品的配置包括:名称、图标、稀有度、权重
// 权重越高,被抽中的概率越大
const prizePool = [
{ name: "普通手枪", icon: "🔫", rarity: "普通", weight: 40 },
{ name: "军用匕首", icon: "🔪", rarity: "普通", weight: 35 },
{ name: "战斗步枪", icon: "🛡️", rarity: "稀有", weight: 15 },
{ name: "狙击步枪", icon: "🎯", rarity: "稀有", weight: 12 },
{ name: "重型机枪", icon: "💥", rarity: "史诗", weight: 8 },
{ name: "黄金AK47", icon: "🌟", rarity: "史诗", weight: 5 },
{ name: "龙狙", icon: "🐉", rarity: "传说", weight: 2 },
{ name: "宝石刀", icon: "💎", rarity: "传说", weight: 1 }
];
// ==========================================
const lotteryBox = document.getElementById('lotteryBox');
const currentItem = document.getElementById('currentItem');
const startBtn = document.getElementById('startBtn');
const resultDiv = document.getElementById('result');
const probabilityTable = document.getElementById('probabilityTable');
let isDrawing = false;
let animationId = null;
let selectedPrize = null;
let currentSpeed = 50; // 初始切换速度(毫秒)
let maxSpeed = 500; // 最大切换间隔(毫秒)
let speedIncrease = 1.1; // 速度增加因子
let currentInterval = null;
// 初始化显示
function initDisplay() {
// 显示初始状态
currentItem.innerHTML = `
<div class="item-icon">🎁</div>
<div class="item-name">点击开始抽奖</div>
`;
resultDiv.innerHTML = '';
}
// 根据稀有度获取CSS类名
function getRarityClass(rarity) {
switch(rarity) {
case '普通': return 'common';
case '稀有': return 'uncommon';
case '史诗': return 'epic';
case '传说': return 'legendary';
default: return 'common';
}
}
// 初始化概率表格
function initProbabilityTable() {
// 计算总权重
const totalWeight = prizePool.reduce((sum, prize) => sum + prize.weight, 0);
// 创建表头
let tableHTML = `
<tr>
<th>奖品名称</th>
<th>稀有度</th>
<th>权重</th>
<th>概率</th>
</tr>
`;
// 添加奖品行
prizePool.forEach(prize => {
const probability = ((prize.weight / totalWeight) * 100).toFixed(2);
tableHTML += `
<tr>
<td>${prize.icon} ${prize.name}</td>
<td class="rarity-${getRarityClass(prize.rarity)}">${prize.rarity}</td>
<td>${prize.weight}</td>
<td>${probability}%</td>
</tr>
`;
});
probabilityTable.innerHTML = tableHTML;
}
// 根据权重随机选择奖品
function selectPrizeByWeight() {
// 计算总权重
const totalWeight = prizePool.reduce((sum, prize) => sum + prize.weight, 0);
// 生成随机数
const random = Math.random() * totalWeight;
// 根据权重选择奖品
let weightSum = 0;
for (const prize of prizePool) {
weightSum += prize.weight;
if (random <= weightSum) {
return prize;
}
}
// 默认返回第一个奖品(理论上不会执行到这里)
return prizePool[0];
}
// 随机显示一个奖品
function showRandomPrize() {
const randomIndex = Math.floor(Math.random() * prizePool.length);
const prize = prizePool[randomIndex];
currentItem.innerHTML = `
<div class="item-icon">${prize.icon}</div>
<div class="item-name">${prize.name}</div>
<div class="item-rarity rarity-${getRarityClass(prize.rarity)}">${prize.rarity}</div>
`;
}
// 显示特定奖品
function showSpecificPrize(prize) {
currentItem.innerHTML = `
<div class="item-icon pulsing">${prize.icon}</div>
<div class="item-name">${prize.name}</div>
<div class="item-rarity rarity-${getRarityClass(prize.rarity)}">${prize.rarity}</div>
`;
lotteryBox.classList.add('glowing');
}
// 开始抽奖动画
function startLottery() {
if (isDrawing) return;
isDrawing = true;
startBtn.disabled = true;
resultDiv.innerHTML = '';
lotteryBox.classList.remove('glowing');
// 重置速度
currentSpeed = 50;
// 随机选择奖品
selectedPrize = selectPrizeByWeight();
// 开始快速切换
startFastSwitching();
}
// 快速切换阶段
function startFastSwitching() {
showRandomPrize();
if (currentSpeed < maxSpeed) {
currentInterval = setTimeout(() => {
startFastSwitching();
}, currentSpeed);
// 逐渐减慢速度
currentSpeed *= speedIncrease;
} else {
// 切换到最终奖品
finishLottery();
}
}
// 完成抽奖
function finishLottery() {
clearTimeout(currentInterval);
// 显示最终奖品
showSpecificPrize(selectedPrize);
// 显示抽奖结果
resultDiv.innerHTML = `
<div class="result-prize">
<div class="item-icon">${selectedPrize.icon}</div>
<div>
<div class="item-name">恭喜您获得了 ${selectedPrize.name}!</div>
<div class="item-rarity rarity-${getRarityClass(selectedPrize.rarity)}">${selectedPrize.rarity}</div>
</div>
</div>
`;
// 高亮概率表格中的对应行
highlightProbabilityTable(selectedPrize.name);
// 重新启用开始按钮
startBtn.disabled = false;
isDrawing = false;
}
// 高亮概率表格中的行
function highlightProbabilityTable(prizeName) {
const rows = probabilityTable.querySelectorAll('tr');
rows.forEach(row => {
row.classList.remove('highlight-row');
if (row.textContent.includes(prizeName)) {
row.classList.add('highlight-row');
}
});
}
// 事件监听
startBtn.addEventListener('click', startLottery);
// 初始化
initDisplay();
initProbabilityTable();
});
</script>
</body>
</html>