方块TETRIS
得分0
最高0
等级1
消行0
已 暂 停

按 P 或点击继续

游 戏 结 束
本 局 得 分0
最高分 0
消行 0 等级 1

方块

Tetris · Canvas Edition

历史最高0
选 择 皮 肤
← → 移动↑ 旋转↓ 加速 空格 落底C 暂存P 暂停ESC 老板键

移动端可直接使用屏幕下方触控按键

player-engine.ts — tetris-lab — Visual Studio Code
—▢✕
⧉⌕⑂▷⛭
资源管理器
▾ tetris-lab
▾ src
▾ core
TS player-engine.ts
TS board.ts
TS skins.ts
JS input.ts
▸ components
▸ utils
◇ package.json
◇ tsconfig.json
◇ README.md
▸ public
▸ tests
TS player-engine.ts ✕
TS board.ts
MD README.md
src › core › player-engine.ts › PlayerEngine
1import { EventBus } from '@/core/event-bus';
2import { createBoard, type BoardState } from '@/core/board';
3import type { Piece, GravityCurve } from '@/types';
4
5/** 重力曲线:随等级递减的落子间隔(毫秒) */
6const GRAVITY: GravityCurve = {
7 base: 800,
8 decay: 0.82,
9 min: 60,
10};
11
12export class PlayerEngine {
13 private board: BoardState;
14 private active: Piece | null = null;
15 private combo = 0;
16
17 constructor(private readonly bus: EventBus) {
18 this.board = createBoard(10, 20);
19 }
20
21 /** 消行计分:多行奖励 + 连击加成 */
22 resolve(lines: number): number {
23 const table = [0, 100, 300, 500, 800];
24 const bonus = this.combo > 0 ? this.combo * 50 : 0;
25 return (table[lines] ?? 0) * this.level + bonus;
26 }
27
28 private tick(dt: number) {
29 const interval = Math.max(GRAVITY.min, GRAVITY.base * GRAVITY.decay ** (this.level - 1));
30 this.accumulator += dt;
31 while (this.accumulator >= interval) {
32 this.accumulator -= interval;
33 this.bus.emit('step', { silent: true });
34 }
35 }
36}
终端输出问题调试控制台
$ pnpm dev
VITE v5.2.11 ready in 412 ms
➜ Local: http://localhost:5173/
[tsc] 0 errors · 0 warnings — watching for file changes
⑂ main*⊗ 0⚠ 0
Ln 25, Col 42UTF-8TypeScript◔