1、清理仓库

This commit is contained in:
贝密游戏
2017-12-21 23:04:13 +08:00
parent eeb1c9e07b
commit b52d442381
1317 changed files with 138642 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},
// use this for initialization
onLoad: function () {
},
onBegin:function(){
/**
* 发射事件到 上一级 处理
*/
this.node.dispatchEvent( new cc.Event.EventCustom("begin", true) );
},
opendeal:function(){
/**
* 发射事件到 上一级 处理
*/
this.node.dispatchEvent( new cc.Event.EventCustom("opendeal", true) );
},
onClose:function(){
/**
* 发射事件到 上一级 处理
*/
this.node.dispatchEvent( new cc.Event.EventCustom("close", true) );
},
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "4e98004f-1cfb-4282-8cc9-84ec3cf0b65e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,879 @@
var beiMiCommon = require("BeiMiCommon");
cc.Class({
extends: beiMiCommon,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
gamebtn: {
default: null,
type: cc.Node
},
continuegamebtn:{
default: null,
type: cc.Node
},
poker: {
default: null,
type: cc.Node
},
lastCardsPanel: { //底牌
default: null,
type: cc.Node
},
waitting: {
default: null,
type: cc.Prefab
},
ratio:{ //底牌
default: null,
type: cc.Label
},
summary_win:{
default:null ,
type : cc.Prefab
},
summary:{
default:null ,
type : cc.Prefab
},
inviteplayer:{
default:null ,
type : cc.Prefab
}
},
// use this for initialization
onLoad: function () {
/**
* 适配屏幕尺寸
*/
this.resize();
this.player = new Array() ; //存放玩家数据
this.pokercards = new Array();
this.lastcards = new Array();
this.lastCardsPanel.active = false ;
this.summarypage = null ;
this.inited = false ;
this.lasttip = null ;
if(cc.beimi!=null){
if(cc.beimi.gamestatus!=null && cc.beimi.gamestatus == "playing"){
//恢复数据
this.recovery() ;
}else if(cc.beimi.extparams!=null && cc.beimi.extparams.gamemodel == "room"){
/**
* 房卡模式,开始启动游戏,当前玩家进入等待游戏的状态,显示邀请好友游戏,并分配 6位数字的房间号码
*/
/**
* 处理完毕,清理掉全局变量
* @type {null}
*/
this.invite = cc.instantiate(this.inviteplayer) ;
}
this.initgame();
}
},
begin:function(){
if(cc.beimi.data!=null && cc.beimi.data.enableai == true){
this.statictimer("正在匹配玩家" , cc.beimi.data.waittime) ;
}else{
this.statictimer("正在匹配玩家,请稍候" , cc.beimi.data.noaiwaitime) ;
}
this.startgame("false") ;
},
opendeal:function(){
if(cc.beimi.data!=null && cc.beimi.data.enableai == true){
this.statictimer("正在匹配玩家" , cc.beimi.data.waittime) ;
}else{
this.statictimer("正在匹配玩家,请稍候" , cc.beimi.data.noaiwaitime) ;
}
this.startgame("true") ;
},
recovery:function(){
this.statictimer("正在恢复数据,请稍候" , cc.beimi.data.waittime) ;
},
initgame:function(){
let self = this ;
this.gamebtn.active = true ;
this.continuegamebtn.active = false ;
if(this.ready()) {
let socket = this.socket();
this.game = this.getCommon("DizhuDataBind");
this.map("joinroom" , this.joinroom_event) ; //加入房价
this.map("players" , this.players_event) ; //接受玩家列表
this.map("catch" , this.catch_event) ; //叫地主
this.map("catchresult" , this.catchresult_event) ; //最终抢到地主的玩家
this.map("lasthands" , this.lasthands_event) ; //翻底牌
this.map("takecards" , this.takecards_event) ; //出牌信息
this.map("ratio" , this.ratio_event) ; //有炸
this.map("play" , this.play_event) ; //接受玩家列表
this.map("allcards" , this.allcards_event) ; //我出的牌
this.map("cardtips" , this.cardtips_event) ; //提示
this.map("roomready" , this.roomready_event) ; //提示
this.map("playeready" , this.playeready_event) ; //玩家点击了开始游戏 即准备就绪
this.map("cardtips" , this.cardtips_event) ; //提示
this.map("recovery" , this.recovery_event) ; //恢复牌局数据
socket.on("command" , function(result){
cc.beimi.gamestatus = "playing" ;
if(self.inited == true){
var data = self.parse(result) ;
self.route(data.command)(data , self);
}
});
/**
* 心跳检查,服务端发起的事件,服务端可以设置 PING的时长和 PING的 TimeOut
*/
socket.on("ping" , function(){
});
/**
* 此处有个问题:游戏中,如果点击了返回,进入过其他游戏,这个 cc.beimi.extparams.playway
* 就发生了改变,会导致当前游戏结束后,继续游戏的时候会出现问题
* @type {{token: (*|null), playway, orgi, extparams: *}}
*/
var param = {
token:cc.beimi.authorization,
playway:cc.beimi.extparams.playway,
orgi:cc.beimi.user.orgi,
extparams:cc.beimi.extparams
} ;
socket.emit("joinroom" ,JSON.stringify(param)) ;
this.inited = true ;
}
},
/**
* 新创建牌局,首个玩家加入,进入等待状态,等待其他玩家加入,服务端会推送 players数据
* @param data
* @param context
*/
joinroom_event:function(data , context){
if(data.cardroom == true && context.inviteplayer!=null){
let script = context.invite.getComponent("BeiMiQR")
script.init(data.roomid);
context.invite.parent = context.root() ;
}
//显示 匹配中并计时间超过设定的倒计时时间即AI加入根据当前的 玩家数量 匹配机器人
if(data.player.id && data.player.id == cc.beimi.user.id){
//本人,开始计时
//console.log("本人") ;
//self.player[0] = data ;
context.index = data.index ; //当前玩家所在位置
}else{
//其他玩家加入,初始化
var inroom = false ;
for(var i = 0 ; i < context.player.length ; i++){
var player = context.player[i].getComponent("PlayerRender") ;
if(player.userid == data.player.id){
inroom = true ;
}
}
if(inroom == false){
context.newplayer(context.player.length , context , data.player , context.index + 1 == data.index) ;
}
}
},
/**
* 房卡模式下,邀请的好友人到齐了
* @param data
* @param context
*/
roomready_event:function(data , context){
if(data.cardroom == true && context.invite!=null){
context.invite.destroy();
}
},
/**
*
* @param data
* @param context
*/
playeready_event:function(data , context){
if(data.userid == cc.beimi.user.id){
context.gamebtn.active = false ;
}
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局 , 玩家座位排列方式 和麻将统一, 都是东南西北方式 排列
* 0是首位玩家
* 1是右侧玩家
* 2是左侧玩家
* 麻将还有一个对家
* @param data
* @param context
*/
players_event:function(data,context){
var inx = -1 ;
for(var i = 0 ; i<data.player.length ; i++){
if(data.player[i].id == cc.beimi.user.id){
inx = i ; break ;
}
}
if(data.player.length > 1 && inx >=0){
var pos = inx+1 ;
while(true){
if(pos == data.player.length){pos = 0 ;}
if(context.playerexist(data.player[pos], context) == false){
context.newplayer(context.player.length , context , data.player[pos] , context.player.length == 0 && !(pos == 0 && data.player.length < data.maxplayers) ) ;
}
if(pos == inx){break ;}
pos = pos + 1;
}
}
},
playerexist:function(player,context){
var inroom = false ;
if(player.id == cc.beimi.user.id){
inroom = true ;
}else{
for(var j = 0 ; j < context.player.length ; j++){
if(context.player[j].id == player.id){
inroom = true ; break ;
}
}
}
return inroom ;
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局
* @param data
* @param context
*/
catch_event:function(data,context){
/**
* 修改倍率
*/
if(context.ratio){
context.ratio.string = data.ratio+"倍" ;
}
if(data.userid == cc.beimi.user.id){ //该我抢
context.game.catchtimer(15);
}else{ //该别人抢
for(var inx =0 ; inx<context.player.length ; inx++){
var render = context.player[inx].getComponent("PlayerRender") ;
if(render.userid && render.userid == data.userid){
render.catchtimer(15);
break ;
}
}
}
},
/**
* 接收到服务端的 恢复牌局的数据 恢复牌局
* @param data
* @param context
*/
recovery_event:function(data,context){
var mycards = context.decode(data.player.cards);
if(context.waittimer != null){
let timer = context.waittimer.getComponent("BeiMiTimer");
if(timer){
timer.stop(context.waittimer) ;
}
}
/**
* 清理掉 extparam;
* @type {boolean}
*/
context.gamebtn.active = false ;
if(context.ratio){
context.ratio.string = data.ratio+"倍" ;
}
context.doLastCards(context.game , context , 3 , 0);
for(var inx =0 ; inx < mycards.length ; inx++){
let pokencard = context.playcards(context.game , context, inx * 50-300 , mycards[inx]);
context.registerProxy(pokencard);
}
/**
* 赋值,解码牌面
*/
for(var i=0 ; i<context.pokercards.length ; i++){
var pokencard = context.pokercards[i];
pokencard.getComponent("BeiMiCard").order();
}
context.lastCardsPanel.active = true ;
if(data.lasthands){
var lasthands = context.decode(data.lasthands);
/**
* 底牌 顶部的 三张底牌显示区域
*/
for(var i=0 ; i<context.lastcards.length ; i++){
var last = context.lastcards[i].getComponent("BeiMiCard") ;
last.setCard(lasthands[i]);
last.order();
}
/**
* 设置地主标志
*/
if(data.banker.userid == cc.beimi.user.id){
context.game.lasthands(context , context.game , data.data ) ;
}else{
context.getPlayer(data.banker.userid).setDizhuFlag(data.data);
}
}
/**
* 恢复最后出的牌
*/
if(data.last != null){
let lastcards = context.decode(data.last.cards); //解析牌型
if (data.last.userid == cc.beimi.user.id) {
context.game.lasttakecards(context.game, context, data.last.cardsnum, lastcards , data.last);
} else {
context.getPlayer(data.last.userid).lasttakecards(context.game, context, data.last.cardsnum, lastcards , data.last);
}
if (data.nextplayer == cc.beimi.user.id) {
context.game.playtimer(context.game, 25 , data.automic);
} else {
context.getPlayer(data.nextplayer).playtimer(context.game, 25);
}
}
if(data.cardsnum!=null && data.cardsnum.length > 0){
for(var i =0 ; i<data.cardsnum.length ; i++){
context.getPlayer(data.cardsnum[i].userid).resetcards(data.cardsnum[i].cardsnum);
}
}
},
/**
* 有玩家出炸
* @param data
* @param context
*/
ratio_event:function(data,context){
/**
* 修改倍率
*/
if(data.king == true){
//王炸,播放音效
}else if(data.bomb == true){
//普通炸弹,播放音效
}
if(context.ratio){
context.ratio.string = data.ratio+"倍" ;
}
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局
* @param data
* @param context
*/
catchresult_event:function(data,context){
/**
* 修改倍率
*/
if(context.ratio){
context.ratio.string = data.ratio+"倍" ;
}
if(data.userid == cc.beimi.user.id){ //该我抢
context.game.catchresult(data);
}else{ //该别人抢
setTimeout(function(){
context.getPlayer(data.userid).catchresult(data);
},1500) ;
}
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局
* @param data
* @param context
*/
lasthands_event:function(data,context){
var lasthands = context.decode(data.lasthands);
/**
* 底牌 顶部的 三张底牌显示区域
*/
for(var i=0 ; i<context.lastcards.length ; i++){
var last = context.lastcards[i].getComponent("BeiMiCard") ;
last.setCard(lasthands[i]);
last.order();
}
/**
* 当前玩家的 底牌处理
*/
if(data.userid == cc.beimi.user.id) {
context.game.lasthands(context , context.game , data ) ;
/**
* 隐藏 其他玩家的 抢地主/不抢地主的 提示信息
*/
for(var inx =0 ; inx<context.player.length ; inx++){
var render = context.player[inx].getComponent("PlayerRender") ;
render.hideresult();
}
for(var i=0 ; i<lasthands.length ; i++){
let func = null ;
if(i == (lasthands.length - 1)){
func = cc.callFunc(function (target , data) {
if(data.tempcontext){
data.tempcontext.layout(data.tempcontext.poker , function(fir , sec){
return fir.zIndex - sec.zIndex ;
});
}
}, this , {tempcontext: context});
}
let pc = context.current(context.game , context ,2 * 300 + (6 + i) * 50-300, lasthands[i] , func) ;
var beiMiCard = pc.getComponent("BeiMiCard") ;
beiMiCard.order();
context.registerProxy(pc);
}
context.game.playtimer(context.game,25 , true);
}else{
context.game.hideresult();
for(var inx =0 ; inx<context.player.length ; inx++){
var render = context.player[inx].getComponent("PlayerRender") ;
render.hideresult();
}
context.getPlayer(data.userid).lasthands(context,context.game,data);
context.getPlayer(data.userid).playtimer(context.game , 25);
}
for(var inx =0 ; inx<context.pokercards.length ; inx++){
var pc = context.pokercards[inx] ;
pc.zIndex = 54 - pc.card ;
}
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局
* @param data
* @param context
*/
takecards_event:function(data,context){
context.lasttip = null ;
if(data.allow == true) {
var lastcards ;
if(data.donot == false){
lastcards = context.decode(data.cards); //解析牌型
}
if (data.userid == cc.beimi.user.id) {
context.game.unselected(context , context.game) ;
context.game.lasttakecards(context.game, context, data.cardsnum, lastcards , data);
} else {
context.getPlayer(data.userid).lasttakecards(context.game, context, data.cardsnum, lastcards , data);
}
context.game.selectedcards.splice(0 ,context.game.selectedcards.length );//清空
if(data.over == false){
if (data.nextplayer == cc.beimi.user.id) {
context.game.playtimer(context.game, 25 , data.automic);
} else {
context.getPlayer(data.nextplayer).playtimer(context.game, 25);
}
}
}else{//出牌不符合规则,需要进行提示
context.game.notallow.active = true ;
setTimeout(function(){
context.game.notallow.active = false ;
} , 2000);
context.game.unselected(context , context.game);
}
},
/**
* 接收到服务端的 出牌提示信息
* @param data
* @param context
*/
cardtips_event:function(data,context){
context.game.unselected(context , context.game) ;
if(data.allow == true) {
var tipcards = context.decode(data.cards); //解析牌型
context.lasttip = tipcards.join(",") ;
for(var inx = 0 ; inx < tipcards.length ; inx++){
context.game.cardtips(context , tipcards[inx] , tipcards) ;
}
}else{//出牌不符合规则,需要进行提示
context.game.cardtipsfornot(context , context.game);
}
},
/**
* 接收到服务端的 推送的 玩家数据,根据玩家数据 恢复牌局
* @param data
* @param context
*/
play_event:function(data,context){
/**
* 增加了全局变量gamestatus , 用于控制当前玩家退出后恢复数据
* @type {string}
*/
cc.beimi.gamestatus = "playing" ;
var mycards = context.decode(data.player.cards);
if(context.waittimer){
let timer = context.waittimer.getComponent("BeiMiTimer");
if(timer){
timer.stop(context.waittimer) ;
}
}
let center = context.game.pokerpool.get();
let left = context.game.pokerpool.get(),right = context.game.pokerpool.get();
center.parent = context.root() ;
left.parent = context.root() ;
right.parent = context.root() ;
center.setPosition(0,200);
left.setPosition(0,200);
right.setPosition(0,200);
let finished = cc.callFunc(function (target , data) {
if(data.game){
data.game.pokerpool.put(data.current) ;
data.game.pokerpool.put(data.left);
data.game.pokerpool.put(data.right);
/**
* 赋值,解码牌面
*/
for(var i=0 ; i<data.self.pokercards.length ; i++){
var pokencard = data.self.pokercards[i];
pokencard.getComponent("BeiMiCard").order();
}
data.self.lastCardsPanel.active = true ;
}
}, this , {game : context.game , self: context, left :left , right : right , current : center});
context.doLastCards(context.game , context , 3 , 0);
/**
* 发牌动作每次6张本人保留总计17张其他人发完即回收
*/
setTimeout(function() {
context.dealing(context.game , 6 , context , 0 , left , right , mycards) ;
setTimeout(function(){
context.dealing(context.game , 6 , context , 1, left , right , mycards) ;
setTimeout(function(){
context.dealing(context.game , 5 , context , 2, left , right , mycards , finished) ;
context.reordering(context);
},500) ;
},500) ;
}, 0);
},
/**
* 打完牌,进入结算界面,结算界面流程:
* 1、提示你赢/输了
* 2、1秒后所有玩家的牌翻出来显示剩余的牌
* 3、2秒后显示结算界面
* 4、玩家点选明牌开始还是继续游戏
* @param data
* @param context
*/
allcards_event:function(data , context){
/**
* 全局变量控制,用于恢复数据
* @type {string}
*/
cc.beimi.gamestatus = "notready" ;
//结算界面,
let player ;
for(var i=0 ; i<data.players.length ; i++){
var temp = data.players[i] ;
if(temp.userid != cc.beimi.user.id){
var cards = context.decode(temp.cards); //解析牌型
var tempscript = context.getPlayer(temp.userid) ;
for(var inx = 0 ; inx < cards.length ; inx++) {
//tempscript.lasttakecards(context.game, context, cards.length, cards, data);
/**
* 最后牌局结束以后,显示所有玩家的手牌
*/
}
}else{
player = temp ;
}
}
if(player!=null) {
/**
* 更新个人账号资产信息
*/
context.pva("gold" , player.balance);
/**
* 刷新个人资产显示 , 可以增加相关动画显示duang的一声显示的金币变成金光闪闪的然后再变回去
*/
context.updatepva() ;
}
setTimeout(function(){
if(player!=null){
if(player.win == true){
context.summarypage = cc.instantiate(context.summary_win) ;
}else{
context.summarypage = cc.instantiate(context.summary) ;
}
context.summarypage.parent = context.root() ;
let temp = context.summarypage.getComponent("SummaryDetail") ;
temp.create(context , data);
}
/**
* 隐藏顶部的 底牌 显示区域
* @type {boolean}
*/
context.lastCardsPanel.active = false ;
if(data.gameRoomOver == true){//房间解散
for(var inx = 0 ; inx<context.player.length ; inx++){
context.player[inx].destroy();
}
context.player.splice(0 , context.player.length) ;//房间解散,释放资源
context.player = new Array();
context.clean();
}
} , 2000);
},
getPlayer:function(userid){
var tempRender;
for(var inx =0 ; inx<this.player.length ; inx++){
var render = this.player[inx].getComponent("PlayerRender") ;
if(render.userid && render.userid == userid){
tempRender = render ; break ;
}
}
return tempRender ;
},
dealing:function(game , num , self , times , left , right , cards , finished){
/**
* 处理当前玩家的 牌, 发牌 17张牌 分三次动作处理完成
*/
for(var i=0 ; i<num ; i++){
var myCards = self.current(game , self ,times * 300 + i * 50-300, cards[times * 6 + i] , finished) ;
this.registerProxy(myCards);
}
self.otherplayer(left , 0 , num ,game , self) ;
self.otherplayer(right , 1 , num ,game , self) ;
},
otherplayer:function(currpoker , inx, num ,game , self){
if(inx == 0){
let seq = cc.sequence(
cc.spawn(cc.moveTo(0.2, -350, 50) , cc.scaleTo(0.2, 0.3, 0.3)) , cc.moveTo(0 , 0 , 200) , cc.scaleTo(0, 1, 1)
);
currpoker.runAction(seq);
}else{
let seq = cc.sequence(
cc.spawn(cc.moveTo(0.2, 350, 50) , cc.scaleTo(0.2, 0.3, 0.3)) , cc.moveTo(0 , 0 , 200) , cc.scaleTo(0, 1, 1)
);
currpoker.runAction(seq);
}
//currpoker.setScale(1);
var render = self.player[inx].getComponent("PlayerRender") ;
for(var i=0 ; i<num ; i++){
render.countcards(1);
}
},
doLastCards:function(game , self , num , card){//发三张底牌
for(var i=0 ; i<num ; i++){
var width = i * 80 - 80;
let currpoker = game.minpokerpool.get() ;
currpoker.getComponent("BeiMiCard").setCard(card) ;
currpoker.card = card ;
currpoker.parent = this.lastCardsPanel;
currpoker.setPosition(width , 0);
self.lastcards[self.lastcards.length] = currpoker ;
}
},
registerProxy:function(myCard){
if(myCard){
var beiMiCard = myCard.getComponent("BeiMiCard") ;
beiMiCard.proxy(this.game);
}
},
playcards:function(game , self , posx , card){
return self.current(game ,self , posx , card , null);
},
current:function(game , self , posx , card , func){
let currpoker = game.pokerpool.get() ;
var beiMiCard = currpoker.getComponent("BeiMiCard") ;
beiMiCard.setCard(card) ;
currpoker.card = card ;
currpoker.parent = self.poker ;
currpoker.setPosition(0,200);
currpoker.setScale(1,1);
currpoker.zIndex = 100 - card ;
self.pokercards.push(currpoker);
if(func!=null){
let seq = cc.sequence(cc.moveTo(0.2, posx, -180) , func);
currpoker.runAction(seq);
}else{
let action = cc.moveTo(0.2, posx, -180) ;
currpoker.runAction(action);
}
return currpoker;
},
reordering:function(self){
for(var i=0 ; i<self.pokercards.length ; i++){
self.pokercards[i].parent = self.poker ;
}
},
newplayer:function(inx , self , data , isRight){
var pos = cc.v2(520, 100) ;
if(isRight == false){
pos = cc.v2(-520,100) ;
}
let game = self.getCommon("DizhuDataBind");
if(game && game.playerspool.size() > 0){
self.player[inx] = game.playerspool.get() ;
self.player[inx].parent = self.root() ;
self.player[inx].setPosition(pos);
var render = self.player[inx].getComponent("PlayerRender") ;
render.initplayer(data , isRight);
}
},
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
/**
* 不抢/叫地主
*/
givup:function(){
if(this.ready()){
let socket = this.socket();
socket.emit("giveup","giveup");
}
},
/**
* 开始游戏
*/
startgame:function(opendeal){
if(this.ready()){
let socket = this.socket();
socket.emit("start",opendeal);
}
},
/**
* 不抢/叫地主
*/
cardtips:function(){
if(this.ready()){
let socket = this.socket();
if(this.lasttip!=null){
socket.emit("cardtips",this.lasttip);
}else{
socket.emit("cardtips","");
}
this.lasttip = null ;
}
},
/**
* 抢/叫地主触发事件
*/
docatch:function(){
if(this.ready()){
let socket = this.socket();
socket.emit("docatch","docatch");
}
},
/**
* 出牌
*/
doPlayCards:function(){
if(this.ready()){
let socket = this.socket();
this.game.selectedcards.splice(0 , this.game.selectedcards.length) ;
for(var i=0 ; i<this.pokercards.length ; i++){
var card = this.pokercards[i] ;
var temp = card.getComponent("BeiMiCard");
if(temp.selected == true){
this.game.selectedcards.push(temp.card) ;
}
}
socket.emit("doplaycards" , this.game.selectedcards.join());
}
this.lasttip = null ;
},
/**
* 不出牌
*/
noCards:function(){
if(this.ready()){
let socket = this.socket();
socket.emit("nocards","nocards");
}
this.lasttip = null ;
},
clean:function(){
for(var inx = 0 ; inx<this.pokercards.length ; inx++){
let pc = this.pokercards[inx] ;
this.game.pokerpool.put(pc) ;//回收回去
}
this.pokercards.splice(0 , this.pokercards.length ) ;
for(var i=0 ; i<this.lastcards.length ; i++){
this.game.minpokerpool.put(this.lastcards[i]);
}
this.lastcards.splice( 0 , this.lastcards.length) ;
for(var i = 0 ; i < this.player.length ; i++){
var player = this.player[i].getComponent("PlayerRender") ;
player.clean(this.game);
}
this.player.splice(0 , this.player.length) ;
this.game.clean(this);
this.ratio.string = "15倍" ;
},
onCloseClick:function(){
this.continuegamebtn.active = true ;
},
restart:function(command){
this.game.restart();
this.statictimer("正在匹配玩家" , 5) ;
/**
* 系统资源回收完毕,发送一个 重新开启游戏的 通知
*/
if(this.ready()){
let socket = this.socket();
socket.emit("restart" , command);
}
},
continuegame:function(){
this.continuegamebtn.active = false ;
this.restart("begin");
},
statictimer:function(message , time){
this.waittimer = cc.instantiate(this.waitting);
this.waittimer.parent = this.root();
let timer = this.waittimer.getComponent("BeiMiTimer");
if(timer){
timer.init(message , time , this.waittimer);
}
},
onDestroy:function(){
this.inited = false ;
this.cleanmap();
if(this.ready()){
let socket = this.socket();
socket.emit("leave","leave");
}
}
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "cc4147da-7f1d-447c-8121-75f5407ac9d6",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,35 @@
var beiMiCommon = require("BeiMiCommon");
cc.Class({
extends: beiMiCommon,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},
// use this for initialization
onLoad: function () {
},
back:function(){
this.loadding();
let self = this ;
setTimeout(function(){
self.scene(cc.beimi.gametype , self);
} , 500)
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "74593989-ba8b-43d1-8fc7-ff28e575f02c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,425 @@
var beiMiCommon = require("BeiMiCommon");
cc.Class({
extends: beiMiCommon,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
goldcoins: {
default: null,
type: cc.Label
},
cards: {
default: null,
type: cc.Label
},
player: {
default: null,
type: cc.Prefab
},
poker: {
default: null,
type: cc.Prefab
},
poker_min: {
default: null,
type: cc.Prefab
},
myself: {
default: null,
type: cc.Prefab
},
atlas: {
default: null,
type: cc.SpriteAtlas
},
catchbtn: {
default: null,
type: cc.Node
},
timer: {
default: null,
type: cc.Node
},
timer_num:{
default: null,
type: cc.Label
},
lastcards:{
default: null,
type: cc.Node
},
playbtn:{
default: null,
type: cc.Node
},
notallow:{
default: null,
type: cc.Node
},
operesult:{
default: null,
type: cc.Node
},
donottake:{
default: null,
type: cc.Node
},
cardtipmsg:{
default: null,
type: cc.Node
}
},
// use this for initialization
onLoad: function () {
let self = this ;
if(this.timer){
this.timer.active = false ;
}
if(this.catchbtn){
this.catchbtn.active = false ;
}
if(this.playbtn){
this.playbtn.active = false ;
}
if(this.notallow){
this.notallow.active = false ;
}
if(this.operesult){
this.operesult.active = false ;
}
if(this.cardtipmsg){
this.cardtipmsg.active = false ;
}
this.playerspool = new cc.NodePool();
this.myselfpool = new cc.NodePool();
this.pokerpool = new cc.NodePool(); //背面
this.minpokerpool = new cc.NodePool(); //背面
this.selectedcards = new Array(); //存放当前玩家 选中 的牌
this.cardslist = new Array();
for(i=0 ; i<2 ; i++){
this.playerspool.put(cc.instantiate(this.player)); // 创建节点
}
for(i =0 ; i<25 ; i++){
this.pokerpool.put(cc.instantiate(this.poker)); //牌-背面
}
for(i =0 ; i<60 ; i++){
this.minpokerpool.put(cc.instantiate(this.poker_min)); //牌-背面
}
this.myselfpool.put(cc.instantiate(this.myself));
if(this.ready()){
this.pva_format(cc.beimi.user.goldcoins , cc.beimi.user.cards , cc.beimi.user.diamonds , self);
this.pvalistener(self , function (context) {
context.pva_format(cc.beimi.user.goldcoins , cc.beimi.user.cards , cc.beimi.user.diamonds , context) ;
});
}
if(this.myselfpool.size() > 0 && cc.beimi != null){
this.playermysql = this.myselfpool.get();
this.playermysql.parent = this.root() ;
this.playermysql.setPosition(-520,-180);
var render = this.playermysql.getComponent("PlayerRender") ;
render.initplayer(cc.beimi.user);
}
},
pva_format:function(coins, cards , diamonds , object){
if(coins > 9999){
var num = coins / 10000 ;
object.goldcoins.string = num.toFixed(2) + '万';
}else{
object.goldcoins.string = coins;
}
object.cards.string = cards + "张" ;
},
catchtimer:function(times){
if(this.playbtn){
this.playbtn.active = false ;
}
if(this.timer){
this.timer.active = true ;
}
if(this.catchbtn){
this.catchbtn.active = true ;
}
if(this.operesult){
this.operesult.active = false ;
}
let self = this ;
var gameTimer = require("GameTimer");
this.beimitimer = new gameTimer();
this.timesrc = this.beimitimer.runtimer(this , this.timer , this.atlas , this.timer_num , this.timer_num , times);
},
catchresult:function(data){
if(this.timer){
this.timer.active = false ;
}
if(this.catchbtn){
this.catchbtn.active = false ;
}
if(this.playbtn){
this.playbtn.active = false ;
}
if(this.timesrc){
this.beimitimer.stoptimer(this , this.timer , this.timesrc);
}
this.doOperatorResult("catch" , data.docatch , false) ;
},
hideresult:function(){
if(this.operesult){
this.operesult.active = false ;
}
},
lasthands:function(self, game,data){ //设置地主
this.setDizhuFlag(data) ;
if(this.operesult){
this.operesult.active = false ;
}
},
setDizhuFlag:function(data){
var render = this.playermysql.getComponent("PlayerRender") ;
render.setDizhuFlag(data);
},
lasttakecards:function(game , self , cardsnum ,lastcards , data){
if(this.result){
this.result.active = false ;
}
if(this.playbtn){
this.playbtn.active = false ;
}
if(this.catchbtn){
this.catchbtn.active = false;
}
if(this.jsq){
this.jsq.active = false ;
}
if(this.lastcards){
this.lastcards.active = true ;
}
if(this.timesrc){
this.beimitimer.stoptimer(this , this.timer , this.timesrc);
}
for(var i=0 ; i<this.cardslist.length ; i++){
this.pokerpool.put(this.cardslist[i]) ;//回收回去
}
this.cardslist.splice(0,this.cardslist.length) ;//删除数组里的所有内容
if (data.donot == false) { //选择出牌或默认出牌
for(var i=0 ; i<lastcards.length ; i++){
this.playcards(self , i , lastcards[i] , lastcards) ;
}
this.layout(this.lastcards , function(fir , sec){
return fir.zIndex - sec.zIndex ;
});
}else{
this.doOperatorResult("lasttakecards" , true , data.sameside) ;
}
},
cardtips:function(self , card , tipcards){
var cacheCard ;
for(var inx = 0 ; inx<self.pokercards.length ; inx++){
let pc = self.pokercards[inx] ;
if(pc.getComponent("BeiMiCard").card == card){
cacheCard = pc ; break ;
}
}
if(cacheCard != null){
cacheCard.getComponent("BeiMiCard").doselect();
}
},
cardtipsfornot:function(self , game){
game.cardtipmsg.active = true ;
setTimeout(function(){
game.cardtipmsg.active = false ;
} , 1000);
game.unselected(self , game) ;
},
unselected:function( self , game){
for(var inx = 0 ; inx<self.pokercards.length ; inx++){
let pc = self.pokercards[inx] ;
pc.getComponent("BeiMiCard").unselected();
}
},
playcards:function(self , index , card , lastcards){
var cacheCard ;
for(var inx = 0 ; inx<self.pokercards.length ; inx++){
let pc = self.pokercards[inx] ;
if(pc.card == card){
cacheCard = pc ; break ;
}
}
if(cacheCard != null){
cacheCard.getComponent("BeiMiCard").unselected();
cacheCard.x = index * 30 - 30 ;
cacheCard.y = 0;
var zIndex = this.countcard(card , lastcards) ;
cacheCard.zIndex = 4 - zIndex ;
// cacheCard.zIndex = zIndex;
cacheCard.setScale(0.5,0.5);
cacheCard.parent = this.lastcards ;
this.cardslist.push(cacheCard) ;
}
},
/**
* 按照张数最大的牌排序
* @param card
* @param lastcards
* @returns {number}
*/
countcard:function(card , lastcards){
let value = parseInt(card / 4);
let count = 0 ;
for(var i = 0 ;i<lastcards.length ; i++){
let temp = parseInt(lastcards[i] / 4) ;
if(value == temp){
count = count + 1 ;
}
}
return count ;
},
/**
*
* @param game
* @param times
* @param automic 不允许 不出
*/
playtimer:function(game , times , automic){
if(this.timer){
this.timer.active = true ;
}
if(this.playbtn){
this.playbtn.active = true ;
}
if(this.catchbtn){
this.catchbtn.active = false;
}
if(this.lastcards){
this.lastcards.active = false ;
}
if(this.operesult){
this.operesult.active = false ;
}
if(automic == true){
this.donottake.active = false ;
}else{
this.donottake.active = true ;
}
for(var i=0 ; i<this.cardslist.length ; i++){
game.pokerpool.put(this.cardslist[i]) ;//回收回去
}
let self = this ;
var gameTimer = require("GameTimer");
this.beimitimer = new gameTimer();
this.timesrc = this.beimitimer.runtimer(this , this.timer , this.atlas , this.timer_num , this.timer_num , times);
},
doOperatorResult:function(oper , resvalue , sameside){
this.operesult.active = true ;
if(oper == "catch"){
if(resvalue == true){
for(var i=0 ; i<this.operesult.children.length ; i++){
this.operesult.children[i].active = false ;
if(this.operesult.children[i].name == "提示_抢地主"){
this.operesult.children[i].active = true ;
}
}
}else {
for (var i = 0; i < this.operesult.children.length; i++) {
this.operesult.children[i].active = false;
if (this.operesult.children[i].name == "提示_不抢") {
this.operesult.children[i].active = true;
}
}
}
}else if(oper == "lasttakecards"){
if(sameside == true){
for (var i = 0; i < this.operesult.children.length; i++) {
this.operesult.children[i].active = false;
if (this.operesult.children[i].name == "不要") {
this.operesult.children[i].active = true;
}
}
}else{
for (var i = 0; i < this.operesult.children.length; i++) {
this.operesult.children[i].active = false;
if (this.operesult.children[i].name == "要不起") {
this.operesult.children[i].active = true;
}
}
}
}
},
doSelectCard:function(card){
var existcard = this.selectedcards.find(function(pokercard){
pokercard.card == card
});
if(existcard == undefined){
this.selectedcards.push(card) ;
}
},
doUnSelectCard:function(card){
var inx = this.selectedcards.indexOf(card);
if(inx >= 0){
this.selectedcards.splice(inx , inx+1) ;
}
},
clean:function(context){
if(this.catchbtn){
this.catchbtn.active = false;
}
if(this.lastcards){
this.lastcards.active = false ;
}
if(this.operesult){
this.operesult.active = false ;
}
var render = this.playermysql.getComponent("PlayerRender") ;
render.clean(context) ;
},
restart:function(){
for(var i=0 ; i<2 ; i++){
this.playerspool.put(cc.instantiate(this.player)); // 创建节点
}
/**
* 费劲巴拉的收集起来,然后又给销毁了,浪费资源!!!
*/
this.pokerpool.clear();
this.minpokerpool.clear();
for(var inx =0 ; inx<25 ; inx++){
this.pokerpool.put(cc.instantiate(this.poker)); //牌-背面
}
for(var inx=0 ; inx<60 ; inx++){
this.minpokerpool.put(cc.instantiate(this.poker_min)); //牌-背面
}
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "eb412ac9-8a52-4f16-8fde-68b568d9ecba",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,29 @@
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},
// use this for initialization
onLoad: function () {
},
back:function(){
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "8ed13591-a0be-4cbf-b7cb-c8d18b1d5a6e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,43 @@
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
posy:cc.Integer,
card:{
default:null ,
type : cc.Node
}
},
// use this for initialization
onLoad: function () {
this.posy = this.card.y ;
},
takecard:function(event){
var beiMiCard = event.target.parent.getComponent("BeiMiCard") ;
if(beiMiCard.game != null){
if(event.target.y == this.posy){
event.target.y = event.target.y + 30 ;
beiMiCard.selected = true ;
}else{
event.target.y = event.target.y - 30 ;
beiMiCard.selected = false ;
}
}
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "0da62514-88a1-42cb-a523-99b5e81f9e77",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,34 @@
var beiMiCommon = require("BeiMiCommon");
cc.Class({
extends: beiMiCommon,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},
// use this for initialization
onLoad: function () {
},
onClick:function(event , data){
if(this.ready()){
let socket = this.socket();
socket.emit("selectcolor" , data);
}
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "f832747c-8051-4b8b-bd90-726f48129490",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,149 @@
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
workitem:{
default: null,
type: cc.Node
},
myscore:{ //底牌
default: null,
type: cc.Label
},
myflag:{
default: null,
type: cc.Node
},
player_1:{
default: null,
type: cc.Node
},
player_1_flag:{
default: null,
type: cc.Node
},
player_1_name:{
default: null,
type: cc.Label
},
player_1_score:{
default: null,
type: cc.Label
},
player_2:{
default: null,
type: cc.Node
},
player_2_flag:{
default: null,
type: cc.Node
},
player_2_name:{
default: null,
type: cc.Label
},
player_2_score:{
default: null,
type: cc.Label
},
},
// use this for initialization
onLoad: function () {
let self = this ;
/**
* SummaryClick发射的事件方便统一处理 / 开始
*/
this.workitem.on("begin",function(event){
if(self.context !=null){
self.context.summarypage.destroy();
/**
* 恢复桌面
*/
self.context.restart("begin");
}
event.stopPropagation();
});
/**
* SummaryClick发射的事件方便统一处理 / 明牌开始
*/
this.workitem.on("opendeal",function(event){
if(self.context !=null){
self.context.summarypage.destroy();
/**
* 恢复桌面,然后发送消息给服务端
*/
self.context.restart("opendeal");
}
event.stopPropagation();
});
/**
* SummaryClick发射的事件方便统一处理 / 开始
*/
this.workitem.on("close",function(event){
if(self.context !=null){
/**
* 显示操作按钮
*/
self.context.onCloseClick();
self.context.summarypage.destroy();
}
event.stopPropagation();
});
},
create:function(context , data){
this.context = context ;
var index = 0 ;
for(var inx = 0 ; inx < data.players.length ; inx++){
var player = data.players[inx] ;
if(player.userid == cc.beimi.user.id){//
this.process(player , null , this.myscore, this.myflag) ;
}else{
if(index == 0){
this.process(player ,this.player_1_name , this.player_1_score , this.player_1_flag ) ;
}else if(index == 1){
this.process(player ,this.player_2_name , this.player_2_score , this.player_2_flag ) ;
}
index = index + 1 ;
}
}
},
/**
* 显示已经处理完毕的结算信息
* @param player
* @param username
* @param score
* @param flag
*/
process:function(player , username , score , flag){
if(username != null){
username.string = player.username ;
}
if(player.win == true){
score.string = player.score ;
}else{
score.string = "-"+player.score ;
}
if(player.dizhu == true){
flag.active = true ;
}else{
flag.active = false ;
}
}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "4b94def9-b352-4c94-b838-5289019afb54",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}