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}