From 59df63504b75a7c3edbc7d79534b1681c189d6ee Mon Sep 17 00:00:00 2001 From: Cloud Bot Date: Sat, 21 Mar 2026 09:45:07 +0000 Subject: [PATCH] =?UTF-8?q?feat(game/GameManager):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=9A=BE=E5=BA=A6=E5=AD=97=E6=AE=B5=E3=80=81=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E5=92=8C=E6=B3=A2=E6=AC=A1=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/GameManager.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/game/GameManager.ts b/game/GameManager.ts index dfa120e..99efbf0 100644 --- a/game/GameManager.ts +++ b/game/GameManager.ts @@ -2,6 +2,7 @@ import { INITIAL_HC, INITIAL_KPI, } from './constants' +import type { DifficultyLevel } from './data/mapConfigs' type GameState = 'idle' | 'playing' | 'paused' | 'victory' | 'defeat' @@ -17,6 +18,11 @@ export class GameManager { public currentWave: number = 0 public gameState: GameState = 'idle' + // 难度与地图状态 + public difficulty: DifficultyLevel = 'normal' + public currentMapIndex: number = 0 // 0=地图1, 1=地图2, 2=地图3 + public totalWaveCleared: number = 0 // 总计已清理波次 + // 事件回调(Scene 通过这些 hook 更新 HUD) public onHCChange: ((hc: number) => void)[] = [] public onKPIChange: ((kpi: number) => void)[] = [] @@ -32,21 +38,28 @@ export class GameManager { return GameManager.instance } - /** 重置游戏状态(新局开始时调用) */ + /** 设置难度 */ + setDifficulty(d: DifficultyLevel): void { + this.difficulty = d + } + + /** 重置游戏状态(保留难度,重置其他字段) */ reset(): void { this.hc = INITIAL_HC this.kpi = INITIAL_KPI this.currentWave = 0 this.gameState = 'idle' + this.currentMapIndex = 0 + this.totalWaveCleared = 0 this.onHCChange = [] this.onKPIChange = [] this.onGameOver = [] this.onVictory = [] + // difficulty 保留,不重置 } /** * 扣除 HC,余额不足时返回 false - * @param amount 扣除数量 */ spendHC(amount: number): boolean { if (this.hc < amount) return false @@ -57,7 +70,6 @@ export class GameManager { /** * 增加 HC - * @param amount 增加数量 */ addHC(amount: number): void { this.hc += amount @@ -66,7 +78,6 @@ export class GameManager { /** * 减少 KPI,归零时触发 GameOver - * @param amount 减少数量 */ reduceKPI(amount: number): void { this.kpi = Math.max(0, this.kpi - amount) @@ -79,7 +90,6 @@ export class GameManager { /** * 增加 KPI(不超过 100) - * @param amount 增加数量 */ addKPI(amount: number): void { this.kpi = Math.min(100, this.kpi + amount)