Commit 1fc27b70 by Mike Zhu

update RoomScene

parent d68283ed
......@@ -13,10 +13,12 @@ declare interface Platform {
connectSocket(options): void
onSocketOpen(callback): void
onSocketClose(callback): void
closeSocket(options): void
onSocketMessage(callback): void
onSocketError(callback): void
sendSocketMessage(callback): void
request(options): void
exitMiniProgram(options): void
}
class DebugPlatform implements Platform {
......@@ -43,6 +45,10 @@ class DebugPlatform implements Platform {
}
closeSocket(options){
}
onSocketMessage(options){
}
......@@ -57,6 +63,9 @@ class DebugPlatform implements Platform {
request(){
}
exitMiniProgram(options){
}
}
......
......@@ -22,7 +22,15 @@ class Store {
}
break;
case 'setUserInfo':
_state.userInfo = message.data
_state = {
..._state,
userInfo: payload
}
case 'updateCid':
_state = {
..._state,
cid: payload.cid
}
default:
break;
}
......
......@@ -20,10 +20,13 @@ class RoomScene extends egret.Sprite {
public update(data) {
const payload = data.payload
if(payload.seat == 0) {
if (payload.seat == 0) {
this.startLabel.text = '开始'
this.startLabel.touchEnabled = true
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
} else {
this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false
}
}
......@@ -44,8 +47,8 @@ class RoomScene extends egret.Sprite {
this.startLabel = new egret.TextField()
this.startLabel.textColor = 0xF0D66D
this.startLabel.text = "请稍等..."
this.startLabel.width = 200
this.startLabel.anchorOffsetX = 100
this.startLabel.width = 300
this.startLabel.anchorOffsetX = 150
this.startLabel.x = 1334 / 2
this.startLabel.textAlign = egret.HorizontalAlign.CENTER;
this.startLabel.y = 1136 / 2
......@@ -53,10 +56,38 @@ class RoomScene extends egret.Sprite {
private startHandler() {
console.log('starthandler')
SceneManager.getInstance().changeScene('gameScene');
platform.sendSocketMessage({
data: JSON.stringify({
type: 'start',
rid: 'default_room',
cid: Store.getState().cid,
payload: {
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}),
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 => {
this.startLabel.text = '启动失败'
}
})
}
public release() {
// 移除事件
this.startLabel.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
}
}
\ No newline at end of file
......@@ -46,6 +46,10 @@ class WxgamePlatform {
wx.onSocketClose(callback)
}
closeSocket(options){
wx.closeSocket(options)
}
onSocketMessage(callback){
wx.onSocketMessage(callback)
}
......@@ -57,9 +61,14 @@ class WxgamePlatform {
sendSocketMessage(options){
wx.sendSocketMessage(options)
}
request(options){
wx.request(options)
}
exitMiniProgram(options){
wx.exitMiniProgram(options)
}
}
......
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