验证中...
Languages: TypeScript
Categories: 算法分析
Latest update 2018-12-09 10:01
无脑更新
Raw Copy
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
/**
*
* @author jack
* 2017-06-28
*/
class NiuNiuGameScene extends eui.Component {
private imgBackground: eui.Image;
private xialaButton: eui.Button;
private xialaopenGroup: eui.Group;
private fanhuiLabel: eui.Label;
private gamecodeLabel: eui.Label;
private typeLabel: eui.Label;
private roundLabel: eui.Label;
private qiangzhuangBtn: eui.Button;
private buqiangzhuangBtn: eui.Button;
private bet1: eui.Image;
private bet2: eui.Image;
private bet3: eui.Image;
private bet4: eui.Image;
private betGroup: eui.Group;
private gpXuanNiu: eui.Group;
private btnYouNiu: eui.Button;
private btnMeiNiu: eui.Button;
private wenziButton:eui.Button;
private btnMeiNiu0: eui.Button;
private compChat:Chat;
//初始化信息
private usernumber: number = 0;
private chairAll: number = 5;
private userReady: eui.Button;
private avatar: string;
private username: string;
private jifen: string;
private dettype: number = 0;
//开牛的组件
private compKaiNiu: KaiNiu;
private gameResultLayer:NiuGameResult;
//上下问是否加载完成
private loadcontextok: boolean = false;
// 消息队列
private msgqueue: Array<any>;
private locked: boolean = false;
private myChairId: number = 0;
//头像列表
private avatars: {};
//昵称列表
private nicknames: {};
//玩家手牌
private handcards: {};
//积分的列表
private scores: {};
//玩家数据group
private playersgroup: {};
//所有玩家的准备图片
private readys: {}
//准备
private ready: boolean = false;
//当前是多少局
private round: number = 0;
//当前房间的房间号
private roomkey: string = "";
//当前房间的状态
private state: string = 'none';
//游戏的小状态
private playstate: string = '';
//房间配置
private roomconfig = {};
//所有玩家的数据
private playersdata = {};
//倒计时
private elapsed: number = -1;
//翻译的码表
private tans_key = {};
//庄的vcid
private zhuang_cid: number = 0;
//定时器对象
private timer: egret.Timer = null;
private clock: NiuClock;
private CARD_SCALE = 0.8
public constructor() {
super();
this.once(egret.Event.REMOVED_FROM_STAGE, this.destroy, this);
this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
this.skinName = "resource/game_skins/NiuNiuGameSkin.exml";
this.tans_key = {
jingdian: "经典模式",
fengkuang: "疯狂模式",
qiang: "抢庄",
lun: '轮庄',
gu: '固定庄',
}
}
/////////////////////////////////////////////////////////////////////////////////////
// 事件
//下拉
private onBtnxialaHandler(event: egret.TouchEvent): void {
if (this.xialaopenGroup.visible) {
this.xialaopenGroup.visible = false;
} else {
this.xialaopenGroup.visible = true;
}
}
//准备按钮处理
private onBtnreadyHandler(event: egret.TouchEvent): void {
myapp.tcp.send("room", "ready", {})
}
protected childrenCreated(): void {
this.init();
}
private clearScene() {
this.clearPlayers();
}
private updateHandCards(playerinfo) {
var self = this;
var vcid = Utils.getViewChairId(this.myChairId, playerinfo.chairId, 5);
for (var i = 1; i <= 5; i++) {
var k = '' + vcid + "-" + i
var v = self.handcards[k];
if (v != null) {
self.removeChild(v);
delete self.handcards[k];
}
}
for (var i = 0; i < playerinfo.handcards.length; i++) {
var c = playerinfo.handcards[i];
var card = new Card(c);
card.scaleX = self.CARD_SCALE;
card.scaleY = self.CARD_SCALE;
var pos = NiuNiuCardLayout.getpos(vcid, (i + 1));
card.x = pos['x'];
card.y = pos['y'];
self.addChild(card);
self.handcards["" + vcid + "-" + (i + 1)] = card;
}
}
private clearPlayers() {
for (var i = 1; i <= 5; i++) {
this.removeplayer(i);
}
}
// UI辅助函数
// 更新一个玩家的数据
private updatePlayer(playerinfo, updatehandcards = true) {
var self = this;
var vcid = Utils.getViewChairId(this.myChairId, playerinfo.chairId, 5);
if (self.playersdata == undefined) {
self.playersdata = {};
}
self.playersdata[vcid] = playerinfo;
var tmp = this.playersgroup[vcid];
var gp: eui.Group = this.playersgroup[vcid];
var tmp = this.avatars[vcid];
var avatar: eui.Image = <eui.Image>tmp;
var tmp = this.nicknames[vcid];
var nickname: eui.Label = <eui.Label>tmp;
var tmp = this.scores[vcid];
var score: eui.Label = <eui.Label>tmp;
gp.visible = true;
avatar.source = playerinfo.avatar;
nickname.text = playerinfo.name;
if (vcid == 1) {
this.ready = playerinfo['state'] == "ready";
}
var tmp = this.readys[vcid];
var img = <eui.Image>tmp;
if (playerinfo['state'] == 'ready') {
img.visible = true;
} else {
img.visible = false;
}
score.text = playerinfo.score;
self.playstate = playerinfo.playstate;
if (updatehandcards) {
self.updateHandCards(playerinfo);
}
self.updateMyReady();
//更新定时器
if (playerinfo['timer']) {
var timestamp = (new Date()).valueOf();
timestamp = Math.floor(timestamp / 1000);
self.elapsed = timestamp + playerinfo.timer;
} else {
self.elapsed = -1;
}
//1.更新下注按钮的状态
if (playerinfo.chairId == self.myChairId) {
self.updateBetBtn(playerinfo['actions']);
//2.跟新玩家的标识状态
self.updateKaiPaiBtn(playerinfo['actions'])
//3.更新完成状态
self.updateWanCheng(playerinfo['actions'])
}
}
private updateWanCheng(actions) {
var self = this;
var imgWanCheng: eui.Image = self['imgWanCheng'];
if (actions != null) {
if (actions['wancheng']) {
imgWanCheng.visible = true;
} else {
imgWanCheng.visible = false;
}
} else {
imgWanCheng.visible = false;
}
}
//我的所有的手牌都下落
private makeMyHandcardDown() {
var self = this;
for (var i = 1; i <= 5; i++) {
var k = "1" + "-" + i
var c: Card = self.handcards[k]
if (c != null) {
c.carddown();
}
}
}
private getMyHandCardsObj() {
var self = this;
var a = [];
for (var i = 1; i <= 5; i++) {
var k = "1" + "-" + i
var c: Card = self.handcards[k]
if (c != null) {
a.push(c)
}
}
return a;
}
private getSelectMyHandCards() {
var self = this;
var a = [];
for (var i = 1; i <= 5; i++) {
var k = "1" + "-" + i
var c: Card = self.handcards[k]
if (c != null && c._is_selected) {
a.push(c.cardnumber);
}
}
return a;
}
private makeMyHandcardUp(cards: number[]) {
var self = this;
var a = self.getMyHandCardsObj();
for (var i = 0; i < cards.length; i++) {
var cardvalue = cards[i];
for (var j = 0; j < a.length; j++) {
var card: Card = a[j];
if (!card._is_selected && card.cardnumber == cardvalue) {
card.cardup();
break;
}
}
}
}
private updateKaiPaiBtn(actions) {
var self = this;
if (actions != null) {
if (actions['kaipai'] && actions['kaipai'].length > 0) {
var kaipai = actions['kaipai'];
var kaipai1 = kaipai[0];
self.gpXuanNiu.visible = true;
self.makeMyHandcardDown();
//没有牛的提示
if (kaipai1['youniu']) {
self.btnMeiNiu0.visible = true;
self.btnMeiNiu.visible = false;
} else {
self.btnMeiNiu0.visible = false;
self.btnMeiNiu.visible = true;
}
//给牌选择上去
if (kaipai1['youniu']) {
self.makeMyHandcardUp(kaipai1['niucard'])
var total = 0;
for (var i = 0; i < kaipai1['niucard'].length; i++) {
var cardvalue = kaipai1['niucard'][i];
total = total + Logic.getniupoint(cardvalue);
self['lblSelectCard' + (i + 1)].text = Logic.getniupoint(cardvalue);
}
self['lblSelectCard4'].text = "" + total;
} else {
self.clearSelectCards();
}
} else {
self.gpXuanNiu.visible = false;
}
} else {
//更新下注按钮
self.gpXuanNiu.visible = false;
}
}
private updateBetBtn(actions) {
var self = this;
if (actions != null) {
if (actions['bet'] && actions['bet'].length > 0) {
var bets = actions['bet'];
//显示下注弹窗
self.betGroup.visible = true;
for (var i = 0; i < bets.length; i++) {
var b = bets[i];
self['lblbet' + (i + 1)].text = b + "b";
}
} else {
self.betGroup.visible = false;
}
} else {
//更新下注按钮
self.betGroup.visible = false;
}
}
private removeplayer(vcid) {
var gp: eui.Group = this.playersgroup[vcid];
gp.visible = false;
}
private updateRoomInfo() {
console.log("当前房间的配置信息", this.roomconfig)
this.gamecodeLabel.text = this.roomkey;
var moshi = this.tans_key[this.roomconfig['moshi']];
var zhuang = this.tans_key[this.roomconfig['zuozhuang']];
var roomTypeName = `${moshi} - ${zhuang}`;
this.typeLabel.text = roomTypeName;
var roundNum = `${this.round}/${this.roomconfig['round']}`;
this.roundLabel.text = roundNum;
}
//更新桌面的定时器
private updateClock(cmd) {
}
//更新庄
private updateZhuang() {
var self = this;
for (var i = 1; i <= 5; i++) {
var vcid = Utils.getViewChairId(this.myChairId, i, 5);
var k = "zhuang" + vcid;
var img: eui.Image = self[k];
img.visible = false;
}
if (self.zhuang_cid >0) {
var vcid = Utils.getViewChairId(this.myChairId, self.zhuang_cid, 5);
var k = "zhuang" + vcid;
var img: eui.Image = self[k];
img.visible = true;
}
}
// 更新我自己的ready
private updateMyReady() {
var self = this;
if (self.round==0 && !this.ready && this.state == 'none') {
this.userReady.visible = true;
} else {
this.userReady.visible = false;
}
}
//是否3张牌都选择了完了
private isSelectCardFull(): boolean {
var self = this;
for (var i = 1; i <= 3; i++) {
var s = self['lblSelectCard' + i].text;
if (s == '') {
return false
}
}
return true
}
//清空所有选择的牌的数据
private clearSelectCards() {
var self = this;
for (var i = 1; i <= 4; i++) {
self['lblSelectCard' + i].text = "";
}
}
private getEmptySelectCardIndex(): number {
var self = this;
for (var i = 1; i <= 3; i++) {
var s = self['lblSelectCard' + i].text;
if (s == '') {
return i;
}
}
return 0;
}
private clearKaiNiuGroup() {
var self = this;
if (self.compKaiNiu) {
self.removeChild(self.compKaiNiu);
self.compKaiNiu = null;
}
}
private getSelectCardNiuPoint() {
var self = this;
var total = 0;
for (var i = 1; i <= 3; i++) {
var s = self['lblSelectCard' + i].text;
try {
var n = parseInt(s);
total = total + n;
} catch (e) {
}
}
return total;
}
private clearGameResultLayer(){
var self = this;
if(self.gameResultLayer){
self.removeChild(self.gameResultLayer);
self.gameResultLayer=null;
}
}
private showGameTotalResult(){
var index = new NiuNiuRoomScene();
myapp.enterScene(index);
}
// 显示计算特效
private showGameResult(gameresult,players,cardstyles) {
var self = this;
self.gameResultLayer = new NiuGameResult(gameresult,players,cardstyles);
self.addChild(self.gameResultLayer);
}
private showChatText(chairId:number,s:string){
console.log("语言聊天",chairId,s);
}
private showChatExpr(chairId:number,index:number){
console.log("表情聊天",chairId,index);
}
// UI处理代码------------------------------------------------------------------------------------------------------------
//点击扑克牌
private on_ui_cardclick(cmd: any) {
var self = this;
if (self.playstate == 'kaipai') {
if (self.isSelectCardFull()) {
self.makeMyHandcardDown();
self.clearSelectCards();
} else {
if (!cmd.data.selected) {
var last = self.getEmptySelectCardIndex();
var cardvalue = cmd.data.cardvalue;
self.makeMyHandcardUp([cardvalue]);
self['lblSelectCard' + last].text = Logic.getniupoint(cardvalue);
if (self.isSelectCardFull()) {
self['lblSelectCard4'].text = "" + self.getSelectCardNiuPoint();
}
}
}
}
self.locked = false;
}
private on_ui_chatexpr(cmd:any){
var self = this;
self.compChat.visible=false;
myapp.tcp.send("room","chat",{t:'expr',content:cmd.data.index,chairId:self.myChairId});
self.locked=false;
}
private on_ui_chattext(cmd:any){
var self = this;
self.compChat.visible=false;
myapp.tcp.send("room","chat",{t:'text',content:cmd.data.s,chairId:self.myChairId});
self.locked=false;
}
private on_ui_gameresultready(cmd:any){
var self = this;
if(self.gameResultLayer){
self.removeChild(self.gameResultLayer);
self.gameResultLayer=null;
}
myapp.tcp.send("room","ready",{});
self.clearGameResultLayer();
self.clearKaiNiuGroup();
self.locked=false;
}
// tcp处理代码-----------------------------------------------------------------------------------------------------------
private on_tcp_room_quit(cmd: any) {
var self = this;
var vcid = Utils.getViewChairId(this.myChairId, cmd.data.chairId, 5);
delete self.playersdata[vcid];
self.removeplayer(vcid);
self.locked = false;
}
private on_tcp_room_chat(cmd: any) {
var self = this;
//直接播放动画
var t = cmd.data.t;
if (t == 'text') {
self.showChatText(cmd.data.chairId, cmd.data.content);
} else if (t == 'expr') {
self.showChatExpr(cmd.data.chairId, cmd.data.content);
}
self.locked = false;
}
private on_tcp_room_gameover(cmd: any) {
var self = this;
console.log("游戏结束", cmd)
var timestamp = (new Date()).valueOf();
timestamp = Math.floor(timestamp / 1000);
self.elapsed = timestamp + cmd.data.timer;
self.ready = false;
self.state = cmd.data.state
//游戏结束的特效
self.clearKaiNiuGroup();
self.compKaiNiu = new KaiNiu();
self.addChild(self.compKaiNiu);
var cardstyle = cmd.data.cardstyle;
var counter = 0;
for (var i = 0; i <= cardstyle.length; i++) {
var cid = i+1;
var style = cardstyle[i];
if (style) {
counter = counter + 1;
var vcid = Utils.getViewChairId(self.myChairId, cid, 5);
self.compKaiNiu.play(vcid, style, function () {
counter = counter - 1;
if (counter <= 0) {
if(cmd.data.isover){
self.showGameTotalResult();
}else{
self.showGameResult(cmd.data.totalresult, cmd.data.players, cmd.data.cardstyle);
}
}
}, self);
}
}
self.updateMyReady();
self.locked = false;
}
private on_tcp_room_sendcard(cmd: any) {
var self = this;
self.betGroup.visible = false;
var cardvalue = cmd.data.card;
var vcid = Utils.getViewChairId(self.myChairId, cmd.data.chairId, 5);
var card = new Card(cardvalue);
card.scaleX = self.CARD_SCALE;
card.scaleY = self.CARD_SCALE;
self.addChild(card);
var s = "" + vcid + "-" + 5;
self.handcards[s] = card;
card.sendcard1(vcid, 5, 500, 500, 500, function () {
self.locked = false;
}, self);
self.updatePlayer(cmd.data, false);
}
private on_tcp_room_kaipai(cmd: any) {
console.log("开牌", cmd)
var self = this;
var timestamp = (new Date()).valueOf();
timestamp = Math.floor(timestamp / 1000);
self.elapsed = timestamp + cmd.data.timer;
self.locked = false;
self.gpXuanNiu.visible = true;
self.betGroup.visible = false;
}
private on_tcp_room_bet(cmd: any) {
var self = this;
var timestamp = (new Date()).valueOf();
timestamp = Math.floor(timestamp / 1000);
self.elapsed = timestamp + cmd.data.timer;
//显示下注弹窗
if (cmd.data.actions['bet']) {
self.betGroup.visible = true;
var bets = cmd.data.actions['bet']
for (var i = 0; i < bets.length; i++) {
var b = bets[i];
self['lblbet' + (i + 1)].text = b + "b";
}
}
//更显显示的倍数的数据
self.locked = false;
}
private on_tcp_room_qiangzhuang(cmd:any){
var self = this;
myapp.tcp.send("room","qiangzhuang",{qiang:0});
self.locked=false;
}
private on_tcp_room_loadcontext(cmd: any) {
var self = this;
self.clearScene();
self.myChairId = cmd.data.mychairId;
for (var i = 0; i < cmd.data.players.length; i++) {
var info = cmd.data.players[i]
self.updatePlayer(info);
}
if (cmd.data['state']) {
self.state = cmd.data.state;
}
this.roomkey = "" + cmd.data.roomkey;
this.round = cmd.data.round;
//更新房间的配置信息
self.roomconfig = cmd.data.config;
self.updateRoomInfo();
self.updateClock(cmd)
self.locked = false;
}
private on_tcp_room_ready(cmd: any) {
var self = this;
self.clearKaiNiuGroup();
this.updatePlayer(cmd.data);
this.updateMyReady();
self.locked = false;
}
private on_tcp_room_userupdate(cmd: any) {
var self = this;
self.updatePlayer(cmd.data);
self.updateMyReady();
self.locked = false;
}
private on_tcp_room_start(cmd: any) {
var self = this;
self.clearKaiNiuGroup();
self.clearScene();
self.clearGameResultLayer();
self.myChairId = cmd.data.mychairId;
if (cmd.data['state']) {
self.state = cmd.data.state;
}
self.round = cmd.data.round;
self.zhuang_cid = cmd.data.zhuang;
//更新房间的配置信息
//更新庄的信息
self.updateRoomInfo();
self.updateClock(cmd)
self.updateMyReady();
for (var i = 0; i < cmd.data.players.length; i++) {
var info = cmd.data.players[i]
self.updatePlayer(info, false);
} self.updateZhuang();
var foo = function () {
self.locked = false;
}
var counter = 0;
for (var i = 0; i < cmd.data.players.length; i++) {
var info = cmd.data.players[i];
var vcid = Utils.getViewChairId(this.myChairId, info.chairId, 5);
for (var j = 0; j < info.handcards.length; j++) {
counter = counter + 1;
var cardvalue = info.handcards[j];
var card = new Card(cardvalue);
card.scaleX = self.CARD_SCALE;
card.scaleY = self.CARD_SCALE;
self.addChild(card);
var s = "" + vcid + "-" + (j + 1);
self.handcards[s] = card;
card.sendcard(vcid, j + 1, 500, 500, 500, function () {
counter = counter - 1;
if (counter <= 0) {
foo();
}
}, self);
}
}
}
// http处理代码----------------------------------------------------------------------------------------------------------
//有人进入时执行
//初始化
private init() {
var self = this;
self.playersdata = {};
//准备
self.userReady.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnreadyHandler, this);
//不抢庄
G_ScaleButton(self.buqiangzhuangBtn, null);
self.buqiangzhuangBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (event: egret.TouchEvent) {
myapp.tcp.send("room", "qiangzhuang", { qiang: 0 });
}, self);
//抢庄
G_ScaleButton(self.qiangzhuangBtn, null);
self.buqiangzhuangBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (event: egret.TouchEvent) {
myapp.tcp.send("room", "qiangzhuang", { qiang: 1 });
}, self);
//聊天
G_ScaleButton(self.wenziButton, null);
self.wenziButton.addEventListener(egret.TouchEvent.TOUCH_TAP, function (event: egret.TouchEvent) {
self.compChat.visible=true;
}, self);
//下拉
G_ScaleButton(this.userReady, null);
// this.xialaButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnxialaHandler, this);
// this.qiangzhuangBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnqiangHandler, this);
G_ScaleButton(this.btnMeiNiu0, null);
self.btnMeiNiu0.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
console.log("再看看其实有牛的");
}, self);
G_ScaleButton(this.btnMeiNiu, null);
self.btnMeiNiu.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
myapp.tcp.send("room", "kaipai", {})
}, self);
G_ScaleButton(this.btnYouNiu, null);
self.btnYouNiu.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
//获得的我选择的牌
var total = self.getSelectCardNiuPoint();
if (total != 0 && total % 10 != 0) {
//TODO:提示玩家选择的不对
console.log("选择的牌对");
} else {
myapp.tcp.send("room", "kaipai", { cards: self.getSelectMyHandCards() });
}
}, self);
//下注的处理
this.bet1.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
myapp.tcp.send("room", "bet", { index: 1 });
self.betGroup.visible = false;
}, this);
this.bet2.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
myapp.tcp.send("room", "bet", { index: 2 });
self.betGroup.visible = false;
}, this);
this.bet3.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
myapp.tcp.send("room", "bet", { index: 3 });
self.betGroup.visible = false;
}, this);
this.bet4.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
myapp.tcp.send("room", "bet", { index: 4 });
self.betGroup.visible = false;
}, this);
this.avatars = {}
this.nicknames = {}
this.scores = {}
this.playersgroup = {}
this.readys = {};
this.handcards = {};
NiuNiuCardLayout.Init();
//格式化界面的控件
for (var i = 1; i <= 5; i++) {
this.avatars[i] = this['user' + i + 'avaterImg'];
this.nicknames[i] = this['user' + i + 'nameLabel'];
this.scores[i] = this['user' + i + 'moneyLabel'];
this.playersgroup[i] = this['user' + i + 'Group'];
var cardpos: eui.Group = this['gpCardPos' + i];
for (var j = 1; j <= 5; j++) {
NiuNiuCardLayout.add(i, j, cardpos.x + j * 30, cardpos.y);
}
var tmp: eui.Group = this.playersgroup[i];
tmp.addEventListener(egret.TouchEvent.TOUCH_TAP, function (event: egret.TouchEvent) {
var info = self.playersdata[i];
if (info != null) {
}
}, this);
this.readys[i] = this['user' + i + 'zb'];
}
var timer: egret.Timer = new egret.Timer(1000, 0);
self.timer = timer;
timer.start();
timer.addEventListener(egret.TimerEvent.TIMER, this.timerFunc, this);
}
//tcp 绑定
private bindtcp() {
var tcp_binds = ["room.loadcontext", "room.context", "Error", "room.join",
"room.heartbeat", "room.error", "room.createagent",
"room.userupdate", "room.start", "room.outcard",
"room.sendcard", "room.gameover", "room.chat",
"room.dissolve", "room.quit", "room.bet", "room.kaipai","room.qiangzhuang"]
for (var i = 0; i < tcp_binds.length; i++) {
myapp.tcp.bind(tcp_binds[i], this.receive, this)
}
}
//定时器函数
private timerFunc() {
var self = this;
if (self.elapsed > 0) {
self.clock.visible = true;
var timestamp = (new Date()).valueOf();
timestamp = Math.floor(timestamp / 1000);
if (self.elapsed <= timestamp) {
self.elapsed = -1
self.clock.visible = false;
} else {
self.clock.setTime(self.elapsed - timestamp);
}
} else {
self.clock.visible = false;
}
}
//场景被加载到舞台的处理
private onLoad() {
this.msgqueue = new Array<any>();
// this.createPlayers();
this.bindtcp();
Director.main.addEventListener(GameEvents.GAMESCENE, this.mainloop, this);
myapp.tcp.send('room', 'loadcontext', {});
//帧数队列动画回调
this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
}
//场景渲染时的处理
private onEnterFrame(e: egret.Event) {
var self = this;
if (!self.locked && self.msgqueue.length > 0) {
var cmd = self.msgqueue.shift();
self.locked = true;
var fname = "on_" + cmd.t + "_" + cmd.data.name
var f: Function = this[fname]
if (f) {
f.call(this, cmd.data)
} else {
self.locked = false;
}
}
}
//场景销毁处理
private destroy() {
Director.main.removeEventListener(GameEvents.GAMESCENE, this.mainloop, this);
}
//主循环函数
private mainloop(event) {
var self = this;
self.msgqueue.push(event.data);
}
//接收消息处理
public receive(data) {
var self = this;
if (self.loadcontextok) {
data.name = data.c + "_" + data.m
Director.main.dispatchEventWith(GameEvents.GAMESCENE, false, {
t: "tcp",
data: data
}, false);
} else {
var name = data.c + "_" + data.m
if (name == 'room_loadcontext') {
data.name = data.c + "_" + data.m
Director.main.dispatchEventWith(GameEvents.GAMESCENE, false, {
t: "tcp",
data: data
}, false);
self.loadcontextok = true;
}
}
}
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close