|
|
@@ -291,6 +291,9 @@ export class InGameManager extends Component {
|
|
|
console.log('[InGameManager] 技能选择UI已关闭');
|
|
|
}
|
|
|
|
|
|
+ // 恢复游戏
|
|
|
+ this.resumeGame();
|
|
|
+
|
|
|
// 如果有等待的diban动画,现在播放diban动画
|
|
|
if (this.pendingBlockSelection) {
|
|
|
console.log('[InGameManager] 技能选择完成,现在播放diban动画');
|
|
|
@@ -352,6 +355,11 @@ export class InGameManager extends Component {
|
|
|
private onGameSuccessEvent() {
|
|
|
console.log('[InGameManager] 接收到游戏成功事件');
|
|
|
this.currentState = GameState.SUCCESS;
|
|
|
+
|
|
|
+ // 游戏结束时进入暂停状态,停止所有游戏对象的行为
|
|
|
+ console.log('[InGameManager] 游戏成功,触发游戏暂停');
|
|
|
+ const eventBus = EventBus.getInstance();
|
|
|
+ eventBus.emit(GameEvents.GAME_PAUSE);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -360,6 +368,11 @@ export class InGameManager extends Component {
|
|
|
private onGameDefeatEvent() {
|
|
|
console.log('[InGameManager] 接收到游戏失败事件');
|
|
|
this.currentState = GameState.DEFEAT;
|
|
|
+
|
|
|
+ // 游戏结束时进入暂停状态,停止所有游戏对象的行为
|
|
|
+ console.log('[InGameManager] 游戏失败,触发游戏暂停');
|
|
|
+ const eventBus = EventBus.getInstance();
|
|
|
+ eventBus.emit(GameEvents.GAME_PAUSE);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -401,35 +414,29 @@ export class InGameManager extends Component {
|
|
|
// 检查能量是否已满,如果满了需要触发技能选择
|
|
|
const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
|
|
|
|
|
|
- // 通过事件系统检查是否有活跃敌人
|
|
|
- let hasActiveEnemies = false;
|
|
|
- EventBus.getInstance().emit(GameEvents.ENEMY_CHECK_ACTIVE, (active: boolean) => {
|
|
|
- hasActiveEnemies = active;
|
|
|
-
|
|
|
- // 在回调中检查波次是否结束
|
|
|
- const isWaveEnd = remaining <= 0 && !hasActiveEnemies;
|
|
|
+ // 基于UI显示的敌人数量判断波次是否结束(Canvas-001/TopArea/EnemyNode/EnemyNumber为0)
|
|
|
+ const isWaveEnd = remaining <= 0;
|
|
|
+
|
|
|
+ if (isWaveEnd) {
|
|
|
+ console.log(`[InGameManager] 波次结束检测: remaining=${remaining}`);
|
|
|
|
|
|
- if (isWaveEnd) {
|
|
|
- console.log(`[InGameManager] 波次结束检测: remaining=${remaining}, hasActiveEnemies=${hasActiveEnemies}`);
|
|
|
-
|
|
|
- // 如果能量已满,设置等待方块选择状态
|
|
|
- if (energyWillBeFull) {
|
|
|
- this.pendingBlockSelection = true;
|
|
|
- this.preparingNextWave = true;
|
|
|
- this.currentState = GameState.BLOCK_SELECTION;
|
|
|
+ // 如果能量已满,设置等待方块选择状态
|
|
|
+ if (energyWillBeFull) {
|
|
|
+ this.pendingBlockSelection = true;
|
|
|
+ this.preparingNextWave = true;
|
|
|
+ this.currentState = GameState.BLOCK_SELECTION;
|
|
|
+ } else {
|
|
|
+ if (this.currentWave < (this.levelWaves?.length || 1)) {
|
|
|
+ this.showNextWavePrompt();
|
|
|
} else {
|
|
|
- if (this.currentWave < (this.levelWaves?.length || 1)) {
|
|
|
- this.showNextWavePrompt();
|
|
|
- } else {
|
|
|
- this.triggerGameSuccess();
|
|
|
- }
|
|
|
+ this.triggerGameSuccess();
|
|
|
}
|
|
|
- } else if (energyWillBeFull) {
|
|
|
- // 如果波次未结束但能量已满,也需要触发技能选择
|
|
|
- console.log('[InGameManager] 能量已满但波次未结束,触发技能选择');
|
|
|
- this.currentState = GameState.BLOCK_SELECTION;
|
|
|
}
|
|
|
- });
|
|
|
+ } else if (energyWillBeFull) {
|
|
|
+ // 如果波次未结束但能量已满,也需要触发技能选择
|
|
|
+ console.log('[InGameManager] 能量已满但波次未结束,触发技能选择');
|
|
|
+ this.currentState = GameState.BLOCK_SELECTION;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -492,39 +499,17 @@ export class InGameManager extends Component {
|
|
|
* 检查所有敌人是否被击败
|
|
|
*/
|
|
|
private checkAllEnemiesDefeated(): boolean {
|
|
|
- // 通过事件系统检查游戏是否开始
|
|
|
- let gameStarted = false;
|
|
|
- EventBus.getInstance().emit(GameEvents.ENEMY_CHECK_GAME_STARTED, (started: boolean) => {
|
|
|
- gameStarted = started;
|
|
|
- });
|
|
|
-
|
|
|
+ // 如果敌人生成还未开始,不进行胜利检查
|
|
|
if (!this.enemySpawningStarted) {
|
|
|
- if (gameStarted) {
|
|
|
- this.enemySpawningStarted = true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- // 通过事件系统获取当前敌人数量
|
|
|
- let currentEnemyCount = 0;
|
|
|
- EventBus.getInstance().emit(GameEvents.ENEMY_GET_COUNT, (count: number) => {
|
|
|
- currentEnemyCount = count;
|
|
|
- });
|
|
|
-
|
|
|
- if (this.levelTotalEnemies > 0) {
|
|
|
- return this.enemiesKilled >= this.levelTotalEnemies && currentEnemyCount === 0;
|
|
|
- }
|
|
|
-
|
|
|
- if (currentEnemyCount > this.totalEnemiesSpawned) {
|
|
|
- this.totalEnemiesSpawned = currentEnemyCount;
|
|
|
- }
|
|
|
-
|
|
|
- const shouldCheckVictory = this.enemySpawningStarted &&
|
|
|
- currentEnemyCount === 0 &&
|
|
|
- this.totalEnemiesSpawned > 0;
|
|
|
-
|
|
|
- return shouldCheckVictory;
|
|
|
+ // 基于当前波次的敌人击杀数量判断是否胜利
|
|
|
+ // 如果当前波次的剩余敌人数量为0,且是最后一波,则胜利
|
|
|
+ const currentWaveRemaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
|
|
|
+ const isLastWave = this.currentWave >= (this.levelWaves?.length || 1);
|
|
|
+
|
|
|
+ return currentWaveRemaining <= 0 && isLastWave;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -647,6 +632,14 @@ export class InGameManager extends Component {
|
|
|
EventBus.getInstance().emit(GameEvents.GAME_PAUSE);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 恢复游戏
|
|
|
+ */
|
|
|
+ private resumeGame() {
|
|
|
+ console.log('[InGameManager] 恢复游戏');
|
|
|
+ EventBus.getInstance().emit(GameEvents.GAME_RESUME);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查游戏是否结束
|
|
|
*/
|
|
|
@@ -958,6 +951,13 @@ export class InGameManager extends Component {
|
|
|
eventBus.emit(GameEvents.RESET_WALL_HEALTH); // 重置墙体血量
|
|
|
eventBus.emit(GameEvents.RESET_UI_STATES); // 重置UI状态
|
|
|
|
|
|
+ // 8. 发送游戏结束事件,确保游戏状态正确转换
|
|
|
+ console.log('[InGameManager] 发送游戏结束事件');
|
|
|
+ eventBus.emit('GAME_END');
|
|
|
+
|
|
|
+ // 9. 重置游戏状态为初始状态
|
|
|
+ this.currentState = GameState.PLAYING;
|
|
|
+
|
|
|
console.log('[InGameManager] 游戏数据清理完成,可以安全返回主页面');
|
|
|
}
|
|
|
|