feat(game/GameManager): 新增难度字段、地图索引和波次计数
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user