Commit 461a7523 by Mike Zhu

更新所有玩家倒计时

parent 9ff81dfe
...@@ -109,20 +109,23 @@ class Main extends egret.DisplayObjectContainer { ...@@ -109,20 +109,23 @@ class Main extends egret.DisplayObjectContainer {
}) })
this.createGameScene(); this.createGameScene();
platform.onSocketMessage(function(res) { platform.onSocketMessage(function (res) {
console.log('收到服务器内容:' + res.data) console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(res.data) const state = Store.onMessage(res.data)
let data = res.data let data = res.data
if (typeof res.data === 'string') { if (typeof res.data === 'string') {
data = JSON.parse(res.data) data = JSON.parse(res.data)
} switch (data.type) {
case 'entry':
if(data.type === 'entry') {
Store.onMessage({ Store.onMessage({
type: 'updateCid', type: 'updateCid',
payload: data payload: data
}) })
SceneManager.getInstance().roomScene.update(data) SceneManager.getInstance().roomScene.update(data)
break;
case 'game_ready':
SceneManager.getInstance().roomScene.update(data)
}
} }
}) })
platform.onSocketError((e) => { platform.onSocketError((e) => {
......
...@@ -26,11 +26,13 @@ class Store { ...@@ -26,11 +26,13 @@ class Store {
..._state, ..._state,
userInfo: payload userInfo: payload
} }
break;
case 'updateCid': case 'updateCid':
_state = { _state = {
..._state, ..._state,
cid: payload.cid cid: payload.cid
} }
break;
default: default:
break; break;
} }
......
...@@ -19,6 +19,8 @@ class RoomScene extends egret.Sprite { ...@@ -19,6 +19,8 @@ class RoomScene extends egret.Sprite {
} }
public update(data) { public update(data) {
switch (data.type) {
case 'entry':
const payload = data.payload const payload = data.payload
if (payload.seat == 0) { if (payload.seat == 0) {
this.startLabel.text = '开始' this.startLabel.text = '开始'
...@@ -28,6 +30,28 @@ class RoomScene extends egret.Sprite { ...@@ -28,6 +30,28 @@ class RoomScene extends egret.Sprite {
this.startLabel.text = '等待房主点击开始' this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false this.startLabel.touchEnabled = false
} }
break;
case 'game_ready':
this.countDown(payload)
default:
break;
}
}
private countDown(res) {
this.startLabel.text = '3'
const timer = setInterval(() => {
if (this.startLabel.text == '1') {
return this.startLabel.text = 'Go!'
}
if (this.startLabel.text == 'Go!') {
clearInterval(timer)
SceneManager.getInstance().changeScene('gameScene')
return
}
this.startLabel.text = `${Number(this.startLabel.text) - 1}`
}, 1000)
} }
private initBg() { private initBg() {
...@@ -67,21 +91,10 @@ class RoomScene extends egret.Sprite { ...@@ -67,21 +91,10 @@ class RoomScene extends egret.Sprite {
} }
}), }),
success: res => { success: res => {
this.startLabel.text = '3'
const timer = setInterval(() => {
if(this.startLabel.text == '1') {
return this.startLabel.text = 'Go!'
}
if(this.startLabel.text == 'Go!') {
clearInterval(timer)
SceneManager.getInstance().changeScene('gameScene')
return
}
this.startLabel.text = `${Number(this.startLabel.text) - 1}`
}, 1000)
}, },
fail: res => { fail: res => {
this.startLabel.text = '启动失败' this.startLabel.text = '启动失败'
console.error('start error: ', res)
} }
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment