|
@@ -217,44 +217,48 @@ export default {
|
|
|
methods: {
|
|
|
//游戏结束方法
|
|
|
game_finished() {
|
|
|
+ try {
|
|
|
+ bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ //停止控制游戏
|
|
|
+ const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
+ countDown.pause();
|
|
|
+ //取消监听低功耗蓝牙设备
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ Toast.success('已成功断开')
|
|
|
+ //设置游戏状态为 停止游戏
|
|
|
+ game_store.setters.setGameStatus(3)
|
|
|
+ //游戏结束重置游戏时间
|
|
|
+ wx.removeStorageSync('play_time')
|
|
|
+ //游戏结束重置游戏模式
|
|
|
+ game_store.setters.setMode(0)
|
|
|
+ //删除游戏得id
|
|
|
+ game_store.setters.removeToyHex()
|
|
|
+ //关闭游戏常亮
|
|
|
+ wx.setKeepScreenOn({
|
|
|
+ keepScreenOn: false
|
|
|
+ })
|
|
|
+ //游戏结束传送一下数据
|
|
|
+ $this.post_data()
|
|
|
|
|
|
- //停止传输数据
|
|
|
- // bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- // bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- //停止控制游戏
|
|
|
- bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
- countDown.pause();
|
|
|
- //取消监听低功耗蓝牙设备
|
|
|
- wx.offBLECharacteristicValueChange()
|
|
|
- Toast.success('已成功断开')
|
|
|
- //设置游戏状态为 停止游戏
|
|
|
- game_store.setters.setGameStatus(3)
|
|
|
- //游戏结束重置游戏时间
|
|
|
- wx.removeStorageSync('play_time')
|
|
|
- //游戏结束重置游戏模式
|
|
|
- game_store.setters.setMode(0)
|
|
|
- //删除游戏得id
|
|
|
- game_store.setters.removeToyHex()
|
|
|
- //关闭游戏常亮
|
|
|
- wx.setKeepScreenOn({
|
|
|
- keepScreenOn: false
|
|
|
- })
|
|
|
- //游戏结束传送一下数据
|
|
|
- $this.post_data()
|
|
|
- $this.game_over()
|
|
|
- Toast.loading({
|
|
|
- forbidClick: true,
|
|
|
- message: "正在生成报告...",
|
|
|
- duration: 0
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- Toast.clear()
|
|
|
- $this.to_report()
|
|
|
- }, 800)
|
|
|
+ Toast.loading({
|
|
|
+ forbidClick: true,
|
|
|
+ message: "正在生成报告...",
|
|
|
+ duration: 0
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ Toast.clear()
|
|
|
+ $this.game_over()
|
|
|
+ $this.to_report()
|
|
|
+ }, 800)
|
|
|
+ } catch (e) {
|
|
|
+ console.log('error', e)
|
|
|
+ }
|
|
|
},
|
|
|
// 时间到
|
|
|
time_out() {
|
|
|
+ console.log('游戏结束')
|
|
|
+ $this.played_time = $this.play_time
|
|
|
+ //游戏结束
|
|
|
$this.game_finished()
|
|
|
},
|
|
|
to_report() {
|
|
@@ -268,7 +272,6 @@ export default {
|
|
|
keepScreenOn: true
|
|
|
})
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
- console.log('监听蓝牙时间获取数据')
|
|
|
// console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
let hexStr = $this.ab2hex(characteristic.value)
|
|
|
let $data = bluetooth.get_big_data(hexStr)
|
|
@@ -277,7 +280,7 @@ export default {
|
|
|
if (hexStr.substr(0, 6) == '555520') {
|
|
|
//当s1为 00时 数据有效
|
|
|
let $s1 = hexStr.substr(8, 2)
|
|
|
- console.log("游戏中监听脑环是否带正:", $s1 == '00')
|
|
|
+ // console.log("游戏中监听脑环是否带正:", $s1 == '00')
|
|
|
$this.device_ok = ($s1 == '00')
|
|
|
}
|
|
|
|
|
@@ -328,12 +331,13 @@ export default {
|
|
|
// 监听时间发生变动
|
|
|
watch_time(e) {
|
|
|
let $datetime = e.mp.detail
|
|
|
- if ($datetime.seconds.length == 1) {
|
|
|
- $datetime.seconds = '0' + $datetime.seconds
|
|
|
+ for (let $key in $datetime) {
|
|
|
+ if ($datetime[$key].toString().length == 1) {
|
|
|
+ $datetime[$key] = "0" + $datetime[$key]
|
|
|
+ }
|
|
|
}
|
|
|
$this.timeData = $datetime
|
|
|
$this.played_time += 1
|
|
|
- console.log("玩了:" + $this.played_time + "秒")
|
|
|
//时间倒数
|
|
|
if ($datetime.seconds == '00') {
|
|
|
// 时间满一分钟 则提交一次数据
|
|
@@ -453,6 +457,7 @@ export default {
|
|
|
$this.mode_item = mode_list[$this.mode - 1]
|
|
|
let $origin_time = $play_time * 1000
|
|
|
$this.mode_item['time'] = $origin_time - ($played_time * 1000)
|
|
|
+
|
|
|
$this.start_game()
|
|
|
|
|
|
//打开蓝牙监听
|
|
@@ -464,6 +469,9 @@ export default {
|
|
|
$this = this;
|
|
|
},
|
|
|
onShow() {
|
|
|
+ if ($this.timeData.minutes == '00' && $this.timeData.seconds == '00'){
|
|
|
+ $this.game_finished()
|
|
|
+ }
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
if (options.end == 1) {
|