浏览代码

日常开发

林旭祥 2 周之前
父节点
当前提交
3db4225f6e

+ 1 - 1
src/components/ActionConfirmWindow/index.vue

@@ -404,7 +404,7 @@ defineExpose({
           height: 100%;
           background: rgba(0, 0, 0, 0.5);
           color: #ffffff;
-          font-size: 7rem;
+          font-size: 10rem;
           display: flex;
           align-items: center;
           justify-content: center;

+ 10 - 1
src/views/game/components/basketball.vue

@@ -907,6 +907,14 @@ const initGame = async () => {
 
 };
 
+// 再次游戏
+const getResumeGame = async () => {
+  handleMouseDown();
+  setTimeout(() => {
+    handleMouseUp();
+  }, 100)
+};
+
 onBeforeMount(() => {
 
 });
@@ -941,7 +949,8 @@ onBeforeUnmount(() => {
 
 //暴露给父组件用
 defineExpose({
-  getInit
+  getInit,
+  getResumeGame
 })
 </script>
 

+ 7 - 1
src/views/game/components/football.vue

@@ -1412,6 +1412,11 @@ function calculateAngleAtB(pointA, pointB, pointC) {
   return parseFloat(angleDegrees.toFixed(2));
 }
 
+// 再次游戏
+const getResumeGame = async () => {
+  restartGame();
+};
+
 onBeforeMount(() => {
 
 });
@@ -1443,7 +1448,8 @@ onBeforeUnmount(() => {
 
 //暴露给父组件用
 defineExpose({
-  getInit
+  getInit,
+  getResumeGame
 })
 </script>
 

+ 11 - 1
src/views/game/components/fruit.vue

@@ -1695,6 +1695,15 @@ const getActiveScene = () => {
   return activeScenes.length > 0 ? activeScenes[0].scene.key : null;
 };
 
+// 再次游戏
+const getResumeGame = async () => {
+  const game = gameRef.value;
+  if (!game) return;
+  const currentScene = getActiveScene();
+  const targetScene = game.scene.getScene(currentScene);
+  targetScene.startGame();
+};
+
 onBeforeMount(() => {
 
 });
@@ -1739,7 +1748,8 @@ onBeforeUnmount(() => {
 
 //暴露给父组件用
 defineExpose({
-  getInit
+  getInit,
+  getResumeGame
 })
 </script>
 

+ 55 - 4
src/views/game/index.vue

@@ -75,6 +75,9 @@
     <div class="close" v-if="start" @click="getExitGame"></div>
     <ActionConfirmWindow ref="actionConfirmRef" @confirmExit="getExitGame({ type: 1 })" @confirmStart="getStartGame">
     </ActionConfirmWindow>
+    <div class="time" v-if="timerNum > 0">
+      <div>{{ timerNum }}</div>
+    </div>
   </div>
 </template>
 
@@ -113,8 +116,10 @@ const data = reactive<any>({
   start: false,//是否开始游戏
   areaStateList: [],//各游戏就绪状态
   resumeGame: false,//游戏结束显示继续游戏
+  timer: null,
+  timerNum: null,
 });
-const { projectList, wsState, bodyposeState, deviceInfo, currentGame, currentGameArea, start, areaStateList, resumeGame } = toRefs(data);
+const { projectList, wsState, bodyposeState, deviceInfo, currentGame, currentGameArea, start, areaStateList, resumeGame, timer, timerNum } = toRefs(data);
 
 /**
  * 监听数据变化
@@ -280,6 +285,8 @@ const getExitGame = (data: any) => {
     currentGame.value = "";
     start.value = false;
     resumeGame.value = false;
+    clearInterval(timer.value);
+    timer.value = null;
   } else if (data.type == 2) {
     //游戏结束显示下一场
     let myIndex = areaStateList.value.findIndex((item: any) => {
@@ -295,6 +302,8 @@ const getExitGame = (data: any) => {
       currentGame.value = "";
       start.value = false;
       resumeGame.value = false;
+      clearInterval(timer.value);
+      timer.value = null;
     }).finally(() => {
     });
   }
@@ -307,7 +316,7 @@ const getStartGame = (data: any) => {
   areaStateList.value = data;
   start.value = false;
   resumeGame.value = false;
-  setTimeout(()=>{
+  setTimeout(() => {
     start.value = true;
   })
 };
@@ -316,12 +325,39 @@ const getStartGame = (data: any) => {
  * 继续游戏
  */
 const getResumeGame = () => {
+  areaStateList.value.forEach((item: any, index: number) => {
+    areaStateList.value[index].gameover = false;
+  })
   resumeGame.value = false;
-  // start.value = false;
-  actionConfirmRef.value.getOpen(currentGame.value, currentGameArea.value);
+
+  timerNum.value = 5;
+  speckText(timerNum.value);
+  timer.value = setInterval(() => {
+    timerNum.value--;
+    speckText(timerNum.value);
+    if (timerNum.value == 0) {
+      clearInterval(timer.value);
+      timer.value = null;
+      if (currentGame.value == 'game_basketball') {
+        basketballLeftRef.value.getResumeGame();
+        basketballRightRef.value.getResumeGame();
+      }
+      if (currentGame.value == 'game_football') {
+        footballLeftRef.value.getResumeGame();
+        footballRightRef.value.getResumeGame();
+      }
+      if (currentGame.value == 'game_fruit') {
+        fruitRef.value.getResumeGame();
+      }
+    }
+  }, 1000)
+
+
 };
 
 onBeforeMount(async () => {
+  //初始化语音
+  initSpeech();
   getInit();
 });
 
@@ -545,6 +581,21 @@ $waiPadding: 6.51rem;
   }
 }
 
+.time {
+  position: absolute;
+  left: 0;
+  top: 0;
+  width: 100%;
+  height: 100%;
+  background: rgba(0, 0, 0, 0.5);
+  color: #ffffff;
+  font-size: 7rem;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  z-index: 998;
+}
+
 ::v-deep(.menu) {
   .swiper-horizontal {
     width: 100%;