123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- var UIHelper = require("UIHelper");
- var Global = require("Global");
- var topTipMsg = require("topTipMsg");
- var GameProtocol = require("TrucoGameProtocol");
- var GameLogic = require("TrucoGameLogic");
- import ScenceManager from 'HNScenceManager';
- cc.Class({
- extends: cc.Component,
- properties: {
- cardNode: cc.Node,
- cardClone: cc.Node,
- },
- onLoad() {
- this.cardsInfo = [
- 0x32,0x22,0x12,0x02,0x32,0x22,0x12,0x02,
- 0x31,0x21,0x11,0x01,0x31,0x21,0x11,0x01,
- 0x3D,0x2D,0x1D,0x0D,0x3D,0x2D,0x1D,0x0D,
- 0x3C,0x2C,0x1C,0x0C,0x3C,0x2C,0x1C,0x0C,
- 0x3B,0x2B,0x1B,0x0B,0x3B,0x2B,0x1B,0x0B,
- 0x3A,0x2A,0x1A,0x0A,0x3A,0x2A,0x1A,0x0A,
- 0x39,0x29,0x19,0x09,0x39,0x29,0x19,0x09,
- 0x38,0x28,0x18,0x08,0x38,0x28,0x18,0x08,
- 0x37,0x27,0x17,0x07,0x37,0x27,0x17,0x07,
- 0x36,0x26,0x16,0x06,0x36,0x26,0x16,0x06,
- 0x35,0x25,0x15,0x05,0x35,0x25,0x15,0x05,
- 0x34,0x24,0x14,0x04,0x34,0x24,0x14,0x04,
- 0x33,0x23,0x13,0x03,0x33,0x23,0x13,0x03,
- ];
- this.cardNode.removeAllChildren();
- for(let i = 0; i < this.cardsInfo.length; ++i) {
- const element = this.cardsInfo[i];
- let card = cc.instantiate(this.cardClone);
- card.parent = this.cardNode;
- card.active = true;
- card.belong = -1;
- card.beMagic = -1;
- let js = card.getComponent("TrucoCard");
- if(js) {
- js.setId(element, 0);
- }
- // UIHelper.addButtonListener(card, this.node, "TrucoControl", "clickCard");
- }
- this.selectedCards = [];
- this.selectedMagicCard = null;
- // this.node.on(cc.Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
- this.node.on(cc.Node.EventType.MOUSE_UP, this.onMouseDown, this);
- },
- onMouseDown(event) {
- let mouseType = event.getButton();
- let mousePoint = event.getLocation();
- let localPoint = this.cardNode.convertToNodeSpaceAR(mousePoint);
- var touchCard = null;
- for(let i = 0; i < this.cardNode.childrenCount; ++i) {
- var cardNode = this.cardNode.children[i];
- var cardSize = cardNode.getBoundingBox().size;
- var cardPos = cardNode.getPosition();
- var rect = cc.rect(cardPos.x-cardSize.width/2,cardPos.y-cardSize.height/2,cardSize.width,cardSize.height);
- if (rect.contains(localPoint)){
- touchCard = cardNode;
- break;
- }
- }
- if(!touchCard) return;
- Global.print(touchCard);
- if (mouseType === cc.Event.EventMouse.BUTTON_LEFT) {
- this.clickCard({target: touchCard});
- }else if(mouseType === cc.Event.EventMouse.BUTTON_RIGHT) {
- this.selectMagicCard({target: touchCard});
- }
- },
- show () {
- this.node.active = true;
- },
- onClickClose() {
- this.node.active = false;
- },
- onClickZiCe() {
-
- // if(this.selectedCards.length < 9) {
- // topTipMsg.showTopTipMsg("选中的牌少于9张");
- // return;
- // }
- let jsGameSence = ScenceManager.Instance().getGameComponent();
- if(jsGameSence._GameLogic.isSet([0,1,2,3],this.selectedCards)) {
- Global.print(this.selectedCards);
- }
- return;
- let magicCard = this.selectedMagicCard?this.selectedMagicCard.getComponent("TrucoCard").cardId():0;
- let huase = magicCard&0xF0;
- let value = (magicCard&0x0F) % 13;
- var magicCards = [];
- if((huase >> 4)%2 == 0) {
- magicCards.push(0x00|(value));
- magicCards.push(0x20|(value));
- }else{
- magicCards.push(0x10|(value));
- magicCards.push(0x30|(value));
- }
- jsGameSence._GameLogic.setMagicCard(magicCards);
- jsGameSence._GameLogic.analyseCardsGroupWithSort(this.selectedCards);
- },
- onClickSend() {
- if(this.selectedCards.length < 9) {
- topTipMsg.showTopTipMsg("选中的牌少于9张");
- return;
- }
- let jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.SendGameSocketData(GameProtocol.SUB_C_TEST_CARD,{
- cbHandCard: this.selectedCards,
- cbMagicCard: this.selectedMagicCard?this.selectedMagicCard.getComponent("TrucoCard").cardId():0,
- });
- },
- selectMagicCard(event) {
- let card = event.target;
- if(this.selectedMagicCard) {
- if(this.selectedMagicCard == card) {
- card.color = cc.color(255,255,255);
- if(card.belong == 1) {
- card.color = cc.color(255,0,0);
- }
- card.beMagic = -1;
- this.selectedMagicCard = null;
- }else{
- this.selectedMagicCard.color = cc.color(255,255,255);
- this.selectedMagicCard.beMagic = -1;
- if(this.selectedMagicCard.belong == 1) {
- this.selectedMagicCard.color = cc.color(255,0,0);
- }
- card.color = cc.color(0,255,0);
- if(card.belong == 1) {
- card.color = cc.color(255,255,0);
- }
- card.beMagic = 1;
- this.selectedMagicCard = card;
- }
- }else{
- card.color = cc.color(0,255,0);
- if(card.belong == 1) {
- card.color = cc.color(255,255,0);
- }
- card.beMagic = 1;
- this.selectedMagicCard = card;
- }
- // let cardid = card.getComponent("TrucoCard").cardId();
- // if(card.beMagic == 1) {
- // card.color = cc.color(255,255,255);
- // if(card.belong == 1) {
- // card.color = cc.color(255,0,0);
- // }
- // card.beMagic = -1;
- // for(let i = 0; i < this.cardNode.childrenCount; ++i) {
- // let cardd = this.cardNode.children[i];
- // if(cardd.getComponent("TrucoCard").cardId() == cardid) {
- // cardd.color = cc.color(255,255,255);
- // if(card.belong == 1) {
- // card.color = cc.color(255,0,0);
- // }
- // this.selectedMagicCard = -1;
- // return;
- // }
- // }
- // return;
- // }
- // if(card.beMagic < 0) {
- // card.beMagic = 1;
- // card.color = cc.color(0,255,0);
- // if(card.belong == 1) {
- // card.color = cc.color(255,255,0);
- // }
- // this.selectedMagicCard = cardid;
- // }
- },
- clickCard(event) {
- let card = event.target;
- let cardid = card.getComponent("TrucoCard").cardId();
- if(card.belong == 1) {
- card.color = cc.color(255,255,255);
- if(card.beMagic == 1) {
- card.color = cc.color(0,255,0);
- }
- card.belong = -1;
- for(let i = 0; i < this.selectedCards.length; ++i) {
- if(this.selectedCards[i] == cardid) {
- this.selectedCards.splice(i, 1);
- return;
- }
- }
- return;
- }
- if(card.belong < 0) {
- if(this.selectedCards.length >= 10) {
- topTipMsg.showTopTipMsg("已选择10张牌");
- return;
- }
- card.belong = 1;
- card.color = cc.color(255,0,0);
- if(card.beMagic == 1) {
- card.color = cc.color(255,255,0);
- }
- this.selectedCards.push(cardid);
- }
- },
- });
|