Procházet zdrojové kódy

开始游戏逻辑优化

chaooo před 1 rokem
rodič
revize
75241b3a49

+ 1 - 12
src/components/connection/brains/connecting.vue

@@ -19,7 +19,7 @@ export default {
   },
   created() {
     $this = this;
-    // 不断获取教具电量
+    // 监听到父级扫码状态
     let connect_interval = setInterval(() => {
       LOG_DEBUG("created监听到父级扫码状态", $this.status);
       if ($this.status*1 === 1) {
@@ -29,17 +29,6 @@ export default {
       }
     }, 500);
   },
-  // watch: {
-  //   'status': {
-  //     handler: function($status) {
-  //       LOG_DEBUG("监听到父级扫码状态",$status);
-  //       if ($status*1 === 1) {
-  //         $this.device_status = 1;
-  //         $this.getBluetoothState();
-  //       }
-  //     }, immediate: true
-  //   }
-  // },
   methods:{
     /**
      * 修改设备连接状态

+ 4 - 4
src/components/connection/index.vue

@@ -42,7 +42,7 @@ export default {
       device_power: 0,
       // 教具电量
       toy_power: 0,
-      toy_sn:"",
+      toy_sn: "",
     }
   },
   created() {
@@ -96,10 +96,10 @@ export default {
     /**
      * 打开教具选择
      */
-    openToyList(){
+    openToyList() {
       this.popup_show = true;
       this.toy_sn = "教具";
-      if ($this.device_status*1 === 2) {
+      if ($this.device_status * 1 === 2) {
         // 关闭脑控
         this.$connection.SendOrder("09", "关闭脑控");
       }
@@ -114,7 +114,7 @@ export default {
       $this.toy_item = ble_store.getters.getToyItem();
       // 初始化教具连接的id
       ble_store.setters.setCurrentToyId("00");
-      if($this.toy_item && $this.toy_item.id > 0) {
+      if ($this.toy_item && $this.toy_item.id > 0) {
         $this.setToyStatus(1);
         $this.$connection.sendToyConnection($this.toy_item);
         // 设置10秒后是否已经连接

+ 24 - 21
src/pages/games/play/index.vue

@@ -291,6 +291,25 @@ export default {
       $this.executed = true
     }
   },
+  mounted() {
+    let game_status = game_store.getters.getGameStatus()*1;
+    if (game_status === 1) {
+      $this.is_end = false;
+      $this.end_loading = false;
+      $this.total_time = game_store.getters.getOverPlayTime();
+      // 筛选模式
+      $this.mode = game_store.getters.getMode() * 1;
+      // 可玩时间 (剩余时长)
+      $this.play_time = game_store.getters.getPlayTime();
+      // 开始游戏
+      $this.startTheGame();
+      // 打开蓝牙监听
+      $this.$connection.watchBLEstatus($this);
+    }
+    if (game_status === 3) {
+      $this.endTheGame();
+    }
+  },
   // 加载完成后、后台切到前台或重新进入页面时触发
   onShow() {
     game_store.setters.setHideStatus(false);
@@ -318,25 +337,6 @@ export default {
       }
     }
   },
-  mounted() {
-    let game_status = game_store.getters.getGameStatus()*1;
-    if (game_status === 1) {
-      $this.is_end = false;
-      $this.end_loading = false;
-      $this.total_time = game_store.getters.getOverPlayTime();
-      // 筛选模式
-      $this.mode = game_store.getters.getMode() * 1;
-      // 可玩时间 (剩余时长)
-      $this.play_time = game_store.getters.getPlayTime();
-      // 开始游戏
-      $this.startTheGame();
-      // 打开蓝牙监听
-      $this.$connection.watchBLEstatus($this);
-    }
-    if (game_status === 3) {
-      $this.endTheGame();
-    }
-  },
   // // 页面从前台切换到后台或者去别的页面时候触发的
   // onHide() {
   //   game_store.setters.setHideStatus(true);
@@ -369,7 +369,7 @@ export default {
       // 四舍五入取整
       game_store.setters.setHideTime(Math.round(new Date() / 1000));
     }
-    clearInterval($timeout);
+    // clearInterval($timeout);
   },
   methods: {
     /**
@@ -491,11 +491,14 @@ export default {
     countdownInterval(){
       clearInterval($timeout)
       $timeout = setInterval(() => {
-        if ($this.play_time > 0) {
+        //判断是否游戏中
+        let game_status = game_store.getters.getGameStatus()*1;
+        if (game_status === 2 && $this.play_time > 0) {
           // 自定义定时器
           $this.play_time -= 1;
           game_store.setters.setPlayedTime($this.total_time-$this.play_time);
           $this.countdown_text = formatPlaySeconds($this.play_time);
+          console.log("%c游戏倒计时", "color:red;", $this.countdown_text);
         } else {
           clearInterval($timeout);
           $this.endTheGame();

+ 1 - 1
src/pages/games/report/index.vue

@@ -24,7 +24,7 @@ export default {
     }
   },
   methods: {
-    webLoading(params) {
+    webLoading() {
       console.log("报告页面web-view加载完成")
       wx.hideLoading();
     }

+ 2 - 1
src/utils/connection.js

@@ -504,7 +504,7 @@ export default {
         //判断游戏是否游戏中
         let $game_status = game_store.getters.getGameStatus();
         if ($game_status === 1 || $game_status === 2) {
-          // $that.endTheGame();
+          $this.endTheGame();
           Notify({
             type: 'danger',
             duration: 0,
@@ -588,6 +588,7 @@ export default {
     let $code = ble_store.getters.getDeviceSn();
     // 关闭脑控
     that.SendOrder("09", "关闭脑控");
+    ble_store.setters.setBluetoothLinkStatus(false);
     game_store.setters.setGameStatus(0);
     // todo 清空链接的设备
     $this.connect_toy = 0;