-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-keyboard-typing-game.html
More file actions
800 lines (765 loc) · 58.1 KB
/
Copy pathmain-keyboard-typing-game.html
File metadata and controls
800 lines (765 loc) · 58.1 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
<!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>
:root{ --bg:#0d1117; --panel:#161b22; --line:#30363d; --txt:#e6edf3; --accent:#58a6ff; }
*{ box-sizing:border-box; }
body{ margin:0; background:var(--bg); color:var(--txt);
font-family:-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
display:flex; flex-direction:column; align-items:center; min-height:100vh; padding:16px; }
h1{ font-size:20px; margin:4px 0 12px; letter-spacing:1px; }
.wrap{ width:480px; max-width:100%; }
.hud{ display:flex; gap:8px; margin-bottom:8px; }
.hud .cell{ flex:1; background:var(--panel); border:1px solid var(--line);
border-radius:8px; padding:6px 8px; text-align:center; }
.hud .label{ font-size:11px; opacity:.6; }
.hud .val{ font-size:18px; font-weight:700; }
.stage{ position:relative; width:480px; max-width:100%; aspect-ratio:480/640;
border:1px solid var(--line); border-radius:12px; overflow:hidden; background:#000; }
canvas{ display:block; width:100%; height:100%; }
.overlay{ position:absolute; inset:0; background:rgba(13,17,23,.92);
display:flex; flex-direction:column; align-items:center; justify-content:center;
gap:12px; padding:24px; text-align:center; }
.overlay.hidden{ display:none; }
.overlay h2{ margin:0; font-size:24px; }
.overlay p{ margin:0; font-size:13px; opacity:.8; line-height:1.6; }
.row{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; justify-content:center; }
label{ font-size:13px; }
select, button, input[type=range]{ font:inherit; }
select{ background:var(--panel); color:var(--txt); border:1px solid var(--line);
border-radius:6px; padding:5px 8px; }
button{ background:var(--accent); color:#04122b; border:none; border-radius:8px;
padding:9px 18px; font-weight:700; cursor:pointer; }
button.ghost{ background:var(--panel); color:var(--txt); border:1px solid var(--line); }
button:active{ transform:translateY(1px); }
.controls{ display:flex; gap:10px; align-items:center; flex-wrap:wrap;
margin-top:10px; background:var(--panel); border:1px solid var(--line);
border-radius:10px; padding:10px 12px; }
.controls .grp{ display:flex; align-items:center; gap:6px; }
.hint{ font-size:12px; opacity:.6; margin-top:10px; line-height:1.6; text-align:center; }
.keycap{ display:inline-block; background:#21262d; border:1px solid var(--line);
border-radius:4px; padding:1px 6px; font-size:12px; }
.custom{ margin-top:6px; border-top:1px dashed var(--line); padding-top:10px; width:100%; }
.custom.hidden{ display:none; }
.crow{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; justify-content:center; margin:6px 0; font-size:13px; }
.chips{ display:flex; flex-wrap:wrap; gap:2px 4px; justify-content:center; max-width:340px; }
.custom label{ display:inline-flex; align-items:center; gap:3px; }
</style>
</head>
<body>
<div class="wrap">
<h1 id="pageTitle" data-i18n="title">⬇ 主键盘打字游戏 · 坠落拦截</h1>
<div class="hud">
<div class="cell"><div class="label" data-i18n="score">得分</div><div class="val" id="hScore">0</div></div>
<div class="cell"><div class="label" data-i18n="level">级别</div><div class="val" id="hLevel">第一级</div></div>
<div class="cell"><div class="label" data-i18n="combo">连击</div><div class="val" id="hCombo">0</div></div>
<div class="cell"><div class="label" data-i18n="lives">生命</div><div class="val" id="hLives">♥♥♥</div></div>
<div class="cell"><div class="label" data-i18n="hKph">速度KPH</div><div class="val" id="hKph">0</div></div>
<div class="cell"><div class="label" data-i18n="acc">准确率</div><div class="val" id="hAcc">100%</div></div>
</div>
<div class="stage">
<canvas id="game" width="480" height="640"></canvas>
<!-- 开始界面 -->
<div class="overlay" id="startScreen">
<h2 data-i18n="startH2">坠落拦截</h2>
<p data-i18n-html="startDesc">Letters / symbols fall from the sky—type the matching key on the <b>main keyboard</b> to shoot them down!<br>
Miss one and it hits the ground, costing a life; lose all lives and the game ends.</p>
<div class="row">
<label><span data-i18n="lblLevel">级别</span>
<select id="selLevel" data-i18n-opts="levelOpts">
<option value="0">CapsLock a s d f g (forward · 10× each)</option>
<option value="1">第二级(CapsLock a s d f g · 不重复)</option>
<option value="2">第三级(g f d s a capslock · 不重复)</option>
<option value="3">第四级(CapsLock a s d f g · 随机)</option>
<option value="4">第五级(随机字符)</option>
<option value="5">第六级(h j k l ; ' enter · 不重复)</option>
<option value="6">第七级(enter ' ; l k j h · 不重复)</option>
<option value="7">第八级(h j k l ; ' enter · 随机)</option>
<option value="8">第九级(左Shift z x c v b · 正序·每字符10次)</option>
<option value="9">第十级(左Shift z x c v b · 不重复)</option>
<option value="10">第十一级(b v c x z 左Shift · 不重复)</option>
<option value="11">第十二级(左Shift z x c v b · 随机)</option>
<option value="12">第十三级(n m , . / 右Shift · 正序·每字符10次)</option>
<option value="13">第十四级(n m , . / 右Shift · 不重复)</option>
<option value="14">第十五级(右Shift / . , m n · 不重复)</option>
<option value="15">第十六级(n m , . / 右Shift · 随机)</option>
<option value="16">第十七级(Tab q w e r t · 正序·每字符10次)</option>
<option value="17">第十八级(Tab q w e r t · 不重复)</option>
<option value="18">第十九级(t r e w q Tab · 不重复)</option>
<option value="19">第二十级(Tab q w e r t · 随机)</option>
<option value="20">第二十一级(y u i o p [ ] \ · 正序·每字符10次)</option>
<option value="21">第二十二级(y u i o p [ ] \ · 不重复)</option>
<option value="22">第二十三级(\ ] [ p o i u y · 不重复)</option>
<option value="23">第二十四级(y u i o p [ ] \ · 随机)</option>
<option value="24">第二十五级(` 1 2 3 4 5 · 正序·每字符10次)</option>
<option value="25">第二十六级(` 1 2 3 4 5 · 不重复)</option>
<option value="26">第二十七级(5 4 3 2 1 ` · 不重复)</option>
<option value="27">第二十八级(` 1 2 3 4 5 · 随机)</option>
<option value="28">第二十九级(6 7 8 9 0 - = Backspace · 正序·每字符10次)</option>
<option value="29">第三十级(6 7 8 9 0 - = Backspace · 不重复)</option>
<option value="30">第三十一级(Backspace = - 0 9 8 7 6 · 不重复)</option>
<option value="31">第三十二级(6 7 8 9 0 - = Backspace · 随机)</option>
<option value="32">第三十三级(~ ! @ # $ % Space · 正序·每字符10次)</option>
<option value="33">第三十四级(~ ! @ # $ % Space · 不重复)</option>
<option value="34">第三十五级(Space % $ # @ ! ~ · 不重复)</option>
<option value="35">第三十六级(~ ! @ # $ % Space · 随机)</option>
<option value="36">第三十七级(^ & * ( ) _ + · 正序·每字符10次)</option>
<option value="37">第三十八级(^ & * ( ) _ + · 不重复)</option>
<option value="38">第三十九级(+ _ ) ( * & ^ · 不重复)</option>
<option value="39">第四十级(^ & * ( ) _ + · 随机)</option>
<option value="40">第四十一级(A S D F G · 正序·每字符10次 · 需Shift)</option>
<option value="41">第四十二级(A S D F G · 不重复 · 需Shift)</option>
<option value="42">第四十三级(G F D S A · 不重复 · 需Shift)</option>
<option value="43">第四十四级(A S D F G · 随机 · 需Shift)</option>
<option value="45">第四十五级(H J K L : " · 正序·每字符10次)</option>
<option value="46">第四十六级(H J K L : " · 不重复)</option>
<option value="47">第四十七级(" : L K J H · 不重复)</option>
<option value="48">第四十八级(H J K L : " · 随机)</option>
<option value="49">第四十九级(Z X C V B · 正序·每字符10次 · 需Shift)</option>
<option value="50">第五十级(Z X C V B · 不重复 · 需Shift)</option>
<option value="51">第五十一级(B V C X Z · 不重复 · 需Shift)</option>
<option value="52">第五十二级(Z X C V B · 随机 · 需Shift)</option>
<option value="53">第五十三级(N M < > ? · 正序·每字符10次 · 需Shift)</option>
<option value="54">第五十四级(N M < > ? · 不重复 · 需Shift)</option>
<option value="55">第五十五级(? > < M N · 不重复 · 需Shift)</option>
<option value="56">第五十六级(N M < > ? · 随机 · 需Shift)</option>
<option value="57">第五十七级(Q W E R T · 正序·每字符10次 · 需Shift)</option>
<option value="58">第五十八级(Q W E R T · 不重复 · 需Shift)</option>
<option value="59">第五十九级(T R E W Q · 不重复 · 需Shift)</option>
<option value="60">第六十级(Q W E R T · 随机 · 需Shift)</option>
<option value="61">第六十一级(Y U I O P { } | · 正序·每字符10次 · 需Shift)</option>
<option value="62">第六十二级(Y U I O P { } | · 不重复 · 需Shift)</option>
<option value="63">第六十三级(| } { P O I U Y · 不重复 · 需Shift)</option>
<option value="64">第六十四级(Y U I O P { } | · 随机 · 需Shift)</option>
<option value="44">自选(自定义)</option>
</select>
</label>
<label><span data-i18n="lblTheme">主题</span>
<select id="selTheme" data-i18n-opts="theme">
<option value="space">太空入侵</option>
<option value="candy">糖果世界</option>
<option value="neon">霓虹像素</option>
</select>
</label>
</div>
<div id="customPanel" class="custom hidden">
<div class="crow"><span data-i18n="customDigits">字母</span><div id="chDigits" class="chips"></div></div>
<div class="crow"><span data-i18n="customSymbols">符号</span><div id="chSyms" class="chips"></div></div>
<div class="crow"><span data-i18n="customNums">数字</span><div id="chNums" class="chips"></div></div>
<div class="crow"><span data-i18n="customFunc">功能键</span><div id="chFunc" class="chips"></div></div>
<div class="crow">
<label><span data-i18n="lblOrder">顺序</span> <select id="cOrder" data-i18n-opts="order">
<option value="正序">正序</option><option value="倒序">倒序</option><option value="随机">随机</option>
</select></label>
<label><span data-i18n="lblEach">每字符</span> <select id="cRepeat" data-i18n-opts="repeat">
<option>1</option><option>2</option><option>3</option><option>4</option>
<option selected>5</option><option>6</option><option>8</option><option>10</option>
</select> <span data-i18n="unitEach">次</span></label>
<label><span data-i18n="lblSpeed">速度</span> <select id="cSpeed" data-i18n-opts="speed">
<option value="26">慢</option><option value="38" selected>中</option>
<option value="60">快</option><option value="84">很快</option>
</select></label>
<label><span data-i18n="lblFall">下落</span> <select id="cFall" data-i18n-opts="fall">
<option value="单个">单个</option><option value="多个">多个</option>
</select></label>
</div>
</div>
<button id="btnStart" data-i18n="btnStart">开始游戏</button>
</div>
<!-- 结束界面 -->
<div class="overlay hidden" id="overScreen">
<h2 id="overTitle" data-i18n="overH2">游戏结束</h2>
<p id="overStats"></p>
<button id="btnRestart" data-i18n="btnAgain">再来一局</button>
</div>
<!-- 暂停界面 -->
<div class="overlay hidden" id="pauseScreen">
<h2 data-i18n="pauseH2">已暂停</h2>
<p data-i18n-html="pauseTip">按 <span class="keycap">P</span> 或 <span class="keycap">空格</span> 继续</p>
<div class="row">
<button id="btnResume" data-i18n="btnResume">继续</button>
<button id="btnRestartPaused" class="ghost" data-i18n="btnRestart">重新开始</button>
</div>
</div>
</div>
<div class="controls">
<button id="btnPause" class="ghost" data-i18n="btnPause">暂停</button>
<div class="grp">
<label for="vol" data-i18n="lblVol">音量</label>
<input type="range" id="vol" min="0" max="100" value="60">
</div>
<div class="grp">
<label><input type="checkbox" id="mute"> <span data-i18n="lblMute">静音</span></label>
</div>
<div class="grp">
<label><span data-i18n="lblTheme">主题</span>
<select id="selTheme2" data-i18n-opts="theme">
<option value="space">太空</option>
<option value="candy">糖果</option>
<option value="neon">霓虹</option>
</select>
</label>
</div>
<div class="grp">
<label><span data-i18n="lblLang">语言</span>
<select id="selLang" data-i18n-opts="langsel">
<option value="zh">简中</option>
<option value="zhHant">繁中</option>
<option value="en" selected>EN</option>
</select>
</label>
</div>
</div>
<div class="hint" data-i18n-html="hint">
Use the main keyboard to type the matching <b>letter / symbol</b> to shoot targets ·
<span class="keycap">Space</span> or <span class="keycap">Esc</span> to pause ·
when several of the same letter fall, hit the one <b>closest to the ground</b> first
</div>
</div>
<script src="game-core.js"></script>
<script>
(() => {
"use strict";
const cv = document.getElementById('game');
const ctx = cv.getContext('2d');
const W = cv.width, H = cv.height;
const GROUND_Y = H - 70; // 地面线
const DEF_X = W/2, DEF_Y = H - 34; // 防御炮台位置
// ---------- 配置 ----------
const LETTERS = 'abcdefghijklmnopqrstuvwxyz'.split('');
const SYMS = ['.', ',', '/', '<', '>', '?', ';', ':', "'", '"', '[', ']', '\\', '|', '{', '}', '`', '-', '=', 'Backspace', '0','1','2','3','4','5','6','7','8','9','~','!','@','#','$','%','Space','^','&','*','(',')','_','+'];
// 三组练习字符集(玩法相同,仅字符集不同):左手上排 / 右手上排 / 左手下排
const SET_L = ['CapsLock','a','s','d','f','g'];
const SET_R = ['h','j','k','l',';',"'",'Enter'];
const SET_Z = ['LShift','z','x','c','v','b'];
const SET_4 = ['n','m',',','.','/','RShift'];
const SET_5 = ['Tab','q','w','e','r','t'];
const SET_Y = ['y','u','i','o','p','[',']','\\']; // 右手上排延伸:y u i o p + 符号 [ ] \
const SET_B = ['`', '1', '2', '3', '4', '5']; // 数字行左侧:反引号 ` + 1 2 3 4 5
const SET_6 = ['6','7','8','9','0','-','=','Backspace']; // 数字行右侧 + 退格:6 7 8 9 0 - = Backspace
const SET_7 = ['~','!','@','#','$','%','Space']; // 符号行:~ ! @ # $ % 空格
const SET_8 = ['^','&','*','(',')','_','+']; // 符号行:^ & * ( ) _ +
const SET_9 = ['A','S','D','F','G']; // 大写 home 行左手指法:需用 Shift+字母 击落
const SET_10 = ['H', 'J', 'K', 'L', ':', '"']; // 大写 home 行右手 + 冒号/引号:均需用 Shift 击落
const SET_11 = ['Z', 'X', 'C', 'V', 'B']; // 大写左手下排:需用 Shift+字母 击落
const SET_12 = ['N', 'M', '<', '>', '?']; // 大写右手下排 + 尖括号/问号:均需用 Shift 击落
const SET_13 = ['Q', 'W', 'E', 'R', 'T']; // 大写左手上排:需用 Shift+字母 击落
const SET_14 = ['Y', 'U', 'I', 'O', 'P', '{', '}', '|']; // 大写右手上排 + 花括号/竖线:均需用 Shift 击落
// 所有级别共用的玩法参数
const PLAY = { speed:26, spawn:350, ramp:0.0004, oneAtATime:true };
const seqFwd = (set, repeat) => ({ ...PLAY, mode:'seq', pattern:set, repeat }); // 正序序列
const seqRev = (set, repeat) => ({ ...PLAY, mode:'seq', pattern:[...set].reverse(), repeat }); // 倒序序列
const randSet = (set) => ({ ...PLAY, mode:'rand', set }); // 随机下落
// 配对:1↔5↔9↔13↔17、2↔6↔10↔14↔18、3↔7↔11↔15↔19、4↔8↔12↔16↔20(同一玩法,五组字符集)
const LEVELS = [
{ id:'lv1', name:'第一级', ...seqFwd(SET_L, 10) },
{ id:'lv2', name:'第二级', ...seqFwd(SET_L, 1) },
{ id:'lv3', name:'第三级', ...seqRev(SET_L, 1) },
{ id:'lv4', name:'第四级', ...randSet(SET_L) },
{ id:'lv5', name:'第五级', ...seqFwd(SET_R, 10) },
{ id:'lv6', name:'第六级', ...seqFwd(SET_R, 1) },
{ id:'lv7', name:'第七级', ...seqRev(SET_R, 1) },
{ id:'lv8', name:'第八级', ...randSet(SET_R) },
{ id:'lv9', name:'第九级', ...seqFwd(SET_Z, 10) },
{ id:'lv10', name:'第十级', ...seqFwd(SET_Z, 1) },
{ id:'lv11', name:'第十一级', ...seqRev(SET_Z, 1) },
{ id:'lv12', name:'第十二级', ...randSet(SET_Z) },
{ id:'lv13', name:'第十三级', ...seqFwd(SET_4, 10) },
{ id:'lv14', name:'第十四级', ...seqFwd(SET_4, 1) },
{ id:'lv15', name:'第十五级', ...seqRev(SET_4, 1) },
{ id:'lv16', name:'第十六级', ...randSet(SET_4) },
{ id:'lv17', name:'第十七级', ...seqFwd(SET_5, 10) },
{ id:'lv18', name:'第十八级', ...seqFwd(SET_5, 1) },
{ id:'lv19', name:'第十九级', ...seqRev(SET_5, 1) },
{ id:'lv20', name:'第二十级', ...randSet(SET_5) },
// 第二十一至二十四级:玩法与 1~4 级一致,字符集换为 y u i o p [ ] \
{ id:'lv21', name:'第二十一级', ...seqFwd(SET_Y, 10) },
{ id:'lv22', name:'第二十二级', ...seqFwd(SET_Y, 1) },
{ id:'lv23', name:'第二十三级', ...seqRev(SET_Y, 1) },
{ id:'lv24', name:'第二十四级', ...randSet(SET_Y) },
// 第二十五至二十八级:玩法与 1~4 级一致,字符集换为 ` 1 2 3 4 5
{ id:'lv25', name:'第二十五级', ...seqFwd(SET_B, 10) },
{ id:'lv26', name:'第二十六级', ...seqFwd(SET_B, 1) },
{ id:'lv27', name:'第二十七级', ...seqRev(SET_B, 1) },
{ id:'lv28', name:'第二十八级', ...randSet(SET_B) },
// 第二十九至三十二级:玩法与 1~4 级一致,字符集换为 6 7 8 9 0 - = Backspace
{ id:'lv29', name:'第二十九级', ...seqFwd(SET_6, 10) },
{ id:'lv30', name:'第三十级', ...seqFwd(SET_6, 1) },
{ id:'lv31', name:'第三十一级', ...seqRev(SET_6, 1) },
{ id:'lv32', name:'第三十二级', ...randSet(SET_6) },
// 第三十三至三十六级:玩法与 1~4 级一致,字符集换为 ~ ! @ # $ % Space
{ id:'lv33', name:'第三十三级', ...seqFwd(SET_7, 10) },
{ id:'lv34', name:'第三十四级', ...seqFwd(SET_7, 1) },
{ id:'lv35', name:'第三十五级', ...seqRev(SET_7, 1) },
{ id:'lv36', name:'第三十六级', ...randSet(SET_7) },
// 第三十七至四十级:玩法与 1~4 级一致,字符集换为 ^ & * ( ) _ +
{ id:'lv37', name:'第三十七级', ...seqFwd(SET_8, 10) },
{ id:'lv38', name:'第三十八级', ...seqFwd(SET_8, 1) },
{ id:'lv39', name:'第三十九级', ...seqRev(SET_8, 1) },
{ id:'lv40', name:'第四十级', ...randSet(SET_8) },
// 第四十一至四十四级:玩法与 1~4 级一致,字符集换为大写 A S D F G(需配合 Shift 击落)
{ id:'lv41', name:'第四十一级', ...seqFwd(SET_9, 10) },
{ id:'lv42', name:'第四十二级', ...seqFwd(SET_9, 1) },
{ id:'lv43', name:'第四十三级', ...seqRev(SET_9, 1) },
{ id:'lv44', name:'第四十四级', ...randSet(SET_9) },
// 第四十五至四十八级:玩法与 1~4 级一致,字符集换为大写 H J K L 与冒号 :(均需 Shift 击落)
{ id:'lv45', name:'第四十五级', ...seqFwd(SET_10, 10) },
{ id:'lv46', name:'第四十六级', ...seqFwd(SET_10, 1) },
{ id:'lv47', name:'第四十七级', ...seqRev(SET_10, 1) },
{ id:'lv48', name:'第四十八级', ...randSet(SET_10) },
// 第四十九至五十二级:玩法与 1~4 级一致,字符集换为大写 Z X C V B(需配合 Shift 击落)
{ id:'lv49', name:'第四十九级', ...seqFwd(SET_11, 10) },
{ id:'lv50', name:'第五十级', ...seqFwd(SET_11, 1) },
{ id:'lv51', name:'第五十一级', ...seqRev(SET_11, 1) },
{ id:'lv52', name:'第五十二级', ...randSet(SET_11) },
// 第五十三至五十六级:玩法与 1~4 级一致,字符集换为大写 N M 与尖括号/问号 < > ?(均需 Shift 击落)
{ id:'lv53', name:'第五十三级', ...seqFwd(SET_12, 10) },
{ id:'lv54', name:'第五十四级', ...seqFwd(SET_12, 1) },
{ id:'lv55', name:'第五十五级', ...seqRev(SET_12, 1) },
{ id:'lv56', name:'第五十六级', ...randSet(SET_12) },
// 第五十七至六十级:玩法与 1~4 级一致,字符集换为大写 Q W E R T(需配合 Shift 击落)
{ id:'lv57', name:'第五十七级', ...seqFwd(SET_13, 10) },
{ id:'lv58', name:'第五十八级', ...seqFwd(SET_13, 1) },
{ id:'lv59', name:'第五十九级', ...seqRev(SET_13, 1) },
{ id:'lv60', name:'第六十级', ...randSet(SET_13) },
// 第六十一至六十四级:玩法与 1~4 级一致,字符集换为大写 Y U I O P 与花括号/竖线 { } |(均需 Shift 击落)
{ id:'lv61', name:'第六十一级', ...seqFwd(SET_14, 10) },
{ id:'lv62', name:'第六十二级', ...seqFwd(SET_14, 1) },
{ id:'lv63', name:'第六十三级', ...seqRev(SET_14, 1) },
{ id:'lv64', name:'第六十四级', ...randSet(SET_14) },
];
const THEMES = {
space: { bg:['#0b1026','#1b2452'], item:['#7ee787','#a371f7','#58a6ff','#ff7b72'],
def:'#58a6ff', ground:'#1f6feb', star:true },
candy: { bg:['#ffe3f1','#ffd6a5'], item:['#ff6b9d','#ffd166','#8ac926','#1982c4','#6a4c93'],
def:'#ff6b9d', ground:'#ffb3d1', star:false },
neon: { bg:['#05010a','#11021f'], item:['#39ff14','#ff00ff','#00ffff','#ffff00','#ff3131'],
def:'#39ff14', ground:'#ff00ff', star:true },
};
// ---------- 多语言 ----------
let lang = 'en';
const I18N = {
zh: {
title:'⬇ 主键盘打字游戏 · 坠落拦截',
score:'得分', level:'级别', combo:'连击', lives:'生命', hKph:'速度KPH', acc:'准确率',
startH2:'坠落拦截',
startDesc:'字母 / 符号从天而降,用<b>主键盘</b>敲对应键击落它!<br>漏接掉到地面会扣生命,生命耗尽即结束。',
lblLevel:'级别', lblTheme:'主题', customDigits:'字母', customSymbols:'符号', customNums:'数字', customFunc:'功能键',
lblOrder:'顺序', lblEach:'每字符', unitEach:'次', lblSpeed:'速度', lblFall:'下落',
btnStart:'开始游戏', overH2:'游戏结束', btnAgain:'再来一局',
pauseH2:'已暂停', pauseTip:'按 <span class="keycap">空格</span> 或 <span class="keycap">Esc</span> 继续',
btnResume:'继续', btnRestart:'重新开始', btnPause:'暂停',
lblVol:'音量', lblMute:'静音', lblLang:'语言',
hint:'操作:用主键盘输入对应<b>字母 / 符号</b>击落目标 · <span class="keycap">空格</span> 或 <span class="keycap">Esc</span> 暂停 · 同一字母多个落下时,先打<b>最靠近地面</b>的那个',
finalScore:'最终得分', maxCombo:'最高连击', kph:'速度',
level:{ lv1:'第一级', lv2:'第二级', lv3:'第三级', lv4:'第四级', lv5:'第五级', lv6:'第六级', lv7:'第七级', lv8:'第八级', lv9:'第九级', lv10:'第十级', lv11:'第十一级', lv12:'第十二级', lv13:'第十三级', lv14:'第十四级', lv15:'第十五级', lv16:'第十六级', lv17:'第十七级', lv18:'第十八级', lv19:'第十九级', lv20:'第二十级', lv21:'第二十一级', lv22:'第二十二级', lv23:'第二十三级', lv24:'第二十四级', lv25:'第二十五级', lv26:'第二十六级', lv27:'第二十七级', lv28:'第二十八级', lv29:'第二十九级', lv30:'第三十级', lv31:'第三十一级', lv32:'第三十二级', lv33:'第三十三级', lv34:'第三十四级', lv35:'第三十五级', lv36:'第三十六级', lv37:'第三十七级', lv38:'第三十八级', lv39:'第三十九级', lv40:'第四十级', lv41:'第四十一级', lv42:'第四十二级', lv43:'第四十三级', lv44:'第四十四级', lv45:'第四十五级', lv46:'第四十六级', lv47:'第四十七级', lv48:'第四十八级', lv49:'第四十九级', lv50:'第五十级', lv51:'第五十一级', lv52:'第五十二级', lv53:'第五十三级', lv54:'第五十四级', lv55:'第五十五级', lv56:'第五十六级', lv57:'第五十七级', lv58:'第五十八级', lv59:'第五十九级', lv60:'第六十级', lv61:'第六十一级', lv62:'第六十二级', lv63:'第六十三级', lv64:'第六十四级', custom:'自选' },
levelOpts:{ '0':'第一级(CapsLock a s d f g · 正序·每字符10次)','1':'第二级(CapsLock a s d f g · 不重复)','2':'第三级(g f d s a capslock · 不重复)','3':'第四级(CapsLock a s d f g · 随机)','4':"第五级(h j k l ; ' enter · 每字符10次)",'5':"第六级(h j k l ; ' enter · 不重复)",'6':"第七级(enter ' ; l k j h · 不重复)",'7':"第八级(h j k l ; ' enter · 随机)",'8':'第九级(左Shift z x c v b · 正序·每字符10次)','9':'第十级(左Shift z x c v b · 不重复)','10':'第十一级(b v c x z 左Shift · 不重复)','11':'第十二级(左Shift z x c v b · 随机)','12':"第十三级(n m , . / 右Shift · 正序·每字符10次)",'13':"第十四级(n m , . / 右Shift · 不重复)",'14':"第十五级(右Shift / . , m n · 不重复)",'15':"第十六级(n m , . / 右Shift · 随机)",'16':"第十七级(Tab q w e r t · 正序·每字符10次)",'17':"第十八级(Tab q w e r t · 不重复)",'18':"第十九级(t r e w q Tab · 不重复)",'19':"第二十级(Tab q w e r t · 随机)",'20':'第二十一级(y u i o p [ ] \\ · 正序·每字符10次)','21':'第二十二级(y u i o p [ ] \\ · 不重复)','22':'第二十三级(\\ ] [ p o i u y · 不重复)','23':'第二十四级(y u i o p [ ] \\ · 随机)','24':'第二十五级(` 1 2 3 4 5 · 正序·每字符10次)','25':'第二十六级(` 1 2 3 4 5 · 不重复)','26':'第二十七级(5 4 3 2 1 ` · 不重复)','27':'第二十八级(` 1 2 3 4 5 · 随机)','28':'第二十九级(6 7 8 9 0 - = Backspace · 正序·每字符10次)','29':'第三十级(6 7 8 9 0 - = Backspace · 不重复)','30':'第三十一级(Backspace = - 0 9 8 7 6 · 不重复)','31':'第三十二级(6 7 8 9 0 - = Backspace · 随机)','32':'第三十三级(~ ! @ # $ % Space · 正序·每字符10次)','33':'第三十四级(~ ! @ # $ % Space · 不重复)','34':'第三十五级(Space % $ # @ ! ~ · 不重复)','35':'第三十六级(~ ! @ # $ % Space · 随机)','36':'第三十七级(^ & * ( ) _ + · 正序·每字符10次)','37':'第三十八级(^ & * ( ) _ + · 不重复)','38':'第三十九级(+ _ ) ( * & ^ · 不重复)','39':'第四十级(^ & * ( ) _ + · 随机)','40':'第四十一级(A S D F G · 正序·每字符10次 · 需Shift)','41':'第四十二级(A S D F G · 不重复 · 需Shift)','42':'第四十三级(G F D S A · 不重复 · 需Shift)','43':'第四十四级(A S D F G · 随机 · 需Shift)','45':'第四十五级(H J K L : " · 正序·每字符10次)','46':'第四十六级(H J K L : " · 不重复)','47':'第四十七级(" : L K J H · 不重复)','48':'第四十八级(H J K L : " · 随机)','49':'第四十九级(Z X C V B · 正序·每字符10次 · 需Shift)','50':'第五十级(Z X C V B · 不重复 · 需Shift)','51':'第五十一级(B V C X Z · 不重复 · 需Shift)','52':'第五十二级(Z X C V B · 随机 · 需Shift)','53':'第五十三级(N M < > ? · 正序·每字符10次 · 需Shift)','54':'第五十四级(N M < > ? · 不重复 · 需Shift)','55':'第五十五级(? > < M N · 不重复 · 需Shift)','56':'第五十六级(N M < > ? · 随机 · 需Shift)','57':'第五十七级(Q W E R T · 正序·每字符10次 · 需Shift)','58':'第五十八级(Q W E R T · 不重复 · 需Shift)','59':'第五十九级(T R E W Q · 不重复 · 需Shift)','60':'第六十级(Q W E R T · 随机 · 需Shift)','61':'第六十一级(Y U I O P { } | · 正序·每字符10次 · 需Shift)','62':'第六十二级(Y U I O P { } | · 不重复 · 需Shift)','63':'第六十三级(| } { P O I U Y · 不重复 · 需Shift)','64':'第六十四级(Y U I O P { } | · 随机 · 需Shift)','44':'自选(自定义)' },
theme:{ space:'太空入侵', candy:'糖果世界', neon:'霓虹像素' },
order:{ '正序':'正序', '倒序':'倒序', '随机':'随机' },
repeat:{ '1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','8':'8','10':'10' },
speed:{ '26':'慢','38':'中','60':'快','84':'很快' },
fall:{ '单个':'单个', '多个':'多个' },
langsel:{ zh:'简中', zhHant:'繁中', en:'EN' },
},
zhHant: {
title:'⬇ 主鍵盤打字遊戲 · 墜落攔截',
score:'得分', level:'級別', combo:'連擊', lives:'生命', hKph:'速度KPH', acc:'準確率',
startH2:'墜落攔截',
startDesc:'字母 / 符號從天而降,用<b>主鍵盤</b>敲對應鍵擊落它!<br>漏接掉到地面會扣生命,生命耗盡即結束。',
lblLevel:'級別', lblTheme:'主題', customDigits:'字母', customSymbols:'符號', customNums:'數字', customFunc:'功能鍵',
lblOrder:'順序', lblEach:'每字符', unitEach:'次', lblSpeed:'速度', lblFall:'下落',
btnStart:'開始遊戲', overH2:'遊戲結束', btnAgain:'再來一局',
pauseH2:'已暫停', pauseTip:'按 <span class="keycap">空格</span> 或 <span class="keycap">Esc</span> 繼續',
btnResume:'繼續', btnRestart:'重新開始', btnPause:'暫停',
lblVol:'音量', lblMute:'靜音', lblLang:'語言',
hint:'操作:用主鍵盤輸入對應<b>字母 / 符號</b>擊落目標 · <span class="keycap">空格</span> 或 <span class="keycap">Esc</span> 暫停 · 同一字母多個落下時,先打<b>最靠近地面</b>的那個',
finalScore:'最終得分', maxCombo:'最高連擊', kph:'速度',
level:{ lv1:'第一級', lv2:'第二級', lv3:'第三級', lv4:'第四級', lv5:'第五級', lv6:'第六級', lv7:'第七級', lv8:'第八級', lv9:'第九級', lv10:'第十級', lv11:'第十一級', lv12:'第十二級', lv13:'第十三級', lv14:'第十四級', lv15:'第十五級', lv16:'第十六級', lv17:'第十七級', lv18:'第十八級', lv19:'第十九級', lv20:'第二十級', lv21:'第二十一級', lv22:'第二十二級', lv23:'第二十三級', lv24:'第二十四級', lv25:'第二十五級', lv26:'第二十六級', lv27:'第二十七級', lv28:'第二十八級', lv29:'第二十九級', lv30:'第三十級', lv31:'第三十一級', lv32:'第三十二級', lv33:'第三十三級', lv34:'第三十四級', lv35:'第三十五級', lv36:'第三十六級', lv37:'第三十七級', lv38:'第三十八級', lv39:'第三十九級', lv40:'第四十級', lv41:'第四十一级', lv42:'第四十二級', lv43:'第四十三級', lv44:'第四十四級', lv45:'第四十五級', lv46:'第四十六級', lv47:'第四十七級', lv48:'第四十八級', lv49:'第四十九級', lv50:'第五十級', lv51:'第五十一級', lv52:'第五十二級', lv53:'第五十三級', lv54:'第五十四級', lv55:'第五十五級', lv56:'第五十六級', lv57:'第五十七級', lv58:'第五十八級', lv59:'第五十九級', lv60:'第六十級', lv61:'第六十一級', lv62:'第六十二級', lv63:'第六十三級', lv64:'第六十四級', custom:'自訂' },
levelOpts:{ '0':'第一級(CapsLock a s d f g · 正序·每字符10次)','1':'第二級(CapsLock a s d f g · 不重複)','2':'第三級(g f d s a capslock · 不重複)','3':'第四級(CapsLock a s d f g · 隨機)','4':"第五級(h j k l ; ' enter · 每字符10次)",'5':"第六級(h j k l ; ' enter · 不重複)",'6':"第七級(enter ' ; l k j h · 不重複)",'7':"第八級(h j k l ; ' enter · 隨機)",'8':'第九級(左Shift z x c v b · 正序·每字符10次)','9':'第十級(左Shift z x c v b · 不重複)','10':'第十一級(b v c x z 左Shift · 不重複)','11':'第十二級(左Shift z x c v b · 隨機)','12':"第十三級(n m , . / 右Shift · 正序·每字符10次)",'13':"第十四級(n m , . / 右Shift · 不重複)",'14':"第十五級(右Shift / . , m n · 不重複)",'15':"第十六級(n m , . / 右Shift · 隨機)",'16':"第十七級(Tab q w e r t · 正序·每字符10次)",'17':"第十八級(Tab q w e r t · 不重複)",'18':"第十九級(t r e w q Tab · 不重複)",'19':"第二十級(Tab q w e r t · 隨機)",'20':'第二十一級(y u i o p [ ] \\ · 正序·每字符10次)','21':'第二十二級(y u i o p [ ] \\ · 不重複)','22':'第二十三級(\\ ] [ p o i u y · 不重複)','23':'第二十四級(y u i o p [ ] \\ · 隨機)','24':'第二十五級(` 1 2 3 4 5 · 正序·每字符10次)','25':'第二十六級(` 1 2 3 4 5 · 不重複)','26':'第二十七級(5 4 3 2 1 ` · 不重複)','27':'第二十八級(` 1 2 3 4 5 · 隨機)','28':'第二十九級(6 7 8 9 0 - = Backspace · 正序·每字符10次)','29':'第三十級(6 7 8 9 0 - = Backspace · 不重複)','30':'第三十一级(Backspace = - 0 9 8 7 6 · 不重複)','31':'第三十二級(6 7 8 9 0 - = Backspace · 隨機)','32':'第三十三級(~ ! @ # $ % Space · 正序·每字符10次)','33':'第三十四級(~ ! @ # $ % Space · 不重複)','34':'第三十五級(Space % $ # @ ! ~ · 不重複)','35':'第三十六級(~ ! @ # $ % Space · 隨機)','36':'第三十七級(^ & * ( ) _ + · 正序·每字符10次)','37':'第三十八級(^ & * ( ) _ + · 不重複)','38':'第三十九級(+ _ ) ( * & ^ · 不重複)','39':'第四十級(^ & * ( ) _ + · 隨機)','40':'第四十一级(A S D F G · 正序·每字符10次 · 需Shift)','41':'第四十二級(A S D F G · 不重複 · 需Shift)','42':'第四十三級(G F D S A · 不重複 · 需Shift)','43':'第四十四級(A S D F G · 隨機 · 需Shift)','45':'第四十五級(H J K L : " · 正序·每字符10次)','46':'第四十六級(H J K L : " · 不重複)','47':'第四十七級(" : L K J H · 不重複)','48':'第四十八級(H J K L : " · 隨機)','49':'第四十九級(Z X C V B · 正序·每字符10次 · 需Shift)','50':'第五十級(Z X C V B · 不重複 · 需Shift)','51':'第五十一級(B V C X Z · 不重複 · 需Shift)','52':'第五十二級(Z X C V B · 隨機 · 需Shift)','53':'第五十三級(N M < > ? · 正序·每字符10次 · 需Shift)','54':'第五十四級(N M < > ? · 不重複 · 需Shift)','55':'第五十五級(? > < M N · 不重複 · 需Shift)','56':'第五十六級(N M < > ? · 隨機 · 需Shift)','57':'第五十七級(Q W E R T · 正序·每字符10次 · 需Shift)','58':'第五十八級(Q W E R T · 不重複 · 需Shift)','59':'第五十九級(T R E W Q · 不重複 · 需Shift)','60':'第六十級(Q W E R T · 隨機 · 需Shift)','61':'第六十一級(Y U I O P { } | · 正序·每字符10次 · 需Shift)','62':'第六十二級(Y U I O P { } | · 不重複 · 需Shift)','63':'第六十三級(| } { P O I U Y · 不重複 · 需Shift)','64':'第六十四級(Y U I O P { } | · 隨機 · 需Shift)','44':'自訂(自定義)' },
theme:{ space:'太空入侵', candy:'糖果世界', neon:'霓虹像素' },
order:{ '正序':'正序', '倒序':'倒序', '随机':'隨機' },
repeat:{ '1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','8':'8','10':'10' },
speed:{ '26':'慢','38':'中','60':'快','84':'很快' },
fall:{ '单个':'單個', '多个':'多個' },
langsel:{ zh:'簡中', zhHant:'繁中', en:'EN' },
},
en: {
title:'⬇ Main Keyboard Typing Game · Falling Intercept',
score:'Score', level:'Level', combo:'Combo', lives:'Lives', hKph:'Speed KPH', acc:'Accuracy',
startH2:'Falling Intercept',
startDesc:'Letters / symbols fall from the sky—type the matching key on the <b>main keyboard</b> to shoot them down!<br>Miss one and it hits the ground, costing a life; lose all lives and the game ends.',
lblLevel:'Level', lblTheme:'Theme', customDigits:'Letters', customSymbols:'Symbols', customNums:'Digits', customFunc:'Function keys',
lblOrder:'Order', lblEach:'Each', unitEach:'×', lblSpeed:'Speed', lblFall:'Falling',
btnStart:'Start', overH2:'Game Over', btnAgain:'Play Again',
pauseH2:'Paused', pauseTip:'Press <span class="keycap">Space</span> or <span class="keycap">Esc</span> to resume',
btnResume:'Resume', btnRestart:'Restart', btnPause:'Pause',
lblVol:'Volume', lblMute:'Mute', lblLang:'Language',
hint:'Use the main keyboard to type the matching <b>letter / symbol</b> to shoot targets · <span class="keycap">Space</span> or <span class="keycap">Esc</span> to pause · when several of the same letter fall, hit the one <b>closest to the ground</b> first',
finalScore:'Final Score', maxCombo:'Max Combo', kph:'Speed',
level:{ lv1:'Lv.1', lv2:'Lv.2', lv3:'Lv.3', lv4:'Lv.4', lv5:'Lv.5', lv6:'Lv.6', lv7:'Lv.7', lv8:'Lv.8', lv9:'Lv.9', lv10:'Lv.10', lv11:'Lv.11', lv12:'Lv.12', lv13:'Lv.13', lv14:'Lv.14', lv15:'Lv.15', lv16:'Lv.16', lv17:'Lv.17', lv18:'Lv.18', lv19:'Lv.19', lv20:'Lv.20', lv21:'Lv.21', lv22:'Lv.22', lv23:'Lv.23', lv24:'Lv.24', lv25:'Lv.25', lv26:'Lv.26', lv27:'Lv.27', lv28:'Lv.28', lv29:'Lv.29', lv30:'Lv.30', lv31:'Lv.31', lv32:'Lv.32', lv33:'Lv.33', lv34:'Lv.34', lv35:'Lv.35', lv36:'Lv.36', lv37:'Lv.37', lv38:'Lv.38', lv39:'Lv.39', lv40:'Lv.40', lv41:'Lv.41', lv42:'Lv.42', lv43:'Lv.43', lv44:'Lv.44', lv45:'Lv.45', lv46:'Lv.46', lv47:'Lv.47', lv48:'Lv.48', lv49:'Lv.49', lv50:'Lv.50', lv51:'Lv.51', lv52:'Lv.52', lv53:'Lv.53', lv54:'Lv.54', lv55:'Lv.55', lv56:'Lv.56', lv57:'Lv.57', lv58:'Lv.58', lv59:'Lv.59', lv60:'Lv.60', lv61:'Lv.61', lv62:'Lv.62', lv63:'Lv.63', lv64:'Lv.64', custom:'Custom' },
levelOpts:{ '0':'Lv.1 (CapsLock a s d f g · forward · 10× each)','1':'Lv.2 (CapsLock a s d f g · once)','2':'Lv.3 (g f d s a capslock · once)','3':'Lv.4 (CapsLock a s d f g · random)','4':"Lv.5 (h j k l ; ' enter · 10× each)",'5':"Lv.6 (h j k l ; ' enter · once)",'6':"Lv.7 (enter ' ; l k j h · once)",'7':"Lv.8 (h j k l ; ' enter · random)",'8':"Lv.9 (LShift z x c v b · 10× each)",'9':"Lv.10 (LShift z x c v b · once)",'10':"Lv.11 (b v c x z LShift · once)",'11':"Lv.12 (LShift z x c v b · random)",'12':"Lv.13 (n m , . / RShift · 10× each)",'13':"Lv.14 (n m , . / RShift · once)",'14':"Lv.15 (RShift / . , m n · once)",'15':"Lv.16 (n m , . / RShift · random)",'16':"Lv.17 (Tab q w e r t · 10× each)",'17':"Lv.18 (Tab q w e r t · once)",'18':"Lv.19 (t r e w q Tab · once)",'19':"Lv.20 (Tab q w e r t · random)",'20':"Lv.21 (y u i o p [ ] \\ · forward · 10× each)",'21':"Lv.22 (y u i o p [ ] \\ · once)",'22':"Lv.23 (\\ ] [ p o i u y · reverse · once)",'23':"Lv.24 (y u i o p [ ] \\ · random)",'24':"Lv.25 (` 1 2 3 4 5 · forward · 10× each)",'25':"Lv.26 (` 1 2 3 4 5 · once)",'26':"Lv.27 (5 4 3 2 1 ` · reverse · once)",'27':"Lv.28 (` 1 2 3 4 5 · random)",'28':"Lv.29 (6 7 8 9 0 - = Backspace · forward · 10× each)",'29':"Lv.30 (6 7 8 9 0 - = Backspace · once)",'30':"Lv.31 (Backspace = - 0 9 8 7 6 · reverse · once)",'31':"Lv.32 (6 7 8 9 0 - = Backspace · random)",'32':"Lv.33 (~ ! @ # $ % Space · forward · 10× each)",'33':"Lv.34 (~ ! @ # $ % Space · once)",'34':"Lv.35 (Space % $ # @ ! ~ · reverse · once)",'35':"Lv.36 (~ ! @ # $ % Space · random)",'36':"Lv.37 (^ & * ( ) _ + · forward · 10× each)",'37':"Lv.38 (^ & * ( ) _ + · once)",'38':"Lv.39 (+ _ ) ( * & ^ · reverse · once)",'39':"Lv.40 (^ & * ( ) _ + · random)",'40':"Lv.41 (A S D F G · forward · 10× each · Shift)",'41':"Lv.42 (A S D F G · once · Shift)",'42':"Lv.43 (G F D S A · reverse · once · Shift)",'43':"Lv.44 (A S D F G · random · Shift)",'45':"Lv.45 (H J K L : \" · forward · 10× each)",'46':"Lv.46 (H J K L : \" · once)",'47':"Lv.47 (\" : L K J H · reverse · once)",'48':"Lv.48 (H J K L : \" · random)",'49':"Lv.49 (Z X C V B · forward · 10× each · Shift)",'50':"Lv.50 (Z X C V B · once · Shift)",'51':"Lv.51 (B V C X Z · reverse · once · Shift)",'52':"Lv.52 (Z X C V B · random · Shift)",'53':"Lv.53 (N M < > ? · forward · 10× each · Shift)",'54':"Lv.54 (N M < > ? · once · Shift)",'55':"Lv.55 (? > < M N · reverse · once · Shift)",'56':"Lv.56 (N M < > ? · random · Shift)",'57':"Lv.57 (Q W E R T · forward · 10× each · Shift)",'58':"Lv.58 (Q W E R T · once · Shift)",'59':"Lv.59 (T R E W Q · reverse · once · Shift)",'60':"Lv.60 (Q W E R T · random · Shift)",'61':"Lv.61 (Y U I O P { } | · forward · 10× each · Shift)",'62':"Lv.62 (Y U I O P { } | · once · Shift)",'63':"Lv.63 (| } { P O I U Y · reverse · once · Shift)",'64':"Lv.64 (Y U I O P { } | · random · Shift)",'44':"Custom" },
theme:{ space:'Space', candy:'Candy', neon:'Neon' },
order:{ '正序':'Forward', '倒序':'Reverse', '随机':'Random' },
repeat:{ '1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','8':'8','10':'10' },
speed:{ '26':'Slow','38':'Med','60':'Fast','84':'Very Fast' },
fall:{ '单个':'One', '多个':'Many' },
langsel:{ zh:'Simplified', zhHant:'Traditional', en:'English' },
},
};
function applyLang(l){
lang = l;
document.documentElement.lang = (l==='en') ? 'en' : 'zh-Hans';
document.title = I18N[l].title;
document.querySelectorAll('[data-i18n]').forEach(el=>{
const k = el.dataset.i18n; if(I18N[l][k]!=null) el.textContent = I18N[l][k];
});
document.querySelectorAll('[data-i18n-html]').forEach(el=>{
const k = el.dataset.i18nHtml; if(I18N[l][k]!=null) el.innerHTML = I18N[l][k];
});
document.querySelectorAll('[data-i18n-opts]').forEach(sel=>{
const map = I18N[l][sel.dataset.i18nOpts];
if(map) Array.from(sel.options).forEach(o=>{ if(map[o.value]!=null) o.textContent = map[o.value]; });
});
const hl = document.getElementById('hLevel');
if(hl) hl.textContent = I18N[l].level[activeLevel.id] || '';
}
// ---------- 状态 ----------
let state, levelIdx = 0, themeKey = 'space';
let last = performance.now();
function freshState(){ return GameCore.createState(); }
// ---------- 音频(WebAudio 实时合成,无外部文件) ----------
let actx = null, master = null;
function initAudio(){
if(actx) return;
actx = new (window.AudioContext||window.webkitAudioContext)();
master = actx.createGain();
master.connect(actx.destination);
applyVol();
}
function applyVol(){
if(!master) return;
const v = +document.getElementById('vol').value/100 * 0.5;
master.gain.value = document.getElementById('mute').checked ? 0 : v;
}
function tone(freq, dur, type='square', vol=0.6){
if(!actx) return;
const o = actx.createOscillator(), g = actx.createGain();
o.type = type; o.frequency.value = freq;
g.gain.setValueAtTime(vol, actx.currentTime);
g.gain.exponentialRampToValueAtTime(0.0001, actx.currentTime+dur);
o.connect(g); g.connect(master);
o.start(); o.stop(actx.currentTime+dur);
}
function noise(dur=0.18, vol=0.5){
if(!actx) return;
const n = actx.sampleRate*dur, buf = actx.createBuffer(1,n,actx.sampleRate);
const d = buf.getChannelData(0);
for(let i=0;i<n;i++) d[i] = (Math.random()*2-1)*(1-i/n);
const src = actx.createBufferSource(); src.buffer = buf;
const g = actx.createGain(); g.gain.value = vol;
src.connect(g); g.connect(master); src.start();
}
const SFX = {
shoot:()=>tone(880,0.05,'square',0.4),
boom: ()=>{ noise(0.18,0.5); tone(140,0.18,'sawtooth',0.4); },
err: ()=>tone(180,0.16,'sawtooth',0.45),
level:()=>{ [523,659,784,1046].forEach((f,i)=>setTimeout(()=>tone(f,0.12,'triangle',0.5),i*70)); },
over: ()=>{ [440,330,247,165].forEach((f,i)=>setTimeout(()=>tone(f,0.2,'sawtooth',0.5),i*130)); },
};
// ---------- 工具 ----------
// 字母保留大小写:小写目标用对应字母键,大写目标(如 A)需用 Shift+字母 击落
const isChar = k => /^[a-zA-Z]$/.test(k) || SYMS.includes(k) || k==='Enter' || k==='CapsLock' || k==='LShift' || k==='RShift' || k==='Tab' || k==='Space';
function normKey(k){ return k; }
const rnd = (a,b)=>a+Math.random()*(b-a);
const pick = arr => arr[(Math.random()*arr.length)|0];
// 按气泡亮度选反色字符,保证字符清晰可读
function textOn(c){
const r=parseInt(c.slice(1,3),16), g=parseInt(c.slice(3,5),16), b=parseInt(c.slice(5,7),16);
const L = (0.299*r + 0.587*g + 0.114*b)/255;
return L > 0.5 ? '#0a0e1a' : '#ffffff';
}
// 特殊键显示短名;其余字符原样显示
function charLabel(ch){
const M = { Space:'␣', Enter:'⏎', CapsLock:'⇪', LShift:'⇧', RShift:'⇧', Tab:'⇥', Backspace:'⌫' };
return M[ch] != null ? M[ch] : ch;
}
let activeLevel = LEVELS[0];
function curLevel(){ return activeLevel; }
function effSpeed(){ return GameCore.effSpeed(curLevel(), state.score); }
function effSpawn(){ return GameCore.effSpawn(curLevel(), state.score); }
// ---------- 生成 / 击落 ----------
function spawnItem(){
const lv = curLevel(), th = THEMES[themeKey];
const ch = GameCore.nextChar(lv, state.seqIdx); // 纯玩法:决定下一个字符
state.seqIdx++;
state.items.push({ ch, x:rnd(34, W-34), y:-20, r:25, c:pick(th.item) }); // 表现层:位置/颜色
}
function hitItem(key){
const target = GameCore.findTarget(state.items, key); // 纯玩法:命中判定
state.presses++;
if(!target){ state.combo = 0; SFX.err(); return; }
state.combo++; state.maxCombo = Math.max(state.maxCombo, state.combo);
state.hits++;
const pts = GameCore.scoreFor(state.combo); // 纯玩法:计分
state.score += pts;
// —— 以下为表现层(音画),非玩法逻辑 ——
explode(target.x, target.y, target.c);
state.beam = { x1:DEF_X, y1:DEF_Y, x2:target.x, y2:target.y, life:0.12 };
state.flash = 0.12;
state.items.splice(state.items.indexOf(target),1);
SFX.shoot(); SFX.boom();
}
function groundHit(it){
state.items.splice(state.items.indexOf(it),1);
explode(it.x, GROUND_Y, it.c); // 表现层
const over = GameCore.applyMiss(state); // 纯玩法:扣命 / 是否结束
SFX.err(); // 音效
if(over) gameOver(); // 流程
}
function explode(x,y,color){
for(let i=0;i<14;i++){
const a = Math.random()*Math.PI*2, sp = rnd(40,180);
state.particles.push({ x,y, vx:Math.cos(a)*sp, vy:Math.sin(a)*sp,
life:rnd(0.3,0.7), max:0.7, c:color });
}
}
// ---------- 主循环 ----------
function update(dt){
state.spawnTimer -= dt*1000;
if(state.spawnTimer<=0){
if(curLevel().oneAtATime && state.items.length>0){
state.spawnTimer = 80; // 等当前字符被击落/落地后再出下一个
} else {
spawnItem();
state.spawnTimer = curLevel().oneAtATime ? 350 : effSpawn();
}
}
const sp = effSpeed();
for(const it of state.items.slice()){
it.y += sp*dt;
if(it.y >= GROUND_Y) groundHit(it);
}
for(const p of state.particles.slice()){
p.x += p.vx*dt; p.y += p.vy*dt; p.vy += 120*dt; p.life -= dt;
if(p.life<=0) state.particles.splice(state.particles.indexOf(p),1);
}
if(state.beam){ state.beam.life -= dt; if(state.beam.life<=0) state.beam=null; }
if(state.flash>0) state.flash -= dt;
updateHUD();
}
function draw(){
const th = THEMES[themeKey];
// 背景
const g = ctx.createLinearGradient(0,0,0,H);
g.addColorStop(0, th.bg[0]); g.addColorStop(1, th.bg[1]);
ctx.fillStyle = g; ctx.fillRect(0,0,W,H);
if(th.star){
ctx.fillStyle='rgba(255,255,255,.5)';
for(let i=0;i<40;i++){ const x=(i*97%W), y=((i*53)%(GROUND_Y-20)); ctx.fillRect(x,y,2,2); }
}
// 地面
ctx.fillStyle = th.ground; ctx.fillRect(0, GROUND_Y, W, H-GROUND_Y);
ctx.fillStyle = themeKey==='candy' ? 'rgba(255,255,255,.5)' : 'rgba(255,255,255,.15)';
ctx.fillRect(0, GROUND_Y, W, 3);
// 目标
for(const it of state.items){
ctx.beginPath(); ctx.arc(it.x, it.y, it.r, 0, Math.PI*2);
ctx.fillStyle = it.c; ctx.fill();
ctx.fillStyle = 'rgba(0,0,0,.25)'; ctx.beginPath();
ctx.arc(it.x-5, it.y-5, 3, 0, Math.PI*2); ctx.arc(it.x+5, it.y-5, 3, 0, Math.PI*2); ctx.fill();
const label = charLabel(it.ch);
ctx.fillStyle = textOn(it.c); ctx.font = 'bold ' + (label.length > 2 ? 16 : 26) + 'px monospace';
ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.fillText(label, it.x, it.y+1);
}
// 粒子
for(const p of state.particles){
ctx.globalAlpha = Math.max(0, p.life/p.max);
ctx.fillStyle = p.c; ctx.fillRect(p.x-2, p.y-2, 4, 4);
}
ctx.globalAlpha = 1;
// 激光束
if(state.beam){
ctx.strokeStyle = th.def; ctx.lineWidth = 3; ctx.globalAlpha = state.beam.life/0.12;
ctx.beginPath(); ctx.moveTo(state.beam.x1, state.beam.y1);
ctx.lineTo(state.beam.x2, state.beam.y2); ctx.stroke();
ctx.globalAlpha = 1;
}
// 防御炮台(视觉形象)
drawDefender(th);
}
function drawDefender(th){
const flash = state.flash>0;
ctx.save();
ctx.translate(DEF_X, DEF_Y);
// 底座
ctx.fillStyle = th.def;
ctx.beginPath(); ctx.moveTo(-26,26); ctx.lineTo(26,26);
ctx.lineTo(16,-6); ctx.lineTo(-16,-6); ctx.closePath(); ctx.fill();
// 炮管
ctx.fillStyle = flash ? '#fff' : '#fff';
ctx.fillRect(-5,-26,10,22);
// 眼睛
ctx.fillStyle = '#04122b';
ctx.beginPath(); ctx.arc(-8,8,3,0,7); ctx.arc(8,8,3,0,7); ctx.fill();
ctx.restore();
}
function updateHUD(){
document.getElementById('hScore').textContent = state.score;
const lv = curLevel();
const base = I18N[lang].level[lv.id] || lv.name;
const lvlTxt = base + '·R' + GameCore.roundOf(lv, state.seqIdx);
document.getElementById('hLevel').textContent = lvlTxt;
document.getElementById('hCombo').textContent = state.combo;
document.getElementById('hLives').textContent = '♥'.repeat(Math.max(0,state.lives)) || '—';
const mins = Math.max(1e-4,(performance.now()-state.startTime)/60000);
document.getElementById('hKph').textContent = Math.round(state.hits/mins);
const acc = state.presses ? Math.round(state.hits/state.presses*100) : 100;
document.getElementById('hAcc').textContent = acc + '%';
}
function loop(now){
const dt = Math.min((now-last)/1000, 0.05); last = now;
if(state.running && !state.paused && !state.over) update(dt);
draw();
requestAnimationFrame(loop);
}
// ---------- 流程控制 ----------
function buildCustom(){
const chars = [];
document.querySelectorAll('#customPanel input[data-ch]:checked').forEach(cb => chars.push(cb.dataset.ch));
if(chars.length === 0) chars.push('a');
const order = document.getElementById('cOrder').value;
const rep = +document.getElementById('cRepeat').value || 1;
const speed = +document.getElementById('cSpeed').value || 40;
const single = document.getElementById('cFall').value === '单个';
const pattern = order==='正序' ? chars.slice()
: order==='倒序' ? chars.slice().reverse()
: chars.slice();
return { id:'custom', name:'自选', mode: order==='随机' ? 'rand' : 'seq',
pattern, set: chars.slice(), speed,
spawn: single ? 350 : 1000, ramp:0.0008,
oneAtATime: single, repeat: rep };
}
function startGame(){
initAudio(); if(actx.state==='suspended') actx.resume();
levelIdx = +document.getElementById('selLevel').value;
// 下拉中「自选」占用了选项值 44,等级选项 45–64 需 -1 才对应 LEVELS[44–63]
const lvIndex = (levelIdx === 44) ? -1 : (levelIdx > 44 ? levelIdx - 1 : levelIdx);
activeLevel = (lvIndex < 0) ? buildCustom() : LEVELS[lvIndex];
themeKey = document.getElementById('selTheme').value;
document.getElementById('selTheme2').value = themeKey;
state = freshState();
state.running = true; state.startTime = performance.now();
document.getElementById('startScreen').classList.add('hidden');
document.getElementById('overScreen').classList.add('hidden');
document.getElementById('pauseScreen').classList.add('hidden');
document.getElementById('btnPause').textContent = I18N[lang].btnPause;
updateHUD();
}
function togglePause(){
if(!state.running || state.over) return;
state.paused = !state.paused;
document.getElementById('pauseScreen').classList.toggle('hidden', !state.paused);
document.getElementById('btnPause').textContent = state.paused ? I18N[lang].btnResume : I18N[lang].btnPause;
}
function gameOver(){
state.over = true; state.running = false; SFX.over();
const mins = Math.max(1e-4,(performance.now()-state.startTime)/60000);
const kph = Math.round(state.hits/mins);
const acc = state.presses ? Math.round(state.hits/state.presses*100) : 100;
const t = I18N[lang];
document.getElementById('overStats').innerHTML =
`${t.finalScore} <b>${state.score}</b> · ${t.maxCombo} <b>${state.maxCombo}</b><br>` +
`${t.kph} <b>${kph}</b> KPH · ${t.acc} <b>${acc}%</b>`;
document.getElementById('overScreen').classList.remove('hidden');
}
// 返回开始界面,可重新选择级别 / 自定义
function showStartScreen(){
state.running = false; state.paused = false; state.over = false;
document.getElementById('startScreen').classList.remove('hidden');
document.getElementById('pauseScreen').classList.add('hidden');
document.getElementById('overScreen').classList.add('hidden');
document.getElementById('btnPause').textContent = I18N[lang].btnPause;
}
// ---------- 事件 ----------
window.addEventListener('keydown', e => {
const lv = curLevel();
const spaceIsTarget = (lv.pattern||[]).includes('Space') || (lv.set||[]).includes('Space');
if(e.key==='Escape'){
if(state && state.running){ e.preventDefault(); togglePause(); }
return;
}
if(e.key===' '){ // 空格:本关把空格当目标字符时作为击落键,否则作为暂停键
if(!spaceIsTarget){ if(state && state.running){ e.preventDefault(); togglePause(); } return; }
if(!state || !state.running || state.paused || state.over) return;
if(isChar('Space')){ e.preventDefault(); hitItem('Space'); }
return;
}
if(!state || !state.running || state.paused || state.over) return;
// Shift 单独按下:仅当本关把 Shift 当作目标字符时才击落,否则仅作修饰键,忽略
if(e.key === 'Shift'){
const chars = lv.pattern || lv.set || [];
if(chars.includes('LShift') || chars.includes('RShift')){
const k = (e.location === 1) ? 'LShift' : 'RShift';
if(isChar(k)){ e.preventDefault(); hitItem(k); }
}
return;
}
let k = normKey(e.key);
if(isChar(k)){ e.preventDefault(); hitItem(k); }
});
document.getElementById('btnStart').onclick = startGame;
document.getElementById('btnRestart').onclick = startGame;
document.getElementById('btnPause').onclick = togglePause;
document.getElementById('btnResume').onclick = togglePause;
document.getElementById('btnRestartPaused').onclick = showStartScreen;
document.getElementById('vol').oninput = applyVol;
document.getElementById('mute').onchange = applyVol;
document.getElementById('selTheme').onchange = e => {
themeKey = e.target.value; document.getElementById('selTheme2').value = themeKey;
};
document.getElementById('selTheme2').onchange = e => {
themeKey = e.target.value; document.getElementById('selTheme').value = themeKey;
};
document.getElementById('selLevel').onchange = e => {
document.getElementById('customPanel').classList.toggle('hidden', e.target.value !== '44');
};
// 自选面板:列出 1~64 级出现过的全部字符(去重),按 字母 / 符号 / 数字 / 功能键 分组
const CUSTOM_POOL = (() => {
const seen = new Set(), out = [];
[SET_L,SET_R,SET_Z,SET_4,SET_5,SET_Y,SET_B,SET_6,SET_7,SET_8,SET_9,SET_10,SET_11,SET_12,SET_13,SET_14]
.forEach(s => (s||[]).forEach(c => { if(!seen.has(c)){ seen.add(c); out.push(c); } }));
return out;
})();
const _isL = c => /^[a-zA-Z]$/.test(c);
const _isD = c => /^[0-9]$/.test(c);
const _isF = c => ['CapsLock','Enter','LShift','RShift','Tab','Space','Backspace'].includes(c);
const poolLetters = CUSTOM_POOL.filter(_isL).sort((a,b)=> a.toLowerCase()===b.toLowerCase() ? (a<b?1:-1) : (a.toLowerCase()<b.toLowerCase()?-1:1));
const poolSyms = CUSTOM_POOL.filter(c=>!_isL(c)&&!_isD(c)&&!_isF(c)).sort();
const poolDigits = CUSTOM_POOL.filter(_isD).sort();
const poolFuncs = ['Space','Enter','Tab','CapsLock','Backspace','LShift','RShift'].filter(c=>CUSTOM_POOL.includes(c));
function mkChip(ch){
const label = document.createElement('label');
const cb = document.createElement('input');
cb.type = 'checkbox'; cb.dataset.ch = ch; cb.checked = true;
label.appendChild(cb);
label.appendChild(document.createTextNode(' ' + charLabel(ch)));
return label;
}
const mountChips = (id, list) => { const box = document.getElementById(id); list.forEach(ch => box.appendChild(mkChip(ch))); };
mountChips('chDigits', poolLetters);
mountChips('chSyms', poolSyms);
mountChips('chNums', poolDigits);
mountChips('chFunc', poolFuncs);
// 初始
state = freshState();
document.getElementById('selLang').onchange = e => applyLang(e.target.value);
applyLang('en');
requestAnimationFrame(loop);
})();
</script>
</body>
</html>