瀏覽代碼

日常开发

林旭祥 2 周之前
父節點
當前提交
92a67380fc
共有 3 個文件被更改,包括 24 次插入25 次删除
  1. 18 18
      src/views/game/components/basketball.vue
  2. 0 2
      src/views/game/components/football.vue
  3. 6 5
      src/views/game/components/fruit.vue

+ 18 - 18
src/views/game/components/basketball.vue

@@ -840,25 +840,25 @@ const draw = () => {
     drawText(ctx, 'Game Over', clientObj.value.width / 2, 200, 80);
     drawText(ctx, '成绩:' + gameState.score, clientObj.value.width / 2, 400, 50);
     ctx.textAlign = 'center';
-
+    emit('confirmExit', { type: 2, area: props.currentGameArea });
     // 游戏结束后2秒自动退出
-    if (!gameState.exitTimer) {
-      gameState.exitTimer = setTimeout(() => {
-        // 退出游戏,这里可以根据实际需求调整,比如返回主菜单或跳转到其他页面
-        gameState.gameOver = false;
-        gameState.started = false;
-        gameState.score = 0;
-        gameState.time = 60;
-        gameState.balls = [];
-        //gameState.state = 'menu';
-        gameState.click = false;
-        gameState.exitTimer = null;
-
-        // 如果需要跳转到其他页面,可以使用路由
-        // router.push('/');
-        emit('confirmExit', { type: 2, area: props.currentGameArea });
-      }, 500);
-    }
+    // if (!gameState.exitTimer) {
+    //   gameState.exitTimer = setTimeout(() => {
+    //     // 退出游戏,这里可以根据实际需求调整,比如返回主菜单或跳转到其他页面
+    //     gameState.gameOver = false;
+    //     gameState.started = false;
+    //     gameState.score = 0;
+    //     gameState.time = 60;
+    //     gameState.balls = [];
+    //     //gameState.state = 'menu';
+    //     gameState.click = false;
+    //     gameState.exitTimer = null;
+
+    //     // 如果需要跳转到其他页面,可以使用路由
+    //     // router.push('/');
+    //     emit('confirmExit', { type: 2, area: props.currentGameArea });
+    //   }, 500);
+    // }
 
     // 保留点击退出的功能
     if (gameState.click) {

+ 0 - 2
src/views/game/components/football.vue

@@ -148,12 +148,10 @@ const initGame = () => {
 
   game.value.events.on('gameOver', () => {
     currentScene.value = 'gameover';
-    setTimeout(() => {
       if (currentScene.value == 'gameover') {
         // restartGame();
         emit('confirmExit', { type: 2, area: props.currentGameArea });
       }
-    }, 500)
   });
   setTimeout(() => {
     if (currentScene.value === 'start') {

+ 6 - 5
src/views/game/components/fruit.vue

@@ -1612,11 +1612,12 @@ class PlayScene extends Phaser.Scene {
       ease: 'Elastic.Out', // 更明显的弹性动画,增强视觉效果
       onComplete: () => {
         // 动画完成后再设置自动返回,确保用户有足够时间看到画面
-        setTimeout(() => {
-          console.log('游戏结束,返回首页');
-          // this.scene.start('main');
-          emit('confirmExit', { type: 2, area: props.currentGameArea });
-        }, 500);
+        // setTimeout(() => {
+        //   console.log('游戏结束,返回首页');
+        //   // this.scene.start('main');
+        //   emit('confirmExit', { type: 2, area: props.currentGameArea });
+        // }, 500);
+        emit('confirmExit', { type: 2, area: props.currentGameArea });
       }
     });