Forráskód Böngészése

游戏胜利判断

woso_javan 3 hónapja
szülő
commit
5b0abb3da4

+ 1 - 1
assets/module_take_goblet/Script/Component/OriginCup.ts

@@ -20,7 +20,7 @@ export class OriginCup extends Component {
 
     start() {
         this.node.on(Node.EventType.TOUCH_END, () => {
-            // EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this);
+            EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this);
         });
     }
 

+ 18 - 8
assets/module_take_goblet/Script/LevelAction.ts

@@ -278,7 +278,7 @@ export class LevelAction extends Component {
         }
     }
 
-    // 修改原有方法,在添加新杯子后触发暂存区倒水
+    // 在添加新杯子后触发暂存区倒水
     private async addWaitCupToOutArea() {
         // 原有添加逻辑保持不变
         const waitCups = this.waitArea.cups;
@@ -314,14 +314,22 @@ export class LevelAction extends Component {
         newCups.forEach(cup => cup.setParent(outNodes));
 
         // 执行统一平移
-        this.outArea.getCups().concat(this.waitArea.getCups()).forEach(cup => {
-            tween(cup)
-                .by(0.3, { position: new Vec3(80, 0, 0) }, { easing: 'sineOut' })
-                .start();
-        });
+        if (this.waitArea.getCups().length > 0) {
+            this.outArea.getCups().concat(this.waitArea.getCups()).forEach(cup => {
+                tween(cup)
+                    .by(0.3, { position: new Vec3(80, 0, 0) }, { easing: 'sineOut' })
+                    .start();
+            });
+        }
 
         // 在添加完成后处理暂存区倒水
         await this.handlePourTempCupToOutArea();
+
+        // 胜利条件检测:当两个区域都没有杯子时触发胜利
+        if (this.outArea.getCups().length === 0 && this.waitArea.cups.length === 0) {
+            this.isProcessing = true;
+            console.log('Game Victory!');
+        }
     }
 
     private async pourAnimation(
@@ -372,6 +380,10 @@ export class LevelAction extends Component {
     }
 
     private async spawnNewOriginCup(targetPos: Vec3) {
+        // DOTO 获取颜色配置
+        const colors = this.getAvailableColors(5); // 获取前5个颜色
+        if (colors.length <= 0) return;
+
         // 创建新原浆杯
         const height = TakeGobletGlobalInstance.instance.generateOriginCupHeight();
         const prefab = await TakeGobletGlobalInstance.instance.loadAsyncOriginCup(height);
@@ -390,8 +402,6 @@ export class LevelAction extends Component {
             .to(0.5, { position: targetPos })
             .start();
 
-        // DOTO 获取颜色配置
-        const colors = this.getAvailableColors(5); // 获取前5个颜色
         this.setupOriginCupColors(newCup, colors);
     }