#include "ZJH_GameScene.h" #include "ZJH_GamePlayer.h" #include "ZJH_GameLogic.h" #include "UserInfo.h" #include "MainScene.h" #include "MissionWeiXin.h" #include "DismissScene.h" #include "PopScene.h" #include "ActionEx.h" #include "JniFun.h" #include "SetScene.h" #include "ChatScene.h" #include "PlayerScene.h" #include "IpTipScene.h" #include "SimpleAudioEngine.h" using namespace ZJH_SPACE; bool ZJHGameScene::init() { if (!GameFrameBase::init()) { return false; } m_strGameRuleInfo = ""; m_cbGameStatus = ZJH_GS_FREE; m_bPrivateEnd = false; _lCellScore = 1; _wOperTimeOut = 1; _cbCurRound = 1; _cbMaxRound = 1; _lMaxChipScore = 1; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { _aryChairToViewID[i] = INVALID_CHAIR; } zeromemory(&m_PrivateRoomInfo, sizeof(CMD_GF_Private_Room_Info)); initNet(); initScene(); return true; } //进场动画完成回调; void ZJHGameScene::onEnterTransitionDidFinish() { GameFrameBase::onEnterTransitionDidFinish(); if (true == GAME_MUISCBG) { CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Games/ZJH/Sound/BackMusic.mp3", true); } // 暂时停了测试; #if CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); pAudio->stopBackgroundMusic(true); #endif // 录像模式; if (m_IsGameRecord) { StartRecord(ZJH_GAME_PLAYER); } else { // 增加游戏内事件处理; auto dispatcher = Director::getInstance()->getEventDispatcher(); dispatcher->addCustomEventListener(SHOW_PRIVATE_END, CC_CALLBACK_1(ZJHGameScene::onEventShowPrivate, this)); CGameServerItem* pGameServerItem = GameMission::g_pGameServerItem; CC_ASSERT(pGameServerItem != nullptr); if (pGameServerItem != nullptr) { m_kGameMission.SetServerItem(pGameServerItem); m_kGameMission.start(); } } } //场景退出; void ZJHGameScene::onExit() { GameFrameBase::onExit(); for (int i = 0; i < ZJH_GAME_PLAYER; i++) { SafeDelete(m_aryPlayer[i]); } auto dispatcher = Director::getInstance()->getEventDispatcher(); dispatcher->removeCustomEventListeners(SHOW_PRIVATE_END); } //场景初始化; void ZJHGameScene::initScene() { //根节点; m_rootNode = CSLoader::createNodeWithVisibleSize("Games/ZJH/GameTableScene.csb"); CC_ASSERT(m_rootNode != nullptr); this->addChild(m_rootNode, ZO_DEFAULT); // 公告; auto ImageSytem = (ImageView*)m_rootNode->getChildByName("ImgRoll"); CC_ASSERT(ImageSytem!=nullptr); SetSystemNode(ImageSytem); // 绑定界面元素; _MainPanel = static_cast(m_rootNode->getChildByName("MainPanel")); CC_ASSERT(_MainPanel != nullptr); // 房间信息; _imgRoomInfo = static_cast(_MainPanel->getChildByName("imgRoomInfo")); CC_ASSERT(_imgRoomInfo != nullptr); // 房间ID; _txtRoomID = static_cast(_imgRoomInfo->getChildByName("txtRoomID")); CC_ASSERT(_txtRoomID != nullptr); //比牌轮数文本; _txtCompareRound = static_cast(_imgRoomInfo->getChildByName("txtCompareRound")); CC_ASSERT(_txtCompareRound != nullptr); //看牌轮数文本; _txtLookCardRound = static_cast(_imgRoomInfo->getChildByName("txtLookCard")); CC_ASSERT(_txtLookCardRound != nullptr); //开牌轮数文本; _txtOpenCardRound = static_cast(_imgRoomInfo->getChildByName("txtOpenCardRound")); CC_ASSERT(_txtOpenCardRound != nullptr); // 局数; _txtJushu = static_cast(_imgRoomInfo->getChildByName("txtRoundNum")); CC_ASSERT(_txtJushu != nullptr); _txtJushu->setVisible(false); // 筹码面板; _ChipPanel = static_cast(_MainPanel->getChildByName("ChipPanel")); CC_ASSERT(_ChipPanel != nullptr); // 比牌面板; _ComparePanel = static_cast(m_rootNode->getChildByName("comparePanel")); CC_ASSERT(_ComparePanel != nullptr); _ComparePanel->setVisible(false); // 比牌动画; _armCompare = static_cast(_ComparePanel->getChildByName("armCompare")); CC_ASSERT(_armCompare != nullptr); _armCompare->setVisible(false); ArmatureAnimation* pAniCompare = _armCompare->getAnimation(); if (pAniCompare != nullptr) { pAniCompare->setMovementEventCallFunc(CC_CALLBACK_3(ZJHGameScene::movementEventCallFunc, this)); } // 左头像; _sprLeftHead = static_cast(_ComparePanel->getChildByName("sprLeftHead")); CC_ASSERT(_sprLeftHead != nullptr); // 左昵称; _txtLeftNickName = static_cast(_ComparePanel->getChildByName("txtLeftNickName")); CC_ASSERT(_txtLeftNickName != nullptr); // 左背牌; _sprLeftBackCard = static_cast(_ComparePanel->getChildByName("sprLeftBackCard")); CC_ASSERT(_sprLeftBackCard != nullptr); // 左输赢标志; _sprLeftFlag = static_cast(_ComparePanel->getChildByName("sprLeftFlag")); CC_ASSERT(_sprLeftFlag != nullptr); _sprLeftFlag->setVisible(false); // 左比牌失败动画; _armLeftLose = static_cast(_ComparePanel->getChildByName("armLeftLose")); CC_ASSERT(_armLeftLose != nullptr); _armLeftLose->setVisible(false); ArmatureAnimation* pAniLeftLose = _armLeftLose->getAnimation(); if (pAniLeftLose != nullptr) { pAniLeftLose->setMovementEventCallFunc(CC_CALLBACK_3(ZJHGameScene::movementEventCallFunc, this)); } // 右头像; _sprRightHead = static_cast(_ComparePanel->getChildByName("sprRightHead")); CC_ASSERT(_sprRightHead != nullptr); // 右昵称; _txtRightNickName = static_cast(_ComparePanel->getChildByName("txtRightNickName")); CC_ASSERT(_txtRightNickName != nullptr); // 右背牌; _sprRightBackCard = static_cast(_ComparePanel->getChildByName("sprRightBackCard")); CC_ASSERT(_sprRightBackCard != nullptr); // 右输赢标志; _sprRightFlag = static_cast(_ComparePanel->getChildByName("sprRightFlag")); CC_ASSERT(_sprRightFlag != nullptr); _sprRightFlag->setVisible(false); // 右比牌失败动画; _armRightLose = static_cast(_ComparePanel->getChildByName("armRightLose")); CC_ASSERT(_armRightLose != nullptr); _armRightLose->setVisible(false); ArmatureAnimation* pAniRightLose = _armRightLose->getAnimation(); if (pAniRightLose != nullptr) { pAniRightLose->setMovementEventCallFunc(CC_CALLBACK_3(ZJHGameScene::movementEventCallFunc, this)); } // 结束面板; _ResultPanel = static_cast(m_rootNode->getChildByName("resultPanel")); CC_ASSERT(_ResultPanel != nullptr); _ResultPanel->setVisible(false); // 胜负动画; _pArmatureResult = (Armature*)_ResultPanel->getChildByName("armaGameResult"); CC_ASSERT(_pArmatureResult != nullptr); _pArmatureResult->setVisible(false); // 准备按钮; _btnReady = static_cast(_ResultPanel->getChildByName("btnReady")); CC_ASSERT(_btnReady != nullptr); // 准备开始; _btnReady->addClickEventListener([=](Ref* pSender) { playBtnClickEffect(); SendUserReady(); ArmatureAnimation* pAniResult = _pArmatureResult->getAnimation(); if (pAniResult != nullptr) { pAniResult->stop(); } _pArmatureResult->setVisible(false); _ResultPanel->setVisible(false); }); // 查看总成绩按钮; _btnPrivateEnd = static_cast(_ResultPanel->getChildByName("btnPrivateEnd")); CC_ASSERT(_btnPrivateEnd != nullptr); _btnPrivateEnd->setVisible(false); _btnPrivateEnd->addClickEventListener([this](Ref*){ playBtnClickEffect(); _OpenResultScene->updateUIData(m_dwRoomID, &_aryResultItem, true); _OpenResultScene->setVisible(true); }); for (uint16 i = 0; i < ZJH_GAME_PLAYER; i++) { string strName = StringUtils::format("txtScoreChair_%d", i); _pTxtResultScore[i] = static_cast(_ResultPanel->getChildByName(strName)); CC_ASSERT(_pTxtResultScore[i]!=nullptr); _pTxtResultScore[i]->setString(""); strName = StringUtils::format("txtXiScoreChair_%d", i); _pTxtXiScore[i] = static_cast(_ResultPanel->getChildByName(strName)); CC_ASSERT(_pTxtXiScore[i] != nullptr); _pTxtXiScore[i]->setString(""); } // 按钮面板; _ButtonPanel = static_cast(_MainPanel->getChildByName("ButtonPanel")); CC_ASSERT(_ButtonPanel != nullptr); // 微信邀请按钮; _btnInvite = static_cast(_ButtonPanel->getChildByName("btnInvite")); CC_ASSERT(_btnInvite != nullptr); _btnInvite->setVisible(false); // 解散房间按钮; _btnDismiss = static_cast(_ButtonPanel->getChildByName("btnDismiss")); CC_ASSERT(_btnDismiss != nullptr); _btnDismiss->setVisible(false); //设置按钮; auto btnSetting = static_cast(_ButtonPanel->getChildByName("btnSetting")); CC_ASSERT(btnSetting != nullptr); btnSetting->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); TipNode* pNode = SetScene::create(); CC_ASSERT(pNode != nullptr); this->addChild(pNode, ZO_ANI); pNode->pushScene(); }); // 离开按钮; _btnLeave = static_cast(_ButtonPanel->getChildByName("btnLeave")); CC_ASSERT(_btnLeave != nullptr); //_btnLeave->setVisible(false); _btnLeave->addClickEventListener([=](Ref* pSender){ YSAudioEngine::Instance().playBtnClickEffect(); GamePlayer* pGamePlayer = getSelfGamePlayer(); auto callback_ok = [=](){ if (pGamePlayer != nullptr) { CMD_GR_UserStandUp request; memset(&request, 0, sizeof(request)); request.wTableID = pGamePlayer->GetTableID(); request.wChairID = pGamePlayer->GetChairID(); request.cbForceLeave = true; m_kGameMission.SendSocketData(MDM_GR_USER, SUB_GR_USER_STANDUP, &request, sizeof(request)); } this->runAction(Sequence::createWithTwoActions(DelayTime::create(0.2f), CallFunc::create([=]{ Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME); }))); }; std::string strPop = "您确定要离开房间吗?"; if (m_cbGameStatus != ZJH_GS_FREE) { strPop = "您正在游戏中,强行退出会被扣分,确定要强退吗?"; } PopScene::Instance().show(utility::a_u8(strPop), callback_ok, nullptr); }); // 语音按钮; _btnVoice = static_cast(_ButtonPanel->getChildByName("btnVoice")); CC_ASSERT(_btnVoice != nullptr); _btnVoice->addTouchEventListener(CC_CALLBACK_2(ZJHGameScene::OnButtonVoiceTouched, this)); // 聊天按钮; _btnChat = static_cast(_ButtonPanel->getChildByName("btnChat")); CC_ASSERT(_btnChat != nullptr); _btnChat->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); const std::vector& chatList = getShortChatList(); auto chatLayer = ChatLayer::create(chatList); CC_ASSERT(chatLayer != nullptr); this->addChild(chatLayer, ZO_ANI); chatLayer->pushScene(); }); // 开始按钮; _btnStartGame = static_cast(_ButtonPanel->getChildByName("btnStartGame")); CC_ASSERT(_btnStartGame != nullptr); _btnStartGame->setVisible(false); // 开始游戏; _btnStartGame->addClickEventListener([=](Ref* pSender) { playBtnClickEffect(); SendUserReady(); _btnStartGame->setEnabled(false); }); // 操作面板; _OperBtnsPanel = static_cast(_MainPanel->getChildByName("OperBtnsPanel")); CC_ASSERT(_OperBtnsPanel != nullptr); _OperBtnsPanel->setVisible(false); // 放弃按钮; _btnGiveUp = static_cast(_OperBtnsPanel->getChildByName("btnGiveUp")); CC_ASSERT(_btnGiveUp != nullptr); _btnGiveUp->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onGiveUpButtonClick, this)); // 比牌按钮; _btnCompare = static_cast(_OperBtnsPanel->getChildByName("btnCompare")); CC_ASSERT(_btnCompare != nullptr); _btnCompare->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onCompareButtonClick, this)); // 比牌筹码文本; _txtCompareChip = static_cast(_btnCompare->getChildByName("txtNum")); CC_ASSERT(_txtCompareChip != nullptr); // 加注按钮; _btnAddChip = static_cast(_OperBtnsPanel->getChildByName("btnAddChip")); CC_ASSERT(_btnAddChip != nullptr); _btnAddChip->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onAddChipButtonClick, this)); // 跟注按钮; _btnFollow = static_cast(_OperBtnsPanel->getChildByName("btnFollow")); CC_ASSERT(_btnFollow != nullptr); _btnFollow->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onFollowButtonClick, this)); // 跟注筹码文本; _txtFollowChip = static_cast(_btnFollow->getChildByName("txtNum")); CC_ASSERT(_txtFollowChip != nullptr); // 加注面板; _AddChipPanel = static_cast(_MainPanel->getChildByName("AddChipPanel")); CC_ASSERT(_AddChipPanel != nullptr); _AddChipPanel->setVisible(false); // 取消加注按钮; _btnAddCancel = static_cast(_AddChipPanel->getChildByName("btnAddCancel")); CC_ASSERT(_btnAddCancel != nullptr); _btnAddCancel->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onAddCancelButtonClick, this)); for (int i = 0; i < 4; i++) { std::string strName = StringUtils::format("btnAddChip%d", i+1); Button* btnAdd = static_cast(_AddChipPanel->getChildByName(strName)); CC_ASSERT(btnAdd != nullptr); btnAdd->setTag(i+2); btnAdd->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onAddChipBtnsClick, this)); _aryAddChip[i] = btnAdd; } // 摊牌; _txtTip = static_cast(_MainPanel->getChildByName("txtTip")); CC_ASSERT(_txtTip != nullptr); _txtTip->setVisible(true); _txtTip->setString(""); // 选择比牌玩家提示; _sprSelectUserTip = static_cast(_MainPanel->getChildByName("sprSelectUserTip")); CC_ASSERT(_sprSelectUserTip != nullptr); _sprSelectUserTip->setVisible(false); // 发牌位置; _ptSendCardPos = _MainPanel->getChildByName("imgCard")->getPosition(); // 桌面总筹码图片; _imgAllChips = static_cast(_MainPanel->getChildByName("imgAllChips")); CC_ASSERT(_imgAllChips!=nullptr); _imgAllChips->setVisible(false); // 桌面总筹码文本; _txtAllChips = static_cast(_imgAllChips->getChildByName("txtNum")); CC_ASSERT(_txtAllChips!=nullptr); // 语音标志; m_pVoiceNode = (Node*)m_rootNode->getChildByName("VoiceNode"); CC_ASSERT(m_pVoiceNode != nullptr); m_pVoiceNode->setVisible(false); for (int i = 0; i < ZJH_GAME_PLAYER; i++) { std::string strName = StringUtils::format("panelChair_%d", i); Layout* layout = static_cast(_MainPanel->getChildByName(strName)); CC_ASSERT(layout!=nullptr); m_aryPlayer[i] = new ZJHGamePlayer(i, layout); layout->addClickEventListener([i, this](Ref* pSender){ CC_ASSERT(pSender != nullptr); if (nullptr == pSender) return; if ((m_aryPlayer[i] != nullptr) && m_aryPlayer[i]->getUserItem(false) != nullptr) { PlayerScene* playerScene = PlayerScene::create(); playerScene->showPlayerInfo(m_aryPlayer[i]); this->addChild(playerScene, ZO_TRUSTEE); } }); m_aryPlayer[i]->setCompareClickCallback([this](uint16 wChairID){ // 选择比牌后把所有选择按钮隐藏; for (int j = 0; j < ZJH_GAME_PLAYER; j++) { if ((j != ZJH_VIEW_SELF_ID) && (_aryGamingStatus[j]!=ZJH_ST_GAMING_NULL)) { m_aryPlayer[j]->setCompareVisible(false); } } uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; uint16 wMyChairID = getSelfChairID(); if ((_wCurrentUser==wMyChairID) && (cbMyStatus == ZJH_ST_GAMING_HIDDEN || cbMyStatus == ZJH_ST_GAMING_LOOK)) { sendOperateMsg(ZJH_OPERATE_COMPARE_CARD, wChairID); } _sprSelectUserTip->setVisible(false); showOperatePanel(false, ZJH_OPERATE_PANEL); }); if (i==ZJH_VIEW_SELF_ID) { m_aryPlayer[i]->setLookCardClickCallback(CC_CALLBACK_1(ZJHGameScene::onLookCardButtonClick, this)); } } m_pLocalPlayer = m_aryPlayer[ZJH_VIEW_SELF_ID]; auto exitCallFunc = [=](Ref*){ auto callback = [=](){ onClickExitGameButton(nullptr); this->runAction(Sequence::createWithTwoActions(DelayTime::create(0.2f), CallFunc::create([=]{ Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME); }))); }; PopScene::Instance().show(utility::a_u8("您确定要退出游戏吗?"), callback, nullptr); }; // 邀请; _btnInvite->addClickEventListener(CC_CALLBACK_1(ZJHGameScene::onInviteButtonClick, this)); // 解散房间函数; auto callback = [this](){ onEventAgreeDismissRoom(true); }; _btnDismiss->addClickEventListener([=](Ref* pSender) { // 解散; playBtnClickEffect(); std::string strTip; if (0 == m_PrivateRoomInfo.dwPlayCout && false == m_PrivateRoomInfo.bStartGame) { strTip = "牌局开始前解散房间不扣房卡,是否解散?"; } else { strTip = "您确定要解散房间吗?"; } PopScene::Instance().show(utility::a_u8(strTip.c_str()), callback, nullptr); }); // 私人场结束面板; _OpenResultScene = ZJHOpenResultScene::create(); addChild(_OpenResultScene); _OpenResultScene->setVisible(false); //对手机返回键的监听 ; auto keyListener = EventListenerKeyboard::create(); //和回调函数绑定 ; keyListener->onKeyReleased = [=](EventKeyboard::KeyCode keyCode, Event * pEvent){ //返回值处理; if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE) { exitCallFunc(nullptr); } }; //添加到事件分发器中 ; _eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this); SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance(); pSpriteFrameCache->addSpriteFramesWithFile("Games/ZJH/Cards/PinLargeCard1.plist"); pSpriteFrameCache->addSpriteFramesWithFile("Games/ZJH/Cards/PinLargeCard2.plist"); loadShortChat("Games/DDZ/ShortChat/ChatInfo.json"); //重置场景; resetScene(); //重置数据; ResetAllData(); } //重置场景; void ZJHGameScene::resetScene(bool bAll/* = false*/) { //重置玩家UI; for (uint8 i = 0; i < ZJH_GAME_PLAYER; i++) { m_aryPlayer[i]->resetUI(bAll); } _ChipPanel->removeAllChildren(); _aryChipNode.clear(); _sprSelectUserTip->setVisible(false); _OperBtnsPanel->setVisible(false); _AddChipPanel->setVisible(false); _ResultPanel->setVisible(false); } //重置数据; void ZJHGameScene::resetData() { m_cbGameStatus = ZJH_GS_FREE; _wBankerUser = INVALID_CHAIR; _lCurChipScore = 0; _wCurrentUser = INVALID_CHAIR; _dwOperateCode = 0; _lTotalChipScore = 0; _bHasShowLookCard = false; _bComparingCard = false; _bGameEnd = false; zeromemory(&_cmdCompareCard, sizeof(_cmdCompareCard)); zeromemory(&_cmdGameEnd, sizeof(_cmdGameEnd)); for (uint8 i = 0; i < ZJH_GAME_PLAYER; i++) { _aryGamingStatus[i] = ZJH_ST_GAMING_NULL; _aryUserChipScore[i] = 0; } zeromemory(_aryHandCardData, sizeof(_aryHandCardData)); } //重置数据(相当于玩家离开); void ZJHGameScene::ResetAllData() { resetScene(); resetData(); } //重置桌子; void ZJHGameScene::ResetTable() { resetScene(true); resetData(); } //获取快捷语音文件路径; const std::string ZJHGameScene::getShortChatSoundPath(uint8 cbGender, int nIndex) { // 短语; std::string strFilePath = "Games/DDZ/ShortChat/"; if (cbGender == enMan) { strFilePath += StringUtils::format("man/%d.mp3", nIndex); } else { strFilePath += StringUtils::format("woman/%d.mp3", nIndex); } return strFilePath; } //绑定网络消息; void ZJHGameScene::initNet() { addNetCBDefine(ZJH_SUB_S_GAME_START, this, ZJHGameScene::onSubGameStart); addNetCBDefine(ZJH_SUB_S_START_CHIP, this, ZJHGameScene::onSubStartChip); addNetCBDefine(ZJH_SUB_S_GIVE_UP, this, ZJHGameScene::onSubGiveUp); addNetCBDefine(ZJH_SUB_S_USER_CHIP, this, ZJHGameScene::onSubUserChip); addNetCBDefine(ZJH_SUB_S_LOOK_CARD, this, ZJHGameScene::onSubLookCard); addNetCBDefine(ZJH_SUB_S_COMPARE_CARD, this, ZJHGameScene::onSubCompareCard); addNetCBDefine(ZJH_SUB_S_GAME_END, this, ZJHGameScene::onSubGameEnd); addNetCBDefine(ZJH_SUB_S_CHEAT_CARD, this, ZJHGameScene::onSubCheatCard); } bool ZJHGameScene::OnEventSceneMessage(uint8 cbGameStatus, bool bLookonUser, void* pData, int nDataSize) { m_cbGameStatus = cbGameStatus; switch (cbGameStatus) { case ZJH_GS_FREE: { return onGameSceneFree(pData, nDataSize); } case ZJH_GS_SEND_CARD: { return onGameSceneSendCard(pData, nDataSize); } case ZJH_GS_PLAYING: { return onGameScenePlaying(pData, nDataSize); } default: break; } return true; } //恢复空闭场景; bool ZJHGameScene::onGameSceneFree(void* pData, int nDataSize) { //校验数据; CC_ASSERT(nDataSize == sizeof(ZJH_CMD_S_StatusFree)); ZJH_CMD_S_StatusFree* pStatusFree = (ZJH_CMD_S_StatusFree*)pData; initStatusFree(pStatusFree); return true; } //发牌场景; bool ZJHGameScene::onGameSceneSendCard(void* pData, int nDataSize) { //校验数据; CC_ASSERT(nDataSize == sizeof(ZJH_CMD_S_StatusSendCard)); ZJH_CMD_S_StatusSendCard* pStatusSend = (ZJH_CMD_S_StatusSendCard*)pData; initStatusFree(&pStatusSend->stBase); _wBankerUser = pStatusSend->wBankerUser; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { uint16 wViewID = SwitchViewChairID(i); _aryGamingStatus[wViewID] = pStatusSend->aryGamingStatus[i]; _aryUserChipScore[wViewID] = pStatusSend->aryUserChipScore[i]; } uint8 cbUserStatus = m_pLocalPlayer->GetUserStatus(); if (pStatusSend->bSendOver && cbUserStatus == US_PLAYING) { sendSendCardOverMsg(); } return true; } //游戏中场景; bool ZJHGameScene::onGameScenePlaying(void* pData, int nDataSize) { //校验数据; CC_ASSERT(nDataSize == sizeof(ZJH_CMD_S_StatusPlay)); ZJH_CMD_S_StatusPlay* pStatusPlay = (ZJH_CMD_S_StatusPlay*)pData; initStatusFree(&pStatusPlay->stBase); _wBankerUser = pStatusPlay->wBankerUser; _wCurrentUser = pStatusPlay->wCurrentUser; memcpy(_aryHandCardData, pStatusPlay->aryHandCardData, sizeof(_aryHandCardData)); uint16 wMyChairID = getSelfChairID(); CC_ASSERT(wMyChairIDaryGamingStatus[i]; _aryGamingStatus[wViewID] = cbGamingStatus; _aryUserChipScore[wViewID] = pStatusPlay->aryUserChipScore[i]; if (cbGamingStatus != ZJH_ST_GAMING_NULL) { ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; CC_ASSERT(pPlayer!=nullptr); // 显示背牌和状态; pPlayer->showBackCard(); pPlayer->showHandStatus(cbGamingStatus); // 显示玩家已下注筹码; pPlayer->setAddChip(_lCurChipScore); pPlayer->setAllChip(_aryUserChipScore[wViewID]); if (wMyChairID == i) { pPlayer->showCard(_aryHandCardData); if (ZJH_ST_GAMING_HIDDEN == cbGamingStatus) { pPlayer->setLookCardVisible(true); } } playChipAni(wViewID, _aryUserChipScore[wViewID]); _lTotalChipScore += _aryUserChipScore[wViewID]; } } setTotalChipNumber(_lTotalChipScore); ZJHChipInfo mChipInfo; mChipInfo.cbCurRound = pStatusPlay->stBase.cbCurRound; mChipInfo.wCurrentUser = pStatusPlay->wCurrentUser; mChipInfo.lCurChipScore = pStatusPlay->stBase.lCurChipScore; mChipInfo.dwOperateCode = pStatusPlay->dwOperateCode; procChipInfo(INVALID_CHAIR, &mChipInfo); return true; } void ZJHGameScene::initStatusFree(ZJHStatusBase* pStatusBase) { _lCellScore = pStatusBase->lCellScore; _cbCurRound = pStatusBase->cbCurRound; _cbMaxRound = pStatusBase->cbMaxRound; _lCurChipScore = pStatusBase->lCurChipScore; _lMaxChipScore = pStatusBase->lMaxChipScore; _wOperTimeOut = pStatusBase->wOperTimeOut; } void ZJHGameScene::onSubGameStart(const void * pBuffer, uint16 wDataSize) { //校验数据; CC_ASSERT(wDataSize == sizeof(ZJH_CMD_S_GameStart)); ZJH_CMD_S_GameStart* pGameStart = (ZJH_CMD_S_GameStart*)pBuffer; //重置数据; ResetAllData(); m_cbGameStatus = ZJH_GS_PLAYING; _cbCurRound = pGameStart->cbCurRound; _wBankerUser = pGameStart->wBankerUser; _lCurChipScore = pGameStart->lCurChipScore; for (uint8 i = 0; i < ZJH_GAME_PLAYER; i++) { uint16 wViewID = SwitchViewChairID(i); _aryGamingStatus[wViewID] = pGameStart->aryGamingStatus[i]; _aryUserChipScore[wViewID] = pGameStart->aryUserChipScore[i]; if (ZJH_ST_GAMING_HIDDEN == _aryGamingStatus[wViewID]) { m_aryPlayer[wViewID]->setAddChip(0); m_aryPlayer[wViewID]->setAllChip(_aryUserChipScore[wViewID]); playChipAni(wViewID, _aryUserChipScore[wViewID]); _lTotalChipScore += _aryUserChipScore[wViewID]; } } setTotalChipNumber(_lTotalChipScore); startSendCardAni(); // 隐藏同IP显示; IpTipScene::Instance().hide(); } //开始下注; void ZJHGameScene::onSubStartChip(const void * pBuffer, uint16 wDataSize) { //校验数据; CC_ASSERT(wDataSize == sizeof(ZJH_CMD_S_StartChip)); ZJH_CMD_S_StartChip* pStartChip = (ZJH_CMD_S_StartChip*)pBuffer; procChipInfo(INVALID_CHAIR, pStartChip); } //放弃; void ZJHGameScene::onSubGiveUp(const void * pBuffer, uint16 wDataSize) { CC_ASSERT(sizeof(ZJH_CMD_S_GiveUp) == wDataSize); ZJH_CMD_S_GiveUp* pGiveUp = (ZJH_CMD_S_GiveUp*)pBuffer; uint16 wViewID = SwitchViewChairID(pGiveUp->wGiveUpUser); ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; _aryGamingStatus[wViewID] = ZJH_ST_GAMING_GIVEUP; pPlayer->showHandStatus(ZJH_ST_GAMING_GIVEUP); if (ZJH_VIEW_SELF_ID == wViewID) { pPlayer->setLookCardVisible(false); for (uint16 i = 0; i < ZJH_GAME_PLAYER; i++) { if (pGiveUp->wGiveUpUser == i) { continue; } uint16 wViewID = SwitchViewChairID(i); uint8 cbPlayerStatus = _aryGamingStatus[wViewID]; if ((cbPlayerStatus == ZJH_ST_GAMING_HIDDEN) || (cbPlayerStatus == ZJH_ST_GAMING_LOOK)) { m_aryPlayer[wViewID]->setCompareVisible(false); } } _sprSelectUserTip->setVisible(false); } procChipInfo(wViewID, &pGiveUp->stChipInfo); playEffect("GiveUp"); playEffectEx(pPlayer->GetGender(), "fangqi"); } //加注结果; void ZJHGameScene::onSubUserChip(const void * pBuffer, uint16 wDataSize) { CC_ASSERT(sizeof(ZJH_CMD_S_ChipScore) == wDataSize); ZJH_CMD_S_ChipScore* pChipScore = (ZJH_CMD_S_ChipScore*)pBuffer; uint16 wViewID = SwitchViewChairID(pChipScore->wChipUser); ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; pPlayer->showOperateTip(pChipScore->dwOperateCode, pChipScore->lChipScore); pPlayer->setAddChip(pChipScore->lChipScore); pPlayer->setAllChip(pChipScore->lTtlChipScore); playChipAni(wViewID, pChipScore->lChipScore); procChipInfo(wViewID, &pChipScore->stChipInfo); _lTotalChipScore += pChipScore->lChipScore; setTotalChipNumber(_lTotalChipScore); if ((pChipScore->dwOperateCode&ZJH_OPERATE_FOLLOW)>0) { playEffect("FollowChip"); playEffectEx(pPlayer->GetGender(), "genzhu_0"); } else { playEffect("AddChip"); playEffectEx(pPlayer->GetGender(), "jiazhu"); } } //看牌; void ZJHGameScene::onSubLookCard(const void * pBuffer, uint16 wDataSize) { CC_ASSERT(sizeof(ZJH_CMD_S_LookCard) == wDataSize); ZJH_CMD_S_LookCard* pLookCard = (ZJH_CMD_S_LookCard*)pBuffer; uint16 wViewID = SwitchViewChairID(pLookCard->wLookUser); ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; _aryGamingStatus[wViewID] = ZJH_ST_GAMING_LOOK; if (ZJH_VIEW_SELF_ID==wViewID) { pPlayer->showCard(pLookCard->aryCardData); pPlayer->setLookCardVisible(false); uint8 cbCardType = m_GameLogic.GetCardType(pLookCard->aryCardData, ZJH_MAX_COUNT); pPlayer->showCardTypeEx(cbCardType); uint16 wSelfChairID = getSelfChairID(); if (_wCurrentUser == wSelfChairID) { procChipInfo(wViewID, &pLookCard->stChipInfo); } } else { pPlayer->showHandStatus(ZJH_ST_GAMING_LOOK); } playEffect("LookCard"); playEffectEx(pPlayer->GetGender(), "kanpai"); } //比牌结果; void ZJHGameScene::onSubCompareCard(const void * pBuffer, uint16 wDataSize) { CC_ASSERT(wDataSize == sizeof(ZJH_CMD_S_CompareCard)); ZJH_CMD_S_CompareCard* pCompare = (ZJH_CMD_S_CompareCard*)pBuffer; _bComparingCard = true; memcpy(&_cmdCompareCard, pCompare, sizeof(ZJH_CMD_S_CompareCard)); uint16 wViewID = SwitchViewChairID(pCompare->wChairID); uint16 wCompareViewID = SwitchViewChairID(pCompare->wCompareUser); ZJHGamePlayer* pOperPlayer = m_aryPlayer[wViewID]; pOperPlayer->closeClock(); pOperPlayer->showOperateTip(ZJH_OPERATE_COMPARE_CARD, pCompare->lChipScore); pOperPlayer->setAddChip(pCompare->lChipScore); pOperPlayer->setAllChip(pCompare->lTtlChipScore); playChipAni(wViewID, pCompare->lChipScore); _lTotalChipScore += pCompare->lChipScore; setTotalChipNumber(_lTotalChipScore); _txtTip->setString(""); playEffectEx(pOperPlayer->GetGender(), "bipai"); _ComparePanel->setVisible(true); _armCompare->setVisible(true); ArmatureAnimation* pAniCompare = _armCompare->getAnimation(); if (pAniCompare != nullptr) { pAniCompare->play("Duel"); } // 设置比牌左面玩家信息; Sprite* sprLeftHead = pOperPlayer->getHeadSprite(); SpriteFrame* sprLeftFrame = sprLeftHead->getSpriteFrame(); _sprLeftHead->setSpriteFrame(sprLeftFrame->clone()); _txtLeftNickName->setString(pOperPlayer->GetNickName()); _sprLeftBackCard->setColor(Color3B(0xFF, 0xFF, 0xFF)); // 设置比牌右面玩家信息; ZJHGamePlayer* pComparePlayer = m_aryPlayer[wCompareViewID]; Sprite* sprRightHead = pComparePlayer->getHeadSprite(); SpriteFrame* sprRightFrame = sprRightHead->getSpriteFrame(); _sprRightHead->setSpriteFrame(sprRightFrame->clone()); _txtRightNickName->setString(pComparePlayer->GetNickName()); _sprRightBackCard->setColor(Color3B(0xFF, 0xFF, 0xFF)); auto callFunc = CallFunc::create([this]{ if (_cmdCompareCard.bWin) { ArmatureAnimation* pAniRightLose = _armRightLose->getAnimation(); if (pAniRightLose != nullptr) { pAniRightLose->play("lose"); } _armRightLose->setVisible(true); } else { ArmatureAnimation* pAniLeftLose = _armLeftLose->getAnimation(); if (pAniLeftLose != nullptr) { pAniLeftLose->play("lose"); } _armLeftLose->setVisible(true); } }); auto actSeq = Sequence::create(DelayTime::create(1.5f), callFunc, nullptr); _ComparePanel->runAction(actSeq); } //发牌结束; void ZJHGameScene::sendSendCardOverMsg() { SendSocketData(ZJH_SUB_C_SEND_OVER); } //开牌操作; void ZJHGameScene::sendOperateMsg(uint32 dwCode, int lData/* = 0*/) { ZJH_CMD_C_UserOperate mUserOper; mUserOper.dwCode = dwCode; mUserOper.lData = lData; SendSocketData(ZJH_SUB_C_USER_OPERATE, &mUserOper, sizeof(ZJH_CMD_C_UserOperate)); } // 显示操作面板; void ZJHGameScene::showOperatePanel(bool bShow, uint8 cbPanelType) { if (bShow) { if (ZJH_OPERATE_PANEL==cbPanelType) { _AddChipPanel->setVisible(false); int nCompareChip = _lCurChipScore; // 已看牌则加倍; if (_aryGamingStatus[ZJH_VIEW_SELF_ID] == ZJH_ST_GAMING_LOOK) { nCompareChip *= 2; } std::string strCompare = StringUtils::format("%d", nCompareChip); // 是否可以放弃; bool bEnabled = (_dwOperateCode&ZJH_OPERATE_GIVEUP) > 0; _btnGiveUp->setEnabled(bEnabled); // 是否可以跟注; bEnabled = (_dwOperateCode&ZJH_OPERATE_FOLLOW) > 0; _btnFollow->setEnabled(bEnabled); _txtFollowChip->setString(strCompare); // 是否可以加注; bEnabled = (_dwOperateCode&ZJH_OPERATE_ADD_CHIP) > 0; _btnAddChip->setEnabled(bEnabled); // 如果可以比牌; bEnabled = (_dwOperateCode&ZJH_OPERATE_COMPARE_CARD) > 0; _btnCompare->setEnabled(bEnabled); _txtCompareChip->setString(strCompare); Size sizeOper = _OperBtnsPanel->getContentSize(); _OperBtnsPanel->setPositionY(-sizeOper.height / 2); _OperBtnsPanel->setVisible(true); auto actMove = Speed::create(MoveBy::create(0.5f, Vec2(0, sizeOper.height)), 2.0f); _OperBtnsPanel->runAction(actMove); } else if (ZJH_ADD_CHIP_PANEL == cbPanelType) { _OperBtnsPanel->setVisible(false); for (int i = 0; i < 4; i++) { bool bEnabled = (_lCurChipScore < (i+2)); _aryAddChip[i]->setEnabled(bEnabled); } Size sizeAdd = _AddChipPanel->getContentSize(); _AddChipPanel->setPositionY(-sizeAdd.height / 2); _AddChipPanel->setVisible(true); auto actMove = Speed::create(MoveBy::create(0.5f, Vec2(0, sizeAdd.height)), 2.0f); _AddChipPanel->runAction(actMove); } } else { _OperBtnsPanel->setVisible(false); _AddChipPanel->setVisible(false); } } // 设置桌面总筹码数; void ZJHGameScene::setTotalChipNumber(int nTotalNumber) { _imgAllChips->setVisible(true); _txtAllChips->setString(StringUtils::format("%d", nTotalNumber)); } //点击放弃按钮; void ZJHGameScene::onGiveUpButtonClick(Ref* pSender) { playBtnClickEffect(); auto callback = [=](){ if (_aryGamingStatus[ZJH_VIEW_SELF_ID] != ZJH_ST_GAMING_NULL) { showOperatePanel(false); sendOperateMsg(ZJH_OPERATE_GIVEUP); } }; PopScene::Instance().show(utility::a_u8("放弃后,只输掉当前下注积分,是否确定放弃?"), callback, nullptr); } //点击比牌按钮; void ZJHGameScene::onCompareButtonClick(Ref* pSender) { playBtnClickEffect(); uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; uint16 wSelfChairID = getSelfChairID(); if (_wCurrentUser==wSelfChairID || (cbMyStatus == ZJH_ST_GAMING_HIDDEN || cbMyStatus == ZJH_ST_GAMING_LOOK)) { uint16 wLastPlayerChairID = INVALID_CHAIR; std::vector aryPlayer; for (uint16 i = 0; i < ZJH_GAME_PLAYER; i++) { uint16 wViewID = SwitchViewChairID(i); if (ZJH_VIEW_SELF_ID == wViewID) { continue; } uint8 cbPlayerStatus = _aryGamingStatus[wViewID]; if ((cbPlayerStatus == ZJH_ST_GAMING_HIDDEN) || (cbPlayerStatus == ZJH_ST_GAMING_LOOK)) { //m_aryPlayer[wViewID]->setCompareVisible(true); aryPlayer.push_back(wViewID); wLastPlayerChairID = i; } } size_t nLength = aryPlayer.size(); if ((1 == nLength) && (wLastPlayerChairID != INVALID_CHAIR)) { sendOperateMsg(ZJH_OPERATE_COMPARE_CARD, wLastPlayerChairID); showOperatePanel(false, ZJH_OPERATE_PANEL); } else { for (size_t i = 0; i < nLength; i++) { uint16 wViewID = aryPlayer.at(i); m_aryPlayer[wViewID]->setCompareVisible(true); } _sprSelectUserTip->setVisible(true); } } } //点击加注按钮; void ZJHGameScene::onAddChipButtonClick(Ref* pSender) { uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; uint16 wSelfChairID = getSelfChairID(); if (_wCurrentUser == wSelfChairID && (cbMyStatus == ZJH_ST_GAMING_HIDDEN || cbMyStatus == ZJH_ST_GAMING_LOOK)) { showOperatePanel(true, ZJH_ADD_CHIP_PANEL); } } //点击跟注按钮; void ZJHGameScene::onFollowButtonClick(Ref* pSender) { uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; uint16 wSelfChairID = getSelfChairID(); if (_wCurrentUser == wSelfChairID && (cbMyStatus == ZJH_ST_GAMING_HIDDEN || cbMyStatus == ZJH_ST_GAMING_LOOK)) { sendOperateMsg(ZJH_OPERATE_FOLLOW); } } //点击取消按钮; void ZJHGameScene::onAddCancelButtonClick(Ref* pSender) { showOperatePanel(true, ZJH_OPERATE_PANEL); } //点击加注按钮; void ZJHGameScene::onAddChipBtnsClick(Ref* pSender) { Button* pButton = (Button*)pSender; int nChipScore = pButton->getTag(); if (nChipScore <= _lMaxChipScore && nChipScore > _lCurChipScore ) { uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; uint16 wSelfChairID = getSelfChairID(); if (_wCurrentUser == wSelfChairID && (cbMyStatus == ZJH_ST_GAMING_HIDDEN || cbMyStatus == ZJH_ST_GAMING_LOOK)) { sendOperateMsg(ZJH_OPERATE_ADD_CHIP, nChipScore); } } } //点击看牌按钮; void ZJHGameScene::onLookCardButtonClick(Ref* pSender) { uint8 cbMyStatus = _aryGamingStatus[ZJH_VIEW_SELF_ID]; if (cbMyStatus == ZJH_ST_GAMING_HIDDEN ) { sendOperateMsg(ZJH_OPERATE_LOOK); } } //邀请按钮被点击; void ZJHGameScene::onInviteButtonClick(Ref* pSender) { playBtnClickEffect(); //房间号:【857252】8局,分庄闲,爬楼,回头一笑,同一首歌。 std::string strText = StringUtils::format("房间号:[%u] %d 局, %s.", m_PrivateRoomInfo.dwRoomNum, m_PrivateRoomInfo.dwPlayTotal, m_strGameRuleInfo.c_str()); std::string strFriendUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_FRIEND_RUL); std::string strUrl = StringUtils::format("%s?param=%d", strFriendUrl.c_str(), m_PrivateRoomInfo.dwRoomNum); MissionWeiXin::Instance().shareUrlWeiXin(strUrl, "炸金花", strText); //SelectShareScene::Instance().shareRoomInfo(strUrl, utility::a_u8("炸金花"), strText, 0); } // 开始发牌; void ZJHGameScene::startSendCardAni() { // 发牌动画; float fDelayTime = playSendCardAni() + 0.1f; uint8 cbUserStatus = m_pLocalPlayer->GetUserStatus(); if (cbUserStatus == US_PLAYING) { auto callback = [=]() { //if (ZJH_ST_GAMING_HIDDEN==_aryGamingStatus[ZJH_VIEW_SELF_ID]) //{ // m_aryPlayer[ZJH_VIEW_SELF_ID]->setLookCardVisible(true); //} sendSendCardOverMsg(); }; runAction(Sequence::create(DelayTime::create(fDelayTime), CallFunc::create(callback), nullptr)); } } // 动画回调; void ZJHGameScene::movementEventCallFunc(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID) { // 播放完成; if (movementType == cocostudio::COMPLETE) { if ("Duel" == movementID) { compareCardEnd(); } else if ("lose" == movementID) { if (_cmdCompareCard.bWin) { _sprRightBackCard->setColor(Color3B(0x7F, 0x7F, 0x7F)); _sprRightFlag->setVisible(true); _sprRightFlag->setTexture("Games/ZJH/Table/lose.png"); _sprLeftFlag->setVisible(true); _sprLeftFlag->setTexture("Games/ZJH/Table/win.png"); } else { _sprLeftBackCard->setColor(Color3B(0x7F, 0x7F, 0x7F)); _sprRightFlag->setVisible(true); _sprRightFlag->setTexture("Games/ZJH/Table/win.png"); _sprLeftFlag->setVisible(true); _sprLeftFlag->setTexture("Games/ZJH/Table/lose.png"); } _ComparePanel->runAction(Sequence::create(DelayTime::create(0.8f), Hide::create(), nullptr)); } } } //游戏结束; void ZJHGameScene::onSubGameEnd(const void * pBuffer, uint16 wDataSize) { //校验数据; CC_ASSERT(wDataSize == sizeof(ZJH_CMD_S_GameEnd)); ZJH_CMD_S_GameEnd* pGameEnd = (ZJH_CMD_S_GameEnd*)pBuffer; _bGameEnd = true; // 保存椅子号对应的视图ID,防止私人场结束自已的位置变为INVALID; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { uint16 wViewID = SwitchViewChairID(i); _aryChairToViewID[i] = wViewID; } if (_bComparingCard) { memcpy(&_cmdGameEnd, pGameEnd, sizeof(_cmdGameEnd)); } else { procGameEnd(pGameEnd); } } //作弊消息; void ZJHGameScene::onSubCheatCard(const void * pBuffer, uint16 wDataSize) { //校验数据; CC_ASSERT(wDataSize == sizeof(ZJH_CMD_S_CheatCardInfo)); ZJH_CMD_S_CheatCardInfo* pCheatCard = (ZJH_CMD_S_CheatCardInfo*)pBuffer; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { uint16 wViewID = SwitchViewChairID(i); CC_ASSERT(wViewID != INVALID_CHAIR); uint8 cbGamingStatus = pCheatCard->aryGamingStatus[i]; if (cbGamingStatus != ZJH_ST_GAMING_NULL && cbGamingStatus != ZJH_ST_GAMING_GIVEUP) { ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; pPlayer->showCard(pCheatCard->aryHandCardData[i]); uint8 cbCardType = m_GameLogic.GetCardType(pCheatCard->aryHandCardData[i], ZJH_MAX_COUNT); pPlayer->showCardType(cbCardType); } } } //筹码信息处理; void ZJHGameScene::procChipInfo(uint16 wLastViewID, ZJHChipInfo* pChipInfo) { if (_cbCurRound != pChipInfo->cbCurRound) { _cbCurRound = pChipInfo->cbCurRound; _txtOpenCardRound->setString(StringUtils::format("%d/%d", _cbCurRound, _cbMaxRound)); } _wCurrentUser = pChipInfo->wCurrentUser; _lCurChipScore = pChipInfo->lCurChipScore; _dwOperateCode = pChipInfo->dwOperateCode; if (ZJH_VIEW_SELF_ID == wLastViewID) { showOperatePanel(false, ZJH_OPERATE_PANEL); } // 关闭上一个玩家闹钟; if ( wLastViewID < ZJH_GAME_PLAYER ) { m_aryPlayer[wLastViewID]->closeClock(); } uint16 wMyChairID = getSelfChairID(); if (_wCurrentUser == wMyChairID) { showOperatePanel(true, ZJH_OPERATE_PANEL); } // 开始当前玩家闹钟; uint16 wCurViewID = SwitchViewChairID(_wCurrentUser); if (wCurViewID< ZJH_GAME_PLAYER) { m_aryPlayer[wCurViewID]->openClock(_wOperTimeOut); } if (!_bHasShowLookCard && (_cbCurRound>_cbMinLookRound) && (ZJH_ST_GAMING_HIDDEN == _aryGamingStatus[ZJH_VIEW_SELF_ID])) { m_aryPlayer[ZJH_VIEW_SELF_ID]->setLookCardVisible(true); _bHasShowLookCard = true; } } //游戏结束处理; void ZJHGameScene::procGameEnd(ZJH_CMD_S_GameEnd* pGameEnd) { _txtTip->setString(""); uint16 wSelfChairID = getSelfChairID(); SCORE lMyResultScore = pGameEnd->aryGameScore[wSelfChairID]; if (pGameEnd->isPrivateEnd) { _btnReady->setVisible(false); _btnPrivateEnd->setVisible(true); } else { _btnReady->setVisible(true); _btnPrivateEnd->setVisible(false); } _ResultPanel->setVisible(true); ArmatureAnimation* pAniResult = _pArmatureResult->getAnimation(); if (pAniResult != nullptr) { if (lMyResultScore > 0) { pAniResult->play("Win", -1, 0); playEffect("Win"); } else if (lMyResultScore < 0) { pAniResult->play("Lose", -1, 0); playEffect("Loss"); } else { pAniResult->play("Draw", -1, 0); } _pArmatureResult->setVisible(true); } // 隐藏自已看牌按钮; m_aryPlayer[ZJH_VIEW_SELF_ID]->setLookCardVisible(false); uint16 wWinChairID = INVALID_CHAIR; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { //uint16 wViewID = SwitchViewChairID(i); uint16 wViewID = _aryChairToViewID[i]; CC_ASSERT(wViewID!=INVALID_CHAIR); uint8 cbGamingStatus = pGameEnd->aryGamingStatus[i]; if (cbGamingStatus != ZJH_ST_GAMING_NULL) { ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; pPlayer->hideHandStatus(); pPlayer->hideCardTypeEx(); pPlayer->closeClock(); if (ZJH_ST_GAMING_GIVEUP==cbGamingStatus) { if (wSelfChairID==i) { pPlayer->showCard(pGameEnd->aryHandCardData[i]); } pPlayer->showHandStatus(cbGamingStatus); } else { pPlayer->showCard(pGameEnd->aryHandCardData[i]); pPlayer->showCardType(pGameEnd->aryCardType[i]); } playResultScoreAni(wViewID, pGameEnd->aryGameScore[i]); playXiScoreAni(wViewID, pGameEnd->aryXiScore[i]); if (pGameEnd->aryGameScore[i]>0) { wWinChairID = i; } } } if (INVALID_CHAIR != wWinChairID) { //uint16 wWinViewID = SwitchViewChairID(wWinChairID); uint16 wWinViewID = _aryChairToViewID[wWinChairID]; CC_ASSERT(wWinViewID != INVALID_CHAIR); const Vec2 ptHeadPos = m_aryPlayer[wWinViewID]->getHeadPos(); //float endPosX = ptHeadPos.x - _ChipPanel->getPositionX(); //float endPosY = ptHeadPos.y - _ChipPanel->getPositionY(); Vec2 ptPos = _ChipPanel->convertToNodeSpace(ptHeadPos); size_t nCount = _aryChipNode.size(); for (size_t i = 0; i < nCount; i++) { ZJHChipNode* pChipNode = _aryChipNode.at(i); Action* act = Sequence::create(MoveTo::create(0.3f, ptPos), RemoveSelf::create(), nullptr); pChipNode->runAction(act); } } m_cbGameStatus = ZJH_GS_FREE; } //比牌结束; void ZJHGameScene::compareCardEnd() { _ComparePanel->stopAllActions(); _ComparePanel->setVisible(false); // 停止比牌动画; ArmatureAnimation* pAniCompare = _armCompare->getAnimation(); if (pAniCompare != nullptr) { pAniCompare->stop(); } _armCompare->setVisible(false); // 停止左侧玩家比牌失败动画; ArmatureAnimation* pAniLeftLose = _armLeftLose->getAnimation(); if (pAniLeftLose != nullptr) { pAniLeftLose->stop(); } _sprLeftFlag->setVisible(false); _armLeftLose->setVisible(false); // 停止右侧玩家比牌失败动画; ArmatureAnimation* pAniRightLose = _armRightLose->getAnimation(); if (pAniRightLose != nullptr) { pAniRightLose->stop(); } _sprRightFlag->setVisible(false); _armRightLose->setVisible(false); uint16 wViewID = INVALID_CHAIR; uint16 wCompareViewID = INVALID_CHAIR; if (_bGameEnd) { wViewID = _aryChairToViewID[_cmdCompareCard.wChairID]; wCompareViewID = _aryChairToViewID[_cmdCompareCard.wCompareUser]; } else { wViewID = SwitchViewChairID(_cmdCompareCard.wChairID); wCompareViewID = SwitchViewChairID(_cmdCompareCard.wCompareUser); } CC_ASSERT((wViewID != INVALID_CHAIR) && (wCompareViewID != INVALID_CHAIR)); if (_cmdCompareCard.bWin) { _aryGamingStatus[wCompareViewID] = ZJH_ST_GAMING_LOSE; m_aryPlayer[wCompareViewID]->showHandStatus(ZJH_ST_GAMING_LOSE); if (ZJH_VIEW_SELF_ID == wCompareViewID) { m_aryPlayer[wCompareViewID]->setLookCardVisible(false); } } else { _aryGamingStatus[wViewID] = ZJH_ST_GAMING_LOSE; m_aryPlayer[wViewID]->showHandStatus(ZJH_ST_GAMING_LOSE); if (ZJH_VIEW_SELF_ID == wViewID) { m_aryPlayer[wViewID]->setLookCardVisible(false); } } _bComparingCard = false; if (_bGameEnd) { procGameEnd(&_cmdGameEnd); } else { procChipInfo(wViewID, &_cmdCompareCard.stChipInfo); } } //用户进入; void ZJHGameScene::OnEventUserEnter(GamePlayer * pPlayer) { if (pPlayer->GetChairID() == getSelfChairID()) { //更新准备按钮状态; uint8 cbUserStatus = pPlayer->GetUserStatus(); if (cbUserStatus >= US_READY || m_cbGameStatus>ZJH_GS_FREE) { _btnStartGame->setEnabled(false); //_ResultPanel->setVisible(false); } else { //_btnStartGame->setVisible(true); } } } //玩家状态改变; void ZJHGameScene::OnEventUserStatus(GamePlayer * pPlayer) { OnEventUserEnter(pPlayer); } // 发牌动画; float ZJHGameScene::playSendCardAni() { float fDelaySendTime = 0.1f; auto pSpriteFrameCache = SpriteFrameCache::getInstance(); for (int i = 0; i < ZJH_MAX_COUNT; i++) { for (int j = 0; j < ZJH_GAME_PLAYER; j++) { uint16 wViewID = SwitchViewChairID(j); if (ZJH_ST_GAMING_HIDDEN==_aryGamingStatus[wViewID]) { std::string strName = StringUtils::format("SendCardSprite%d", j); auto pCardSprite = Sprite::createWithSpriteFrameName("L_0x00.png"); CC_ASSERT(pCardSprite!=nullptr); int nTag = i * 100 + j; pCardSprite->setTag(nTag); pCardSprite->setName(strName); pCardSprite->setPosition(_ptSendCardPos); _MainPanel->addChild(pCardSprite); CC_ASSERT(wViewID < ZJH_GAME_PLAYER); if (wViewID < ZJH_GAME_PLAYER) { moveSentCardSprite(pCardSprite, wViewID, i, fDelaySendTime); } fDelaySendTime += 0.06f; } } } return fDelaySendTime; } void ZJHGameScene::moveSentCardSprite(Sprite* pCardSprite, uint16 wViewID, uint8 cbIndex, float fDelayTime) { CC_ASSERT(wViewIDgetHandCardPos(cbIndex); Vec2 ptEndPos = ptCardPos; auto pAction = Spawn::create(MoveTo::create(0.15f, ptEndPos), RotateBy::create(0.15f, 180), nullptr); auto callback = [=](Node* pNode) { // 替换真牌; int nTag = pNode->getTag(); int nCardIndex = nTag / 100; m_aryPlayer[wViewID]->addOneCard(0, nCardIndex); pNode->removeFromParent(); if (ZJH_VIEW_SELF_ID==wViewID) { playSendCardEffect(); } }; pCardSprite->runAction(Sequence::create(DelayTime::create(fDelayTime), pAction, CallFuncN::create(callback), nullptr)); } // 扔筹码动画; void ZJHGameScene::playChipAni(uint16 wViewID, int nCount, bool bAction/* = true*/) { playEffect("jiaEffect"); // 临时筹码精灵数组; const Vec2 ptHeadPos = m_aryPlayer[wViewID]->getHeadPos(); Vec2 ptStartPos = _ChipPanel->convertToNodeSpace(ptHeadPos); //float startPosX = ptHeadPos.x - _ChipPanel->getPositionX(); //float startPosY = ptHeadPos.y - _ChipPanel->getPositionY(); // 显示筹码数字; int aryChipGroup[5] = { 5, 4, 3, 2, 1 }; for (int i = 0; i < 5; i++) { int nNum = nCount / aryChipGroup[i]; if (nNum > 0) { for (int k = 0; k < nNum; k++) { auto pChipNode = ZJHChipNode::create(aryChipGroup[i]); float fChipWidth = pChipNode->getContentSize().width; float fChipHeight = pChipNode->getContentSize().height; _ChipPanel->addChild(pChipNode); float endPosX = (fChipWidth / 2) + (_ChipPanel->getContentSize().width - fChipWidth)*cocos2d::rand_0_1(); float endPosY = (fChipHeight / 2) + (_ChipPanel->getContentSize().height - fChipHeight)*cocos2d::rand_0_1(); if (bAction) { pChipNode->setPosition(ptStartPos); pChipNode->runAction(MoveTo::create(0.3f, Vec2(endPosX, endPosY))); } else { pChipNode->setPosition(Vec2(endPosX, endPosY)); } _aryChipNode.push_back(pChipNode); } } nCount %= aryChipGroup[i]; if (0==nCount) { break; } } } // 播放结束积分动画; void ZJHGameScene::playResultScoreAni(int nIndex, SCORE lScore) { CC_ASSERT(nIndex < ZJH_GAME_PLAYER); auto pAction1 = ScaleTo::create(0.15f, 0.8f); auto pAction2 = ScaleTo::create(0.18f, 1.5f); auto pAction3 = ScaleTo::create(0.12f, 1.2f); TextAtlas* txtResult = _pTxtResultScore[nIndex]; if (0 != lScore) { txtResult->setVisible(true); txtResult->setScale(0); if (lScore >= 0) { txtResult->setProperty(StringUtils::format("/%d", lScore), "Games/ZJH/Table/imgPositiveFont.png", 26, 35, "/"); } else { txtResult->setProperty(StringUtils::format("/%d", std::abs(lScore)), "Games/ZJH/Table/imgNegativeFont.png", 26, 35, "/"); } txtResult->runAction(Sequence::create(pAction1, pAction2, pAction3, nullptr)); } else { txtResult->setVisible(false); } } // 播放喜钱积分动画; void ZJHGameScene::playXiScoreAni(int nIndex, SCORE lScore) { CC_ASSERT(nIndex < ZJH_GAME_PLAYER); auto pAction1 = ScaleTo::create(0.15f, 0.8f); auto pAction2 = ScaleTo::create(0.18f, 1.5f); auto pAction3 = ScaleTo::create(0.12f, 1.2f); TextAtlas* txtResult = _pTxtXiScore[nIndex]; if (0 != lScore) { txtResult->setVisible(true); txtResult->setScale(0); if (lScore >= 0) { txtResult->setProperty(StringUtils::format(".%d", lScore), "Games/ZJH/Result/num_win.png", 38, 55, "."); } else { txtResult->setProperty(StringUtils::format("/%d", std::abs(lScore)), "Games/ZJH/Result/num_win.png", 38, 55, "."); } txtResult->runAction(Sequence::create(pAction1, pAction2, pAction3, nullptr)); } else { txtResult->setVisible(false); } } //玩家金币改变; void ZJHGameScene::OnUserScore(GamePlayer* pPlayer) { CC_ASSERT(pPlayer!=nullptr); if (pPlayer == nullptr) return; // 不再桌子上; CC_ASSERT(pPlayer->GetTableID() != INVALID_TABLE && pPlayer->GetChairID() != INVALID_CHAIR); if (pPlayer->GetTableID() == INVALID_TABLE || pPlayer->GetChairID() == INVALID_CHAIR) return; // 不是同一桌子玩家; CC_ASSERT(pPlayer->GetTableID() == getSelfGamePlayer()->GetTableID()); if (pPlayer->GetTableID() != getSelfGamePlayer()->GetTableID()) return; cocos2d::log(a_u8c("用户%s,score = %d"), pPlayer->GetNickName().c_str(), pPlayer->GetUserScore()); ((ZJHGamePlayer*)pPlayer)->updateScore(); } // 玩家坐标; Vec2 ZJHGameScene::GetPlayerPosByUserID(uint32 dwUserID) { ZJHGamePlayer* pPlayer = (ZJHGamePlayer*)getPlayerByUserID(dwUserID); if (pPlayer == nullptr) { return Vec2(); } //const Vec2& ptHeadPos = pPlayer->getHeadPos(); //Vec2 ptWorldPos = pPlayer->convertToWorldSpace(ptHeadPos); return pPlayer->getHeadPos(); } //调用; GamePlayer* ZJHGameScene::CreatePlayer(IClientUserItem * pIClientUserItem) { if (pIClientUserItem->GetChairID() == INVALID_CHAIR) { return NULL; } if (pIClientUserItem->GetUserID() == UserInfo::Instance().getUserID()) { m_pLocalPlayer->setUserItem(pIClientUserItem); return m_pLocalPlayer; } else { WORD wViewID = SwitchViewChairID(pIClientUserItem->GetChairID()); CC_ASSERT(wViewID!=INVALID_CHAIR); ZJHGamePlayer* pPlayer = m_aryPlayer[wViewID]; pPlayer->setUserItem(pIClientUserItem); return pPlayer; } return NULL; } //椅子号视图转换; WORD ZJHGameScene::SwitchViewChairID(WORD wChairID) { //参数判断; if (wChairID == INVALID_CHAIR) return INVALID_CHAIR; WORD wSelfChairID = getSelfChairID(); if (wSelfChairID == INVALID_CHAIR) return INVALID_CHAIR; //转换椅子; WORD wChairCount = ZJH_GAME_PLAYER; WORD wViewChairID = (wChairID + wChairCount - wSelfChairID + ZJH_VIEW_SELF_ID) % wChairCount; return wViewChairID; } //本人进入游戏 GameFrameBase.cpp调用; void ZJHGameScene::upSelfPlayerInfo() { log("Self Enter!!"); return; } // 获取当前玩家数量; uint8 ZJHGameScene::getCurPlayerCount() { uint8 cbPlayerCount = 0; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { GamePlayer* pPlayer = m_aryPlayer[i]; if (pPlayer != nullptr && pPlayer->getUserItem(false) != nullptr) { cbPlayerCount++; } } return cbPlayerCount; } /************************************* 语音 ***********************************************************/ // 按住语音按钮; void ZJHGameScene::OnButtonVoiceTouched(Ref*, Widget::TouchEventType type) { if (Widget::TouchEventType::BEGAN == type) { // 暂停播放背景音乐; CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); if (m_pVoiceNode->isVisible()) { m_pVoiceNode->setVisible(false); m_pVoiceNode->stopAllActions(); YvVoiceManager::GetInstance()->StopRecord(); return; } m_pVoiceNode->setVisible(true); // 启动帧动画; auto action = CSLoader::createTimeline("Games/ZJH/VoiceNode.csb"); action->gotoFrameAndPlay(0); m_pVoiceNode->runAction(action); YvVoiceManager::GetInstance()->StartRecord(); } else if ((Widget::TouchEventType::CANCELED == type) || (Widget::TouchEventType::ENDED == type)) { // 继续播放背景音乐; CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); if (!m_pVoiceNode->isVisible()) { return; } m_pVoiceNode->setVisible(false); m_pVoiceNode->stopAllActions(); YvVoiceManager::GetInstance()->StopRecord(); } } //获到性别字符串; std::string ZJHGameScene::getUserGender(int cbGender) { if (cbGender == 0) { return "man"; } return "woman"; } //播放发牌声音; void ZJHGameScene::playSendCardEffect() { CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); pAudio->playEffect("Games/ZJH/Sound/Deal.mp3"); } //播放快捷语音; void ZJHGameScene::playFastVoice(int cbGender, int voiceIndex) { CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); std::string strGender = getUserGender(cbGender); std::string strAudioRes = StringUtils::format("Games/ZJH/Sound/FastVoice/%s/%d.mp3", strGender.c_str(), voiceIndex); log("the strAudioRes is== %s", strAudioRes.c_str()); pAudio->playEffect(strAudioRes.c_str()); } //播放音效; void ZJHGameScene::playEffect(std::string strPath) { CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); std::string strAudioRes = StringUtils::format("Games/ZJH/Sound/%s.mp3", strPath.c_str()); pAudio->playEffect(strAudioRes.c_str()); } // 播放音效; void ZJHGameScene::playEffectEx(int cbGender, std::string strPath) { CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); std::string strGender = getUserGender(cbGender); std::string strAudioRes = StringUtils::format("Games/ZJH/Sound/%s/%s.mp3", strGender.c_str(), strPath.c_str()); log("the strAudioRes is== %s", strAudioRes.c_str()); pAudio->playEffect(strAudioRes.c_str()); } //播放点击音效; void ZJHGameScene::playBtnClickEffect() { CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance(); pAudio->playEffect("Games/ZJH/Sound/ClickBtn.mp3"); } /************************************* 房间信息 ***********************************************************/ // 房间信息消息; void ZJHGameScene::OnSocketSubPrivateRoomInfo(CMD_GF_Private_Room_Info* pNetInfo) { m_PrivateRoomInfo = *pNetInfo; m_dwRoomID = pNetInfo->dwRoomNum; string strRoomID = StringUtils::format("%d", m_dwRoomID); _txtRoomID->setString(strRoomID); _txtRoomID->setVisible(true); uint32 dwPlayCout = __max(pNetInfo->dwPlayCout+1, 1); dwPlayCout = __min(dwPlayCout, pNetInfo->dwPlayTotal); m_dwPlayCout = dwPlayCout; string strPlayCount = StringUtils::format("%u/%u", dwPlayCout, pNetInfo->dwPlayTotal); cocos2d::log("dwPlayCout = %d", pNetInfo->dwPlayCout); _txtJushu->setString(utility::a_u8(strPlayCount)); _txtJushu->setVisible(true); ShowGameRule(pNetInfo); ZJHGamePlayer* pPlayer = (ZJHGamePlayer*)getPlayerByUserID(pNetInfo->dwCreateUserID); if (pPlayer != nullptr) pPlayer->setOwner(true); if (pNetInfo->bStartGame) { //如果游戏已开始则隐藏“返回大厅”按钮,显示“解散房间”按钮; _btnInvite->setVisible(false); _btnStartGame->setVisible(false); _btnDismiss->setVisible(true); _btnLeave->setVisible(false); //私人场已经开始,重连上游戏自带发送准备消息; GamePlayer* pSelfPlayer = getSelfGamePlayer(); if (!_bGameEnd && !_ResultPanel->isVisible() && (pSelfPlayer != nullptr) && (pSelfPlayer->GetUserStatus() == US_SIT) && (m_cbGameStatus == ZJH_GS_FREE)) { SendUserReady(); } } else { GamePlayer* pPlayer = getSelfGamePlayer(); //如果房间主人是自已则隐藏“返回大厅”按钮,显示“解散房间”按钮; if (pPlayer != nullptr && pNetInfo->dwCreateUserID == pPlayer->GetUserID()) { _btnLeave->setVisible(false); _btnDismiss->setVisible(true); } //游戏未开始显示微信分享按钮; if (pNetInfo->dwPlayCout <= 0) { _btnInvite->setVisible(true); _btnStartGame->setVisible(true); } } } // 游戏规则; void ZJHGameScene::ShowGameRule(CMD_GF_Private_Room_Info* pNetInfo) { if (pNetInfo == nullptr) return; std::string strGameSet = ""; uint32 dwGameRule = m_PrivateRoomInfo.bGameRuleIdex; // 看牌轮数; if ((dwGameRule&eZJHGameRuleLookCardRound2) > 0) { strGameSet += "闷2轮, "; _cbMinLookRound = 2; _txtLookCardRound->setString(utility::a_u8("闷2轮")); } else if ((dwGameRule&eZJHGameRuleLookCardRound3) > 0) { strGameSet += "闷3轮, "; _cbMinLookRound = 3; _txtLookCardRound->setString(utility::a_u8("闷3轮")); } else { strGameSet += "不闷牌, "; _cbMinLookRound = 0; _txtLookCardRound->setString(utility::a_u8("不闷牌")); } // 比牌轮数; if ((dwGameRule&eZJHGameRuleCompareRound2) > 0) { strGameSet += "2轮可比牌, "; _txtCompareRound->setString("2"); } else if ((dwGameRule&eZJHGameRuleCompareRound3) > 0) { strGameSet += "3轮可比牌, "; _txtCompareRound->setString("3"); } else { strGameSet += "1轮可比牌, "; _txtCompareRound->setString("1"); } // 开牌轮数; if ((dwGameRule&eZJHGameRuleOpenCardRound10) > 0) { strGameSet += "10轮封顶"; _cbMaxRound = 10; _txtOpenCardRound->setString(StringUtils::format("%d/10", _cbCurRound)); } else if ((dwGameRule&eZJHGameRuleOpenCardRound15) > 0) { strGameSet += "15轮封顶"; _cbMaxRound = 15; _txtOpenCardRound->setString(StringUtils::format("%d/15", _cbCurRound)); } else { strGameSet += "5轮封顶"; _cbMaxRound = 5; _txtOpenCardRound->setString(StringUtils::format("%d/5", _cbCurRound)); } //strGameSet += StringUtils::format("%d分场", _iBaseScore); m_strGameRuleInfo = strGameSet; } // 私人场结束; void ZJHGameScene::OnSocketSubPrivateEnd(void* data, int dataSize) { m_bPrivateEnd = true; // 申请解散界面; DismissScene::Instance().hide(); DataStream kDataStream(data, dataSize); ZJH_CMD_S_Private_End_Info kNetInfo; kNetInfo.StreamValue(kDataStream, false); // 初始化; _aryResultItem.clear(); // 是不是欢乐场; bool bUnionScore = (m_PrivateRoomInfo.cbUnionGoldOpen == 1); for (int i = 0; i < ZJH_GAME_PLAYER; i++) { if (ZJH_ST_GAMING_NULL==kNetInfo.aryActiveStatus[i]) { continue; } tagZJHOpenResultItem mItem; mItem.lTotalScore = kNetInfo.aryTotalScore[i]; mItem.lWinScore = kNetInfo.aryWinScore[i]; mItem.lXiScore = kNetInfo.aryXiScore[i]; //if (bUnionScore) //{ // mItem.lUnionScore = mItem.lTotalScore * m_PrivateRoomInfo.lScoreMultiple; //} //else { mItem.lUnionScore = mItem.lTotalScore * m_PrivateRoomInfo.cbBaseScore; } GamePlayer* player = getPlayerByChairID(i); if (player!=nullptr) { std::string strName = player->GetNickName(); strncpy(mItem.szNickName, strName.c_str(), countarray(mItem.szNickName) - 1); mItem.dwGameID = player->GetGameID(); mItem.bOwner = (player->GetUserID() == m_PrivateRoomInfo.dwCreateUserID); std::string strHttpHead = player->GetHeadHttp(); strncpy(mItem.szHttpHead, strHttpHead.c_str(), countarray(mItem.szHttpHead) - 1); } _aryResultItem.push_back(mItem); } // 工会欢乐场; if (bUnionScore) { int nCount = _aryResultItem.size(); // 寻找大赢家; SCORE lMaxScore = 0; for (size_t i = 0; i < nCount; i++) { tagZJHOpenResultItem* pData = &(_aryResultItem.at(i)); if (pData->lTotalScore > lMaxScore) { lMaxScore = pData->lTotalScore; } } // 统计大赢家数量; int iMaxScoreCount = 0; for (int j = 0; j < nCount; j++) { tagZJHOpenResultItem* pData = &(_aryResultItem.at(j)); if ((lMaxScore > 0) && (pData->lTotalScore == lMaxScore)) { iMaxScoreCount++; } } if (iMaxScoreCount > 0) { // 计算玩家积分; SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost; SCORE lRevenue = floor(lGameGold / iMaxScoreCount); // 重新计算积分, 统计扣税; for (int k = 0; k < nCount; k++) { tagZJHOpenResultItem* pData = &(_aryResultItem.at(k)); if ((lMaxScore > 0) && (pData->lTotalScore == lMaxScore)) { if (pData->lUnionScore > lRevenue) { pData->lUnionScore -= lRevenue; } else { pData->lUnionScore = 0; } } // 这里直接设置为欢乐总积分 pData->lAllUnionScore = pData->lUnionScore + m_PrivateScoreInfo.kScoreInfoArray[k]; } } } if ((ZJH_GS_FREE==m_cbGameStatus) && _ResultPanel->isVisible() == false) { _OpenResultScene->updateUIData(m_dwRoomID, &_aryResultItem, true); _OpenResultScene->setVisible(true); } else { _btnPrivateEnd->setVisible(true); _btnReady->setVisible(false); } // 游戏结束停止网络; PrivateRoomEnd(); } void ZJHGameScene::onEventShowPrivate(cocos2d::EventCustom *event) { //if (m_pPrivateScene) //{ // m_pPrivateScene->pushScene(); //} } // 请求解散房间; void ZJHGameScene::OnSocketSubPrivateDismissInfo(CMD_GF_Private_Dismiss_Info* pNetInfo) { std::string aryName[ZJH_GAME_PLAYER]; BYTE aryResult[ZJH_GAME_PLAYER] = { 0 }; // 0 未选择 1 同意 2 不同意; bool bHasSelf = false; uint32 dwMyChairID = getSelfChairID(); for (uint32 i = 0; i < pNetInfo->dwDissUserCout; i++) { uint32 dwChairID = pNetInfo->dwDissChairID[i]; GamePlayer* pPlayer = getPlayerByChairID(dwChairID); if (pPlayer != nullptr && dwChairID < ZJH_GAME_PLAYER) { aryResult[dwChairID] = 1; } if (dwMyChairID == dwChairID) { bHasSelf = true; } } for (uint32 i = 0; i < pNetInfo->dwNotAgreeUserCout; i++) { uint32 dwChairID = pNetInfo->dwNotAgreeChairID[i]; GamePlayer* pPlayer = getPlayerByChairID(dwChairID); if (pPlayer != nullptr && dwChairID < ZJH_GAME_PLAYER) { aryResult[dwChairID] = 2; } if (dwMyChairID == dwChairID) { bHasSelf = true; } } GamePlayer* players[ZJH_GAME_PLAYER]; for (int i = 0; i < ZJH_GAME_PLAYER; i++) { players[i] = getPlayerByChairID(i); } DismissScene::Instance().show(aryResult, players, !bHasSelf, ZJH_GAME_PLAYER); } void ZJHGameScene::OnSocketSubPrivateDismissResult(CMD_GF_Private_Dismiss_Result* pNetInfo) { if (pNetInfo->bSuccess && false == m_PrivateRoomInfo.bStartGame) { EventLeaveGame(nullptr); } else { DismissScene::Instance().hide(); } } std::string ZJHGameScene::getGameRule(uint32 dwGameRule) { std::string strGameSet = ""; // 看牌轮数; if ((dwGameRule&eZJHGameRuleLookCardRound2) > 0) { strGameSet += "闷2轮, "; } else if ((dwGameRule&eZJHGameRuleLookCardRound3) > 0) { strGameSet += "闷3轮, "; } else { strGameSet += "不闷牌, "; } // 比牌轮数; if ((dwGameRule&eZJHGameRuleCompareRound2) > 0) { strGameSet += "2轮可比牌, "; } else if ((dwGameRule&eZJHGameRuleCompareRound3) > 0) { strGameSet += "3轮可比牌, "; } else { strGameSet += "1轮可比牌, "; } // 开牌轮数; if ((dwGameRule&eZJHGameRuleOpenCardRound10) > 0) { strGameSet += "10轮封顶"; } else if ((dwGameRule&eZJHGameRuleOpenCardRound15) > 0) { strGameSet += "15轮封顶"; } else { strGameSet += "5轮封顶"; } return strGameSet; }