|
@@ -187,20 +187,7 @@ export default {
|
|
|
return {
|
|
|
// 使用类型 1次数 2时间 0未选择
|
|
|
mode: 0,
|
|
|
- mode_list: [
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- name: "会员时间消费",
|
|
|
- time: 30 * 60 * 1000,
|
|
|
- err_title: "本次游玩时间已用完"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- name: "次卡(10分钟)",
|
|
|
- time: 10 * 60 * 1000,
|
|
|
- err_title: "您的会员消费时间已用完",
|
|
|
- }
|
|
|
- ],
|
|
|
+
|
|
|
timeData: {},
|
|
|
mode_item: {},
|
|
|
pop_show: false,
|
|
@@ -253,9 +240,11 @@ export default {
|
|
|
//设置游戏状态为 停止游戏
|
|
|
game_store.setters.setGameStatus(3)
|
|
|
//游戏结束重置游戏时间
|
|
|
- game_store.setters.setPlayTime(0)
|
|
|
+ wx.removeStorageSync('play_time')
|
|
|
//游戏结束重置游戏模式
|
|
|
game_store.setters.setMode(0)
|
|
|
+ //删除游戏得id
|
|
|
+ game_store.setters.removeToyHex()
|
|
|
//游戏结束传送一下数据
|
|
|
$this.post_data()
|
|
|
$this.game_over()
|
|
@@ -328,7 +317,6 @@ export default {
|
|
|
$this.timeData = $datetime
|
|
|
$this.played_time += 1
|
|
|
console.log("玩了:" + $this.played_time + "秒")
|
|
|
- $this.played_time_text = formatSeconds($this.played_time)
|
|
|
//时间倒数
|
|
|
if ($datetime.seconds == '00') {
|
|
|
// 时间满一分钟 则提交一次数据
|
|
@@ -363,12 +351,6 @@ export default {
|
|
|
},
|
|
|
// 结束游戏
|
|
|
game_over() {
|
|
|
- // let $current_time = $this.timeData.minutes * 60 + $this.timeData.seconds
|
|
|
- // let $play_time = $this.play_time - $current_time
|
|
|
- // if ($this.mode == 2) {
|
|
|
- // let $userinfo = wx.getStorageSync('userinfo')
|
|
|
- // $play_time = $userinfo['play_time'] * 60 - $current_time
|
|
|
- // }
|
|
|
let $params = {
|
|
|
game_record_id: game_store.getters.getGameRecordId(),
|
|
|
type: $this.mode,
|
|
@@ -396,7 +378,6 @@ export default {
|
|
|
if ($this.is_end == true) {
|
|
|
$this.game_finished()
|
|
|
} else {
|
|
|
- $this.start_game()
|
|
|
// 筛选 玩具id
|
|
|
$this.toy_hex = game_store.getters.getToyHex()
|
|
|
// bluetooth.sendConnect($this.toy_hex, $this._deviceId, $this._serviceId, $this._characteristicId)
|
|
@@ -404,14 +385,29 @@ export default {
|
|
|
//筛选模式
|
|
|
$this.mode = game_store.getters.getMode()
|
|
|
|
|
|
- //获取用户游玩时间
|
|
|
- let $play_time = $this.play_time = game_store.getters.getPlayTime()
|
|
|
- $this.mode_list.forEach(($val, $index) => {
|
|
|
- $val['time'] = $play_time * 1000
|
|
|
- if ($val['id'] == $this.mode && $val['id'] == 1) {
|
|
|
- $this.mode_item = $val
|
|
|
+
|
|
|
+ let mode_list = [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: "次卡(10分钟)",
|
|
|
+ time: 10 * 60 * 1000,
|
|
|
+ err_title: "您的会员消费时间已用完",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ name: "会员时间消费",
|
|
|
+ time: 30 * 60 * 1000,
|
|
|
+ err_title: "本次游玩时间已用完"
|
|
|
}
|
|
|
- })
|
|
|
+
|
|
|
+ ]
|
|
|
+ //获取用户游玩时间
|
|
|
+ let $played_time = $this.play_time = game_store.getters.getPlayTime() ? game_store.getters.getPlayTime() : 0
|
|
|
+ $this.mode_item = mode_list[$this.mode - 1]
|
|
|
+ let $origin_time = mode_list[$this.mode - 1]['time']
|
|
|
+ $this.mode_item['time'] = $origin_time - ($played_time * 1000)
|
|
|
+ $this.start_game()
|
|
|
+
|
|
|
bluetooth.watch_bluetooth_status($this)
|
|
|
}
|
|
|
|
|
@@ -427,19 +423,21 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
onUnload() {
|
|
|
- // 返回 的时候 暂停
|
|
|
- const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
- countDown.pause();
|
|
|
- //停止传输数据
|
|
|
- bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- wx.offBLECharacteristicValueChange()
|
|
|
- //存储时间
|
|
|
- let $play_time = $this.timeData.minutes * 60 + $this.timeData.seconds
|
|
|
- game_store.setters.setPlayTime($play_time)
|
|
|
- this.pop_show = false
|
|
|
- //设置未结束游戏
|
|
|
- $this.is_end = false
|
|
|
+ if (!$this.is_end) {
|
|
|
+ // 返回 的时候 暂停
|
|
|
+ const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
+ countDown.pause();
|
|
|
+ //停止传输数据
|
|
|
+ bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ //存储时间
|
|
|
+ game_store.setters.setPlayTime($this.played_time)
|
|
|
+ this.pop_show = false
|
|
|
+ //设置未结束游戏
|
|
|
+ $this.is_end = false
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
</script>
|