Commit 480f2513 by Mike Zhu

创建gameover页面

parent 28c14e0c
...@@ -137,6 +137,11 @@ class Main extends egret.DisplayObjectContainer { ...@@ -137,6 +137,11 @@ class Main extends egret.DisplayObjectContainer {
break; break;
case 'game_ready': case 'game_ready':
SceneManager.getInstance().roomScene.update(data) SceneManager.getInstance().roomScene.update(data)
break;
case 'game_end':
SceneManager.getInstance().changeScene('gameoverScene')
SceneManager.getInstance().gameoverScene.update(data)
break;
} }
}) })
platform.onSocketError((e) => { platform.onSocketError((e) => {
......
...@@ -5,9 +5,12 @@ class SceneManager extends egret.DisplayObjectContainer { ...@@ -5,9 +5,12 @@ class SceneManager extends egret.DisplayObjectContainer {
public roomScene: RoomScene; public roomScene: RoomScene;
// 游戏场景 // 游戏场景
public gameScene: GameScene; public gameScene: GameScene;
// 游戏结束场景
public gameoverScene: GameoverScene;
private sceneMap: any = { private sceneMap: any = {
roomScene: RoomScene, roomScene: RoomScene,
gameScene: GameScene gameScene: GameScene,
gameoverScene: GameoverScene
} }
public constructor() { public constructor() {
...@@ -17,8 +20,10 @@ class SceneManager extends egret.DisplayObjectContainer { ...@@ -17,8 +20,10 @@ class SceneManager extends egret.DisplayObjectContainer {
private init() { private init() {
// 实例化两个场景 // 实例化两个场景
this.roomScene = new RoomScene(); this.roomScene = new RoomScene();
this.gameoverScene = new GameoverScene();
// this.gameScene = new GameScene(); // this.gameScene = new GameScene();
// 默认添加开始场景 // 默认添加开始场景
// this.addChild(this.gameoverScene);
this.addChild(this.roomScene); this.addChild(this.roomScene);
} }
// 实例化单例获取方法 // 实例化单例获取方法
......
class GameoverScene extends egret.Sprite {
private startLabel: egret.TextField
private players: Array<any>
private avatars: any
public constructor() {
super();
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('GameoverScene.init')
this.initBg()
this.initEndLabel()
this.initBackLabel()
}
public update(data) {
const payload = data.payload
switch (data.type) {
case 'game_end':
default:
break;
}
}
private initBackLabel() {
var backLabel = new egret.TextField()
backLabel.text = '< 返回'
backLabel.x = 50
backLabel.y = 680
backLabel.bold = true
backLabel.touchEnabled = true
backLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.backHandler, this)
this.addChild(backLabel)
}
private backHandler() {
platform.sendSocketMessage({
data: JSON.stringify({
type: 'entry',
room_id: 'default_room',
payload: {
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}),
success: res => {
console.error("entry success")
},
fail: res => {
console.error("entry fail")
},
complete: res => {
}
})
SceneManager.getInstance().changeScene('roomScene')
}
private initCountDown(res) {
var cdText = new egret.TextField()
cdText.text = '10'
const timer = setInterval(() => {
if (cdText.text == '0') {
clearInterval(timer)
SceneManager.getInstance().changeScene('roomScene')
return
}
cdText.text = `${Number(cdText.text) - 1}`
}, 1000)
}
private initBg() {
var shape: egret.Shape = new egret.Shape();
shape.graphics.beginFill(0x343E5F);
shape.graphics.drawRect(0, 0, 2000, 2000);
shape.graphics.endFill();
this.addChild(shape);
// var bg: egret.Bitmap = new egret.Bitmap()
// bg.texture = RES.getRes("logo_jpg")
// bg.scaleX = bg.scaleY = 2
// bg.x = 1334 / 2 - 280
// bg.y = 100
// this.addChild(bg)
}
private initEndLabel() {
var gameoverText = new egret.TextField()
gameoverText.textColor = 0xF0D66D
gameoverText.strokeColor = 0xffff00
gameoverText.stroke = 5
gameoverText.text = "GAME OVER"
gameoverText.size = 100
gameoverText.width = 700
gameoverText.anchorOffsetX = 350
gameoverText.x = 1334 / 2
gameoverText.textAlign = egret.HorizontalAlign.CENTER;
gameoverText.y = 100
this.addChild(gameoverText);
}
public release() {
// 移除事件
}
}
...@@ -33,9 +33,9 @@ class RoomScene extends egret.Sprite { ...@@ -33,9 +33,9 @@ class RoomScene extends egret.Sprite {
} }
public update(data) { public update(data) {
const payload = data.payload
switch (data.type) { switch (data.type) {
case 'entry': case 'entry':
const payload = data.payload
this.updateStartLabelAndPlayers(payload) this.updateStartLabelAndPlayers(payload)
break; break;
case 'game_ready': case 'game_ready':
...@@ -47,6 +47,7 @@ class RoomScene extends egret.Sprite { ...@@ -47,6 +47,7 @@ class RoomScene extends egret.Sprite {
} }
private updateStartLabelAndPlayers(payload) { private updateStartLabelAndPlayers(payload) {
const {seat, members, nick_name} = payload
if (payload.seat == 0) { if (payload.seat == 0) {
this.startLabel.text = '开始' this.startLabel.text = '开始'
this.startLabel.touchEnabled = true this.startLabel.touchEnabled = true
...@@ -55,7 +56,6 @@ class RoomScene extends egret.Sprite { ...@@ -55,7 +56,6 @@ class RoomScene extends egret.Sprite {
this.startLabel.text = '等待房主点击开始' this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false this.startLabel.touchEnabled = false
} }
const members = payload.members
if(this.avatars && this.avatars.parent){ if(this.avatars && this.avatars.parent){
this.avatars.parent.removeChild(this.avatars) this.avatars.parent.removeChild(this.avatars)
} }
...@@ -66,9 +66,12 @@ class RoomScene extends egret.Sprite { ...@@ -66,9 +66,12 @@ class RoomScene extends egret.Sprite {
} }
private countDown(res) { private countDown(res) {
this.startLabel.bold = true
this.startLabel.text = '3' this.startLabel.text = '3'
this.startLabel.size = 50
const timer = setInterval(() => { const timer = setInterval(() => {
if (this.startLabel.text == '1') { if (this.startLabel.text == '1') {
this.startLabel.size = this.startLabel.size + 20
return this.startLabel.text = 'Go!' return this.startLabel.text = 'Go!'
} }
if (this.startLabel.text == 'Go!') { if (this.startLabel.text == 'Go!') {
...@@ -80,6 +83,7 @@ class RoomScene extends egret.Sprite { ...@@ -80,6 +83,7 @@ class RoomScene extends egret.Sprite {
return return
} }
this.startLabel.text = `${Number(this.startLabel.text) - 1}` this.startLabel.text = `${Number(this.startLabel.text) - 1}`
this.startLabel.size = this.startLabel.size + 10
}, 1000) }, 1000)
} }
......
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