2407 lines
67 KiB
C++
2407 lines
67 KiB
C++
#include "DDZ_GameScene.h"
|
||
|
||
#include "DDZ_Player.h"
|
||
#include "DDZ_GameLogic.h"
|
||
#include "UserInfo.h"
|
||
#include "MainScene.h"
|
||
#include "MissionWeiXin.h"
|
||
#include "DismissScene.h"
|
||
#include "DDZ_SmallCardSprite.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 DDZ_SPACE;
|
||
|
||
bool DDZGameScene::init()
|
||
{
|
||
if (!GameFrameBase::init())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
m_cbTimeOutCard = 0;
|
||
m_cbTimeCallScore = 0;
|
||
m_cbTimeStartGame = 0;
|
||
m_cbTimeHeadOutCard = 0;
|
||
|
||
m_nCellScore = 0;
|
||
m_pVoiceNode = nullptr;
|
||
m_strGameRuleInfo = "";
|
||
|
||
zeromemory(&m_PrivateRoomInfo, sizeof(CMD_GF_Private_Room_Info));
|
||
|
||
initNet();
|
||
initScene();
|
||
|
||
return true;
|
||
}
|
||
|
||
//进场动画完成回调;
|
||
void DDZGameScene::onEnterTransitionDidFinish()
|
||
{
|
||
GameFrameBase::onEnterTransitionDidFinish();
|
||
|
||
if (true == GAME_MUISCBG)
|
||
{
|
||
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Games/DDZ/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(DDZ_GAME_PLAYER);
|
||
}
|
||
else
|
||
{
|
||
// 增加游戏内事件处理;
|
||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||
dispatcher->addCustomEventListener(SHOW_PRIVATE_END, CC_CALLBACK_1(DDZGameScene::onEventShowPrivate, this));
|
||
|
||
CGameServerItem* pGameServerItem = GameMission::g_pGameServerItem;
|
||
CC_ASSERT(pGameServerItem != nullptr);
|
||
if (pGameServerItem != nullptr)
|
||
{
|
||
m_kGameMission.SetServerItem(pGameServerItem);
|
||
m_kGameMission.start();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
//场景退出;
|
||
void DDZGameScene::onExit()
|
||
{
|
||
GameFrameBase::onExit();
|
||
|
||
for (int i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
SafeDelete(m_aryPlayer[i]);
|
||
}
|
||
|
||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||
dispatcher->removeCustomEventListeners(SHOW_PRIVATE_END);
|
||
}
|
||
|
||
//场景初始化;
|
||
void DDZGameScene::initScene()
|
||
{
|
||
//根节点;
|
||
m_rootNode = CSLoader::createNodeWithVisibleSize("Games/DDZ/GameScene.csb");
|
||
CC_ASSERT(m_rootNode != nullptr);
|
||
this->addChild(m_rootNode, ZO_DEFAULT);
|
||
|
||
// 公告;
|
||
auto ImageSytem = (ImageView*)m_rootNode->getChildByName("ImgRoll");
|
||
ASSERT(ImageSytem!=nullptr);
|
||
SetSystemNode(ImageSytem);
|
||
|
||
//桌子节点;
|
||
auto tablePanel = static_cast<Layout*>(m_rootNode->getChildByName("panelRoomBg"));
|
||
CC_ASSERT(tablePanel != nullptr);
|
||
|
||
for (int i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
const char* lpcStr = __String::createWithFormat("panelChair_%d", i)->getCString();
|
||
Layout* layout = static_cast<Layout*>(m_rootNode->getChildByName(lpcStr));
|
||
m_aryPlayer[i] = new DDZPlayer(i, layout);
|
||
|
||
// 自己不可点击;
|
||
if (i != DDZ_SELF_VIEW_ID)
|
||
{
|
||
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_pLocalPlayer = m_aryPlayer[DDZ_SELF_VIEW_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);
|
||
};
|
||
|
||
//退出按钮;
|
||
m_pBtnLeave = static_cast<Button*>(tablePanel->getChildByName("btnExit"));
|
||
CC_ASSERT(m_pBtnLeave != nullptr);
|
||
m_pBtnLeave->addClickEventListener(exitCallFunc);
|
||
|
||
//设置按钮;
|
||
auto btnSetting = static_cast<Button*>(tablePanel->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();
|
||
});
|
||
|
||
//聊天按钮;
|
||
auto btnChat = static_cast<Button*>(tablePanel->getChildByName("btnChat"));
|
||
CC_ASSERT(btnChat != nullptr);
|
||
btnChat->addClickEventListener([this](Ref*){
|
||
YSAudioEngine::Instance().playBtnClickEffect();
|
||
|
||
const std::vector<std::string>& chatList = getShortChatList();
|
||
auto chatLayer = ChatLayer::create(chatList);
|
||
CC_ASSERT(chatLayer != nullptr);
|
||
this->addChild(chatLayer, ZO_ANI);
|
||
chatLayer->pushScene();
|
||
});
|
||
|
||
auto btnTrustee = static_cast<Button*>(tablePanel->getChildByName("btnTrust"));
|
||
CC_ASSERT(btnTrustee != nullptr);
|
||
btnTrustee->addClickEventListener([=](Ref*){
|
||
if (!m_bGameStart) return;
|
||
|
||
DDZ_CMD_C_Trustee mData;
|
||
mData.bTrustee = !m_aryTrustee[DDZ_SELF_VIEW_ID];
|
||
|
||
SendSocketData(DDZ_SUB_C_TRUSTEE, &mData, sizeof(DDZ_CMD_C_Trustee));
|
||
});
|
||
|
||
auto imgTop = static_cast<ImageView*>(tablePanel->getChildByName("imgTop"));
|
||
CC_ASSERT(imgTop != nullptr);
|
||
|
||
//基数;
|
||
m_pTxtBaseScore = static_cast<TextAtlas*>(imgTop->getChildByName("baseScore"));
|
||
CC_ASSERT(m_pTxtBaseScore != nullptr);
|
||
|
||
//倍数;
|
||
m_pTxtMultiple = static_cast<TextAtlas*>(imgTop->getChildByName("multiple"));
|
||
CC_ASSERT(m_pTxtMultiple != nullptr);
|
||
|
||
auto sprRoomID = static_cast<Sprite*>(tablePanel->getChildByName("sprRoomID"));
|
||
CC_ASSERT(sprRoomID != nullptr);
|
||
|
||
//房间号;
|
||
m_txtPrivateRoomID = static_cast<Text*>(sprRoomID->getChildByName("txtPrivateRoomID"));
|
||
CC_ASSERT(m_txtPrivateRoomID != nullptr);
|
||
m_txtPrivateRoomID->setVisible(false);
|
||
|
||
auto imgRule = static_cast<ImageView*>(tablePanel->getChildByName("imgRule"));
|
||
CC_ASSERT(imgRule != nullptr);
|
||
|
||
//局数;
|
||
m_txtPrivatePlayCount = static_cast<Text*>(imgRule->getChildByName("txtPrivatePlayCount"));
|
||
CC_ASSERT(m_txtPrivatePlayCount != nullptr);
|
||
m_txtPrivatePlayCount->setVisible(false);
|
||
|
||
////倍数;
|
||
//m_txtPrivateMultiple = static_cast<Text*>(imgRule->getChildByName("txtPrivateMultiple"));
|
||
//CC_ASSERT(m_txtPrivateMultiple != nullptr);
|
||
//m_txtPrivateMultiple->setVisible(false);
|
||
|
||
//底牌面板;
|
||
m_pPanelBackCard = static_cast<Layout*>(tablePanel->getChildByName("panelBackCard"));
|
||
CC_ASSERT(m_pPanelBackCard != nullptr);
|
||
|
||
//准备按钮;
|
||
m_pBtnReady = static_cast<Button*>(m_rootNode->getChildByName("btnReady"));
|
||
CC_ASSERT(m_pBtnReady != nullptr);
|
||
m_pBtnReady->addClickEventListener([=](Ref*){
|
||
SendUserReady();
|
||
});
|
||
|
||
//叫分按钮面板;
|
||
auto panelCallScore = static_cast<Layout*>(m_rootNode->getChildByName("panelCallScore"));
|
||
CC_ASSERT(panelCallScore != nullptr);
|
||
for (int i = 0; i < 3; i++)
|
||
{
|
||
m_pAryBtnCall[i] = static_cast<Button*>(panelCallScore->getChildByName(StringUtils::format("btnCall%d", (i+1))));
|
||
CC_ASSERT(m_pAryBtnCall[i] != nullptr);
|
||
|
||
m_pAryBtnCall[i]->addClickEventListener([=](Ref*){
|
||
DDZ_CMD_C_CallScore call;
|
||
call.cbCallScore = i+1;
|
||
SendSocketData(DDZ_SUB_C_CALL_SCORE, &call, sizeof(DDZ_CMD_C_CallScore));
|
||
});
|
||
}
|
||
|
||
//不叫按钮;
|
||
m_pBtnNoCall = static_cast<Button*>(panelCallScore->getChildByName("btnPass"));
|
||
CC_ASSERT(m_pBtnNoCall != nullptr);
|
||
m_pBtnNoCall->addClickEventListener([=](Ref*){
|
||
SendPassCall();
|
||
});
|
||
|
||
//出牌按钮面板;
|
||
auto panelOutCard = static_cast<Layout*>(m_rootNode->getChildByName("panelOutCard"));
|
||
CC_ASSERT(panelOutCard != nullptr);
|
||
|
||
//不出按钮;
|
||
m_pBtnPass = static_cast<Button*>(panelOutCard->getChildByName("btnPass"));
|
||
CC_ASSERT(m_pBtnPass != nullptr);
|
||
m_pBtnPass->addClickEventListener([this](Ref*){
|
||
if (getSelfChairID() == m_wCurChairID)
|
||
{
|
||
SendSocketData(DDZ_SUB_C_PASS_CARD);
|
||
|
||
m_pHandCardLayer->downAllCard();
|
||
}
|
||
});
|
||
|
||
//提示按钮;
|
||
m_pBtnTips = static_cast<Button*>(panelOutCard->getChildByName("btnTips"));
|
||
CC_ASSERT(m_pBtnTips != nullptr);
|
||
m_pBtnTips->addClickEventListener(CC_CALLBACK_1(DDZGameScene::onButtonTipClick, this));
|
||
|
||
//出牌按钮;
|
||
m_pBtnOutCard = static_cast<Button*>(panelOutCard->getChildByName("btnOutCard"));
|
||
CC_ASSERT(m_pBtnOutCard != nullptr);
|
||
m_pBtnOutCard->addClickEventListener([this](Ref*){
|
||
//播放出牌音效;
|
||
playSoundEffect(DDZ_ST_OUT_CARD);
|
||
|
||
DDZ_CMD_C_OutCard OutCard;
|
||
zeromemory(&OutCard, sizeof(DDZ_CMD_C_OutCard));
|
||
m_pHandCardLayer->getShootCardData(OutCard.cbCardData, OutCard.cbCardCount);
|
||
|
||
uint16 wHeadSize = sizeof(DDZ_CMD_C_OutCard) - sizeof(OutCard.cbCardData);
|
||
uint16 wSendSize = wHeadSize + sizeof(uint8)*OutCard.cbCardCount;
|
||
SendSocketData(DDZ_SUB_C_OUT_CARD, &OutCard, wSendSize);
|
||
});
|
||
|
||
//提示面板;
|
||
m_pPanelTrustee = static_cast<Layout*>(m_rootNode->getChildByName("panelTrustee"));
|
||
CC_ASSERT(m_pPanelTrustee != nullptr);
|
||
|
||
//取消托管按钮;
|
||
auto btnCancelTrustee = static_cast<Button*>(m_pPanelTrustee->getChildByName("btnTrustee"));
|
||
CC_ASSERT(btnCancelTrustee != nullptr);
|
||
|
||
btnCancelTrustee->addClickEventListener([=](Ref*){
|
||
if (!m_bGameStart || !m_aryTrustee[DDZ_SELF_VIEW_ID]) return;
|
||
|
||
DDZ_CMD_C_Trustee mData;
|
||
mData.bTrustee = false;
|
||
|
||
SendSocketData(DDZ_SUB_C_TRUSTEE, &mData, sizeof(DDZ_CMD_C_Trustee));
|
||
});
|
||
|
||
//提示文字;
|
||
m_pSprTips = static_cast<Sprite*>(m_rootNode->getChildByName("sprTips"));
|
||
CC_ASSERT(m_pSprTips != nullptr);
|
||
|
||
//手牌节点;
|
||
auto panelHandCard = static_cast<Layout*>(m_rootNode->getChildByName("panelHandCard"));
|
||
|
||
auto func = CC_CALLBACK_2(DDZGameScene::selectCardCallback, this);
|
||
m_pHandCardLayer = DDZHandCardLayer::create(panelHandCard->getContentSize(), func);
|
||
panelHandCard->addChild(m_pHandCardLayer);
|
||
|
||
//加载扑克牌缓存;
|
||
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Table/PinCard.plist");
|
||
|
||
//微信分享按钮;
|
||
m_btnWeiXin = (Button*)tablePanel->getChildByName("btnWeiXin");
|
||
CC_ASSERT(m_btnWeiXin != nullptr);
|
||
m_btnWeiXin->setVisible(false);
|
||
|
||
// 分享房间号;
|
||
m_btnWeiXin->addClickEventListener([=](Ref*){
|
||
//std::string strText = StringUtils::format("房间号: [%u] %d 局, 房卡AA, %s。", m_PrivateRoomInfo.dwRoomNum, m_PrivateRoomInfo.dwPlayTotal, m_strGameRuleInfo.c_str());
|
||
std::string strText = StringUtils::format("房间号(%u), %d 局。", m_PrivateRoomInfo.dwRoomNum, m_PrivateRoomInfo.dwPlayTotal);
|
||
|
||
std::string strUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_URL);
|
||
std::string strUrlAll = StringUtils::format("%s?param=%d", strUrl.c_str(), m_PrivateRoomInfo.dwRoomNum);
|
||
|
||
MissionWeiXin::Instance().shareUrlWeiXin(strUrlAll, "斗地主", strText);
|
||
//SelectShareScene::Instance().shareRoomInfo(strUrlAll, utility::a_u8("斗地主"), strText, 0);
|
||
});
|
||
|
||
// 语音标志;
|
||
m_pVoiceNode = (Node*)m_rootNode->getChildByName("VoiceNode");
|
||
CC_ASSERT(m_pVoiceNode != nullptr);
|
||
m_pVoiceNode->setVisible(false);
|
||
|
||
//语音按钮;
|
||
auto btnVoice = (Button*)tablePanel->getChildByName("btnVoice");
|
||
CC_ASSERT(btnVoice != nullptr);
|
||
|
||
//注册触摸事件;
|
||
btnVoice->addTouchEventListener(CC_CALLBACK_2(DDZGameScene::OnButtonVoiceTouched, this));
|
||
//btnVoice->setVisible(false);
|
||
|
||
// 解散房间函数;
|
||
auto callback = [this](){
|
||
onEventAgreeDismissRoom(true);
|
||
};
|
||
|
||
// 离开按钮;
|
||
m_btnDismissRoom = (Button*)tablePanel->getChildByName("btnDismiss");
|
||
CC_ASSERT(m_btnDismissRoom != nullptr);
|
||
m_btnDismissRoom->setVisible(false);
|
||
m_btnDismissRoom->addClickEventListener([=](Ref *pSender){
|
||
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);
|
||
});
|
||
|
||
// 结算面板;
|
||
m_pResultLayer = DDZGameEndNode::create();
|
||
m_pResultLayer->setVisible(false);
|
||
this->addChild(m_pResultLayer, ZO_END);
|
||
|
||
// 私人场面皮;
|
||
m_pPrivateScene = DDZPrivateEndNode::create();
|
||
m_pPrivateScene->setVisible(false);
|
||
this->addChild(m_pPrivateScene, ZO_PRIVATE);
|
||
|
||
//对手机返回键的监听;
|
||
auto keyListener = EventListenerKeyboard::create();
|
||
//和回调函数绑定;
|
||
keyListener->onKeyReleased = [=](EventKeyboard::KeyCode keyCode, Event * pEvent){
|
||
//返回值处理;
|
||
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
|
||
{
|
||
exitCallFunc(nullptr);
|
||
}
|
||
};
|
||
//添加到事件分发器中;
|
||
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
|
||
|
||
loadShortChat("Games/DDZ/ShortChat/ChatInfo.json");
|
||
|
||
//重置场景;
|
||
resetScene();
|
||
|
||
//重置数据;
|
||
ResetAllData();
|
||
}
|
||
|
||
//重置场景;
|
||
void DDZGameScene::resetScene(bool bAll/* = false*/)
|
||
{
|
||
//重置玩家UI
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryPlayer[i]->resetUI(bAll);
|
||
|
||
m_pAryBtnCall[i]->setVisible(false);
|
||
}
|
||
|
||
////重置基数;
|
||
//m_pTxtBaseScore->setString("");
|
||
|
||
//倍数;
|
||
m_pTxtMultiple->setString("");
|
||
|
||
//隐藏所有按钮;
|
||
m_pBtnNoCall->setVisible(false);
|
||
m_pBtnPass->setVisible(false);
|
||
m_pBtnTips->setVisible(false);
|
||
m_pBtnOutCard->setVisible(false);
|
||
m_pBtnReady->setVisible(false);
|
||
|
||
//隐藏面板;
|
||
m_pSprTips->setVisible(false);
|
||
m_pPanelTrustee->setVisible(false);
|
||
|
||
//清空底牌;
|
||
m_pPanelBackCard->removeAllChildren();
|
||
|
||
//清空手牌;
|
||
m_pHandCardLayer->setLordMode(false);
|
||
m_pHandCardLayer->initUIData();
|
||
}
|
||
|
||
//重置数据;
|
||
void DDZGameScene::resetData()
|
||
{
|
||
m_bGameStart = false;
|
||
|
||
m_wLandChairID = INVALID_CHAIR;
|
||
m_wCurChairID = INVALID_CHAIR;
|
||
|
||
m_wTurnWiner = INVALID_CHAIR;
|
||
m_cbTurnCardCount = 0;
|
||
|
||
m_cbBombCount = 0;
|
||
m_cbCallScore = 0;
|
||
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryTrustee[i] = false;
|
||
}
|
||
|
||
zeromemory(m_cbTurnCardData, sizeof(m_cbTurnCardData));
|
||
zeromemory(m_aryHandCardData, sizeof(m_aryHandCardData));
|
||
zeromemory(m_aryHandCardCount, sizeof(m_aryHandCardCount));
|
||
zeromemory(m_aryAllHandCardData, sizeof(m_aryAllHandCardData));
|
||
zeromemory(m_aryBackCardData, sizeof(m_aryBackCardData));
|
||
}
|
||
|
||
//重置数据(相当于玩家离开);
|
||
void DDZGameScene::ResetAllData()
|
||
{
|
||
resetScene();
|
||
|
||
resetData();
|
||
}
|
||
|
||
//重置桌子;
|
||
void DDZGameScene::ResetTable()
|
||
{
|
||
resetScene(true);
|
||
|
||
resetData();
|
||
}
|
||
|
||
//获取快捷语音文件路径;
|
||
const std::string DDZGameScene::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 DDZGameScene::initNet()
|
||
{
|
||
addNetCBDefine(DDZ_SUB_S_GAME_START, this, DDZGameScene::onSubGameStart);
|
||
addNetCBDefine(DDZ_SUB_S_CALL_SCORE, this, DDZGameScene::onSubGameCallScore);
|
||
addNetCBDefine(DDZ_SUB_S_BANKER_INFO, this, DDZGameScene::onSubGameBankerInfo);
|
||
addNetCBDefine(DDZ_SUB_S_OUT_CARD, this, DDZGameScene::onSubGameOutCard);
|
||
addNetCBDefine(DDZ_SUB_S_PASS_CARD, this, DDZGameScene::onSubGamePassCard);
|
||
addNetCBDefine(DDZ_SUB_S_SET_BASESCORE, this, DDZGameScene::onSubGameSetBaseScore);
|
||
addNetCBDefine(DDZ_SUB_S_GAME_CONCLUDE, this, DDZGameScene::onSubGameEnd);
|
||
addNetCBDefine(DDZ_SUB_S_TRUSTEE, this, DDZGameScene::onSubGameTrustee);
|
||
}
|
||
|
||
//按钮点击事件;
|
||
void DDZGameScene::onButtonTipClick(Ref*)
|
||
{
|
||
if (getSelfChairID() != m_wCurChairID)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//搜索出牌;
|
||
tagSearchCardResult mCardResult;
|
||
uint8 cbResultCount = m_GameLogic.SearchOutCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID],
|
||
m_cbTurnCardData, m_cbTurnCardCount, &mCardResult);
|
||
|
||
if (cbResultCount > 0)
|
||
{
|
||
//弹起牌;
|
||
m_pHandCardLayer->shootCardData(mCardResult.cbResultCard[0], mCardResult.cbCardCount[0]);
|
||
m_pBtnOutCard->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
SendSocketData(DDZ_SUB_C_PASS_CARD);
|
||
}
|
||
}
|
||
|
||
bool DDZGameScene::OnEventSceneMessage(uint8 cbGameStatus, bool bLookonUser, void* pData, int nDataSize)
|
||
{
|
||
switch (cbGameStatus)
|
||
{
|
||
case GAME_SCENE_FREE:
|
||
{
|
||
return onGameSceneFree(pData, nDataSize);
|
||
}
|
||
case GAME_SCENE_CALL:
|
||
{
|
||
return onGameSceneCall(pData, nDataSize);
|
||
}
|
||
case GAME_SCENE_PLAY:
|
||
{
|
||
return onGameScenePlay(pData, nDataSize);
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//恢复空闭场景;
|
||
bool DDZGameScene::onGameSceneFree(void* pData, int nDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(nDataSize == sizeof(DDZ_CMD_S_StatusFree));
|
||
DDZ_CMD_S_StatusFree* pStatusFree = (DDZ_CMD_S_StatusFree*)pData;
|
||
|
||
m_cbTimeOutCard = pStatusFree->cbTimeOutCard;
|
||
m_cbTimeCallScore = pStatusFree->cbTimeCallScore;
|
||
m_cbTimeStartGame = pStatusFree->cbTimeStartGame;
|
||
m_cbTimeHeadOutCard = pStatusFree->cbTimeHeadOutCard;
|
||
|
||
m_nCellScore = pStatusFree->lCellScore;
|
||
|
||
m_pTxtBaseScore->setString(utility::toString(pStatusFree->lCellScore));
|
||
|
||
m_pBtnReady->setVisible(true);
|
||
|
||
return true;
|
||
}
|
||
|
||
//恢复叫分场景;
|
||
bool DDZGameScene::onGameSceneCall(void* pData, int nDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(nDataSize == sizeof(DDZ_CMD_S_StatusCall));
|
||
DDZ_CMD_S_StatusCall* pStatusCall = (DDZ_CMD_S_StatusCall*)pData;
|
||
|
||
m_bGameStart = true;
|
||
|
||
m_cbTimeOutCard = pStatusCall->cbTimeOutCard;
|
||
m_cbTimeCallScore = pStatusCall->cbTimeCallScore;
|
||
m_cbTimeStartGame = pStatusCall->cbTimeStartGame;
|
||
m_cbTimeHeadOutCard = pStatusCall->cbTimeHeadOutCard;
|
||
|
||
m_nCellScore = pStatusCall->lCellScore;
|
||
m_cbCallScore = pStatusCall->cbBankerScore;
|
||
|
||
m_pTxtBaseScore->setString(utility::toString(pStatusCall->lCellScore));
|
||
m_pTxtMultiple->setString(utility::toString(pStatusCall->cbBankerScore));
|
||
|
||
//拷贝手牌;
|
||
memcpy(m_aryHandCardData, pStatusCall->cbHandCardData, sizeof(pStatusCall->cbHandCardData));
|
||
//初始化牌数;
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
uint16 wViewID = SwitchViewChairID(i);
|
||
|
||
m_aryHandCardCount[wViewID] = DDZ_NORMAL_COUNT;
|
||
m_aryTrustee[wViewID] = pStatusCall->bUserTrustee[i];
|
||
|
||
m_aryPlayer[wViewID]->setHandCardCount(DDZ_NORMAL_COUNT);
|
||
if (pStatusCall->cbScoreInfo[i] > 0)
|
||
{
|
||
m_aryPlayer[wViewID]->setCallVisible(true, pStatusCall->cbScoreInfo[i]);
|
||
}
|
||
}
|
||
|
||
m_GameLogic.SortCardList(m_aryHandCardData, DDZ_NORMAL_COUNT, DDZ_ST_ORDER);
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, DDZ_NORMAL_COUNT);
|
||
|
||
//更新出牌按钮;
|
||
updateCallButtons(pStatusCall->wCurrentUser, pStatusCall->cbBankerScore);
|
||
|
||
//显示底牌;
|
||
drawBackCardData();
|
||
|
||
m_wCurChairID = pStatusCall->wCurrentUser;
|
||
|
||
//// 同IP判断
|
||
//IsSameIp();
|
||
|
||
//// 隐藏同IP显示;
|
||
//IpTipScene::Instance().hide();
|
||
|
||
return true;
|
||
}
|
||
|
||
//恢复游戏场景;
|
||
bool DDZGameScene::onGameScenePlay(void* pData, int nDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(nDataSize == sizeof(DDZ_CMD_S_StatusPlay));
|
||
DDZ_CMD_S_StatusPlay* pStatusPlay = (DDZ_CMD_S_StatusPlay*)pData;
|
||
|
||
m_bGameStart = true;
|
||
|
||
m_cbTimeOutCard = pStatusPlay->cbTimeOutCard;
|
||
m_cbTimeCallScore = pStatusPlay->cbTimeCallScore;
|
||
m_cbTimeStartGame = pStatusPlay->cbTimeStartGame;
|
||
m_cbTimeHeadOutCard = pStatusPlay->cbTimeHeadOutCard;
|
||
|
||
m_cbCallScore = pStatusPlay->cbBankerScore;
|
||
m_cbBombCount = pStatusPlay->cbBombCount;
|
||
|
||
//显示基数;
|
||
m_pTxtBaseScore->setString(utility::toString(pStatusPlay->lCellScore));
|
||
|
||
//更新倍数;
|
||
updateMultipleText();
|
||
|
||
m_wTurnWiner = pStatusPlay->wTurnWiner;
|
||
m_cbTurnCardCount = pStatusPlay->cbTurnCardCount;
|
||
memcpy(m_cbTurnCardData, pStatusPlay->cbTurnCardData, m_cbTurnCardCount);
|
||
|
||
m_wLandChairID = pStatusPlay->wBankerUser;
|
||
m_wCurChairID = pStatusPlay->wCurrentUser;
|
||
|
||
//初始化牌数;
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
uint16 wViewID = SwitchViewChairID(i);
|
||
|
||
m_aryTrustee[wViewID] = pStatusPlay->bUserTrustee[i];
|
||
|
||
uint8 cbCardCount = pStatusPlay->cbHandCardCount[i];
|
||
m_aryHandCardCount[wViewID] = cbCardCount;
|
||
m_aryPlayer[wViewID]->setHandCardCount(cbCardCount);
|
||
|
||
//最后出牌玩家视图;
|
||
if (i == m_wTurnWiner)
|
||
{
|
||
m_aryPlayer[wViewID]->setOutCardData(pStatusPlay->cbTurnCardData, m_cbTurnCardCount);
|
||
}
|
||
|
||
if (DDZ_SELF_VIEW_ID == wViewID)
|
||
{
|
||
//拷贝手牌;
|
||
memcpy(m_aryHandCardData, pStatusPlay->cbHandCardData, cbCardCount);
|
||
|
||
m_GameLogic.SortCardList(m_aryHandCardData, cbCardCount, DDZ_ST_ORDER);
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, cbCardCount);
|
||
}
|
||
|
||
bool bLandlord = (i == pStatusPlay->wBankerUser);
|
||
m_aryPlayer[wViewID]->setLand(bLandlord);
|
||
}
|
||
|
||
//拷贝底牌;
|
||
memcpy(m_aryBackCardData, pStatusPlay->cbBankerCard, sizeof(pStatusPlay->cbBankerCard));
|
||
|
||
if (m_wLandChairID==getSelfChairID())
|
||
{
|
||
m_pHandCardLayer->setLordMode(true);
|
||
}
|
||
|
||
//显示底牌;
|
||
drawBackCardData();
|
||
|
||
//翻牌动画;
|
||
flipBackCard();
|
||
|
||
//更新按钮状态;
|
||
updateButtonsStatus(pStatusPlay->wCurrentUser, m_cbTimeOutCard, (0 == pStatusPlay->cbTurnCardCount));
|
||
|
||
if (m_aryTrustee[DDZ_SELF_VIEW_ID])
|
||
{
|
||
m_pPanelTrustee->setVisible(true);
|
||
}
|
||
|
||
//// 同IP判断;
|
||
//IsSameIp();
|
||
|
||
//// 隐藏同IP显示;
|
||
//IpTipScene::Instance().hide();
|
||
|
||
return true;
|
||
}
|
||
|
||
void DDZGameScene::onSubGameStart(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_GameStart));
|
||
DDZ_CMD_S_GameStart* pGameStart = (DDZ_CMD_S_GameStart*)pBuffer;
|
||
|
||
m_bGameStart = true;
|
||
|
||
//清除准备状态;
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryPlayer[i]->setReadyVisible(false);
|
||
}
|
||
|
||
m_wCurChairID = pGameStart->wCurrentUser;
|
||
|
||
//拷贝手牌;
|
||
memcpy(m_aryHandCardData, pGameStart->cbCardData, sizeof(pGameStart->cbCardData));
|
||
|
||
if (m_IsGameRecord)
|
||
{
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryHandCardCount[i] = DDZ_NORMAL_COUNT;
|
||
m_aryPlayer[i]->setHandCardCount(DDZ_NORMAL_COUNT);
|
||
}
|
||
|
||
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID], DDZ_ST_ORDER);
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID]);
|
||
|
||
//更新叫分按钮;
|
||
updateCallButtons(m_wCurChairID, 255);
|
||
|
||
|
||
//设置别外两家手牌;
|
||
m_GameLogic.SortCardList(m_aryAllHandCardData[DDZ_LEFT_VIEW_ID], m_aryHandCardCount[DDZ_LEFT_VIEW_ID], DDZ_ST_ORDER);
|
||
m_aryPlayer[DDZ_LEFT_VIEW_ID]->setHandCardData(m_aryAllHandCardData[DDZ_LEFT_VIEW_ID], m_aryHandCardCount[DDZ_LEFT_VIEW_ID]);
|
||
|
||
m_GameLogic.SortCardList(m_aryAllHandCardData[DDZ_RIGHT_VIEW_ID], m_aryHandCardCount[DDZ_RIGHT_VIEW_ID], DDZ_ST_ORDER);
|
||
m_aryPlayer[DDZ_RIGHT_VIEW_ID]->setHandCardData(m_aryAllHandCardData[DDZ_RIGHT_VIEW_ID], m_aryHandCardCount[DDZ_RIGHT_VIEW_ID]);
|
||
}
|
||
else
|
||
{
|
||
playSoundEffect(DDZ_ST_DEAL_CARD);
|
||
|
||
//发牌动画;
|
||
float fDelaySendTime = 0.01f;
|
||
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
|
||
//Vec2 ptInitCard = m_rootNode->getChildByName("imgGameLogo")->getPosition();
|
||
Size sizeWin = Director::getInstance()->getWinSize();
|
||
Vec2 ptInitCard;
|
||
ptInitCard.x = sizeWin.width / 2;
|
||
ptInitCard.y = sizeWin.height / 2;
|
||
|
||
for (uint8 i = 1; i <= (DDZ_FULL_COUNT - DDZ_BACK_COUNT); i++)
|
||
{
|
||
Sprite* pCardSprite = Sprite::createWithSpriteFrameName("bCardBack.png");
|
||
pCardSprite->setTag(i);
|
||
pCardSprite->setScale(0.5f);
|
||
//pCardSprite->setName(StringUtils::format("SendCardSprite%d", i));
|
||
pCardSprite->setPosition(ptInitCard);
|
||
m_rootNode->addChild(pCardSprite);
|
||
|
||
moveSendCardSprite(pCardSprite, i%DDZ_GAME_PLAYER, fDelaySendTime);
|
||
fDelaySendTime = fDelaySendTime + 0.03;
|
||
}
|
||
}
|
||
|
||
////初始化牌数;
|
||
//for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
//{
|
||
// m_aryHandCardCount[i] = DDZ_NORMAL_COUNT;
|
||
//}
|
||
|
||
////更新叫分按钮;
|
||
//updateCallButtons(pGameStart->wCurrentUser, 255);
|
||
|
||
//显示底牌背景;
|
||
drawBackCardData();
|
||
|
||
//// 隐藏同IP显示;
|
||
//IpTipScene::Instance().hide();
|
||
}
|
||
|
||
//玩家叫分
|
||
void DDZGameScene::onSubGameCallScore(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_CallScore));
|
||
DDZ_CMD_S_CallScore* pCallScore = (DDZ_CMD_S_CallScore*)pBuffer;
|
||
|
||
if (pCallScore->cbUserCallScore != 255 && pCallScore->cbUserCallScore>m_cbCallScore)
|
||
{
|
||
m_cbCallScore = pCallScore->cbUserCallScore;
|
||
}
|
||
|
||
//转换叫分玩家视图;
|
||
uint16 wViewID = SwitchViewChairID(pCallScore->wCallScoreUser);
|
||
|
||
//播放叫分声音;
|
||
playSoundEffect(DDZ_ST_CALL, m_aryPlayer[wViewID]->GetGender(), pCallScore->cbUserCallScore);
|
||
|
||
//隐藏倒计时;
|
||
m_aryPlayer[wViewID]->killClock();
|
||
m_aryPlayer[wViewID]->setCallVisible(true, pCallScore->cbUserCallScore);
|
||
|
||
//如果是自已叫分隐藏叫分按钮;
|
||
if (DDZ_SELF_VIEW_ID==wViewID)
|
||
{
|
||
for (uint8 i = 0; i < 3; i++)
|
||
{
|
||
m_pAryBtnCall[i]->setVisible(false);
|
||
}
|
||
m_pBtnNoCall->setVisible(false);
|
||
}
|
||
|
||
if (pCallScore->cbUserCallScore <= 3)
|
||
{
|
||
//显示倍数;
|
||
m_pTxtMultiple->setString(utility::toString<short>(pCallScore->cbUserCallScore));
|
||
}
|
||
|
||
//玩家叫了3分后当前玩家为INVALID_CHAIR;
|
||
if (INVALID_CHAIR!=pCallScore->wCurrentUser)
|
||
{
|
||
updateCallButtons(pCallScore->wCurrentUser, m_cbCallScore);
|
||
|
||
m_wCurChairID = pCallScore->wCurrentUser;
|
||
}
|
||
}
|
||
|
||
//地主信息;
|
||
void DDZGameScene::onSubGameBankerInfo(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_BankerInfo));
|
||
DDZ_CMD_S_BankerInfo* pBankerInfo = (DDZ_CMD_S_BankerInfo*)pBuffer;
|
||
|
||
m_wLandChairID = pBankerInfo->wBankerUser;
|
||
m_cbCallScore = pBankerInfo->cbBankerScore;
|
||
|
||
//清除玩家叫分信息;
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryPlayer[i]->setCallVisible(false);
|
||
}
|
||
|
||
//显示倍数;
|
||
m_pTxtMultiple->setString(utility::toString<short>(pBankerInfo->cbBankerScore));
|
||
|
||
//转换叫分玩家视图;
|
||
uint16 wBankerViewID = SwitchViewChairID(pBankerInfo->wBankerUser);
|
||
|
||
//增加手牌数量;
|
||
m_aryHandCardCount[wBankerViewID] += DDZ_BACK_COUNT;
|
||
|
||
m_aryPlayer[wBankerViewID]->setHandCardCount(m_aryHandCardCount[wBankerViewID]);
|
||
|
||
//设置地主标志;
|
||
m_aryPlayer[wBankerViewID]->setLand(true);
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
if (i != wBankerViewID)
|
||
{
|
||
m_aryPlayer[i]->setLand(false);
|
||
}
|
||
}
|
||
|
||
m_wCurChairID = pBankerInfo->wCurrentUser;
|
||
m_wTurnWiner = m_wCurChairID;
|
||
m_cbTurnCardCount = 0;
|
||
zeromemory(m_cbTurnCardData, sizeof(m_cbTurnCardData));
|
||
|
||
if (DDZ_SELF_VIEW_ID==wBankerViewID)
|
||
{
|
||
memcpy(m_aryHandCardData + DDZ_NORMAL_COUNT, pBankerInfo->cbBankerCard, sizeof(pBankerInfo->cbBankerCard));
|
||
|
||
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID], DDZ_ST_ORDER);
|
||
|
||
m_pHandCardLayer->setLordMode(true);
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID]);
|
||
|
||
updateButtonsStatus(pBankerInfo->wCurrentUser, m_cbTimeHeadOutCard, true);
|
||
}
|
||
else if (m_IsGameRecord)
|
||
{
|
||
memcpy(m_aryAllHandCardData[wBankerViewID] + DDZ_NORMAL_COUNT, pBankerInfo->cbBankerCard, sizeof(pBankerInfo->cbBankerCard));
|
||
|
||
m_GameLogic.SortCardList(m_aryAllHandCardData[wBankerViewID], m_aryHandCardCount[wBankerViewID], DDZ_ST_ORDER);
|
||
m_aryPlayer[wBankerViewID]->setHandCardData(m_aryAllHandCardData[wBankerViewID], m_aryHandCardCount[wBankerViewID]);
|
||
}
|
||
|
||
//拷贝底牌;
|
||
memcpy(m_aryBackCardData, pBankerInfo->cbBankerCard, sizeof(pBankerInfo->cbBankerCard));
|
||
|
||
//翻牌动画;
|
||
flipBackCard();
|
||
}
|
||
|
||
//玩家出牌;
|
||
void DDZGameScene::onSubGameOutCard(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//定义变量;
|
||
DDZ_CMD_S_OutCard* pOutCard = (DDZ_CMD_S_OutCard*)pBuffer;
|
||
|
||
uint16 wHeadSize = sizeof(DDZ_CMD_S_OutCard) - sizeof(pOutCard->cbCardData);
|
||
|
||
//效验数据;
|
||
CC_ASSERT((wDataSize >= wHeadSize) && (wDataSize == (wHeadSize + pOutCard->cbCardCount*sizeof(uint8))));
|
||
if ((wDataSize < wHeadSize) || (wDataSize != (wHeadSize + pOutCard->cbCardCount*sizeof(uint8)))) return ;
|
||
|
||
//转换出牌玩家视图;
|
||
uint16 wViewID = SwitchViewChairID(pOutCard->wOutCardUser);
|
||
m_aryPlayer[wViewID]->setPassVisible(false);
|
||
m_aryPlayer[wViewID]->setOutCardData(pOutCard->cbCardData, pOutCard->cbCardCount);
|
||
m_aryPlayer[wViewID]->killClock();
|
||
|
||
//获取出牌类型;
|
||
uint8 cbCardType = m_GameLogic.GetCardType(pOutCard->cbCardData, pOutCard->cbCardCount);
|
||
|
||
//计算炸弹次数;
|
||
if (DDZ_CT_BOMB_CARD == cbCardType || DDZ_CT_MISSILE_CARD == cbCardType)
|
||
{
|
||
m_cbBombCount++;
|
||
|
||
//更新倍数;
|
||
updateMultipleText();
|
||
}
|
||
|
||
playAnimate(cbCardType, pOutCard->wOutCardUser, m_wTurnWiner);
|
||
|
||
//播放出牌声音;
|
||
playSoundEffect(cbCardType, m_aryPlayer[wViewID]->GetGender(), pOutCard->cbCardData[0]);
|
||
|
||
if (wViewID == DDZ_SELF_VIEW_ID)
|
||
{
|
||
hideOutCardButtons();
|
||
|
||
m_GameLogic.RemoveCard(pOutCard->cbCardData, pOutCard->cbCardCount, m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID]);
|
||
m_aryHandCardCount[DDZ_SELF_VIEW_ID] -= pOutCard->cbCardCount;
|
||
|
||
//剩余牌数大于1再排序;
|
||
if (m_aryHandCardCount[DDZ_SELF_VIEW_ID]>1)
|
||
{
|
||
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID], DDZ_ST_ORDER);
|
||
}
|
||
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID]);
|
||
}
|
||
else
|
||
{
|
||
m_aryHandCardCount[wViewID] -= pOutCard->cbCardCount;
|
||
|
||
if (m_IsGameRecord)
|
||
{
|
||
m_GameLogic.RemoveCard(pOutCard->cbCardData, pOutCard->cbCardCount, m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID] + pOutCard->cbCardCount);
|
||
|
||
m_GameLogic.SortCardList(m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID], DDZ_ST_ORDER);
|
||
m_aryPlayer[wViewID]->setHandCardData(m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID]);
|
||
}
|
||
}
|
||
|
||
m_aryPlayer[wViewID]->setHandCardCount(m_aryHandCardCount[wViewID]);
|
||
|
||
//此时游戏结束;
|
||
if (INVALID_CHAIR == pOutCard->wCurrentUser)
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_wCurChairID = pOutCard->wCurrentUser;
|
||
m_wTurnWiner = pOutCard->wOutCardUser;
|
||
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
if (i != wViewID)
|
||
{
|
||
m_aryPlayer[i]->setPassVisible(false);
|
||
m_aryPlayer[i]->setOutCardData(nullptr, 0);
|
||
}
|
||
}
|
||
|
||
//出牌类型为火箭时出牌玩家等于下个出牌玩家;
|
||
if (pOutCard->wOutCardUser == pOutCard->wCurrentUser)
|
||
{
|
||
m_cbTurnCardCount = 0;
|
||
zeromemory(m_cbTurnCardData, sizeof(m_cbTurnCardData));
|
||
}
|
||
else
|
||
{
|
||
m_cbTurnCardCount = pOutCard->cbCardCount;
|
||
memcpy(m_cbTurnCardData, pOutCard->cbCardData, pOutCard->cbCardCount);
|
||
}
|
||
|
||
//更新出牌按钮状态;
|
||
updateButtonsStatus(pOutCard->wCurrentUser, m_cbTimeOutCard);
|
||
|
||
//只剩一张牌时播放音效;
|
||
if (1==m_aryHandCardCount[wViewID])
|
||
{
|
||
playSoundEffect(DDZ_ST_LEFT_ONE_CARD, m_aryPlayer[wViewID]->GetGender());
|
||
}
|
||
}
|
||
|
||
//玩家不出;
|
||
void DDZGameScene::onSubGamePassCard(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_PassCard));
|
||
DDZ_CMD_S_PassCard* pPassCard = (DDZ_CMD_S_PassCard*)pBuffer;
|
||
|
||
//转换不出玩家视图;
|
||
uint16 wViewID = SwitchViewChairID(pPassCard->wPassCardUser);
|
||
m_aryPlayer[wViewID]->setPassVisible(true);
|
||
m_aryPlayer[wViewID]->setOutCardData(nullptr, 0);
|
||
m_aryPlayer[wViewID]->killClock();
|
||
|
||
//播放不出声音;
|
||
playSoundEffect(DDZ_ST_PASS, m_aryPlayer[wViewID]->GetGender());
|
||
|
||
m_wCurChairID = pPassCard->wCurrentUser;
|
||
|
||
//如果一轮结束清空本轮出牌;
|
||
if (pPassCard->cbTurnOver)
|
||
{
|
||
m_wTurnWiner = m_wCurChairID;
|
||
m_cbTurnCardCount = 0;
|
||
zeromemory(m_cbTurnCardData, sizeof(m_cbTurnCardData));
|
||
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
m_aryPlayer[i]->setPassVisible(false);
|
||
m_aryPlayer[i]->setOutCardData(nullptr, 0);
|
||
}
|
||
}
|
||
|
||
//如果是自已不出隐藏出牌按钮;
|
||
if (wViewID == DDZ_SELF_VIEW_ID)
|
||
{
|
||
hideOutCardButtons();
|
||
}
|
||
|
||
//更新出牌按钮状态;
|
||
updateButtonsStatus(pPassCard->wCurrentUser, m_cbTimeOutCard, pPassCard->cbTurnOver>0);
|
||
}
|
||
|
||
//更新叫分按钮;
|
||
void DDZGameScene::updateCallButtons(uint16 wCurChairID, uint8 cbLastCallScore)
|
||
{
|
||
//转换当前玩家视图;
|
||
uint16 wCurViewID = SwitchViewChairID(wCurChairID);
|
||
|
||
//如果当前是自已显示叫分按钮;
|
||
if (DDZ_SELF_VIEW_ID == wCurViewID)
|
||
{
|
||
if (cbLastCallScore < 3 || 255 == cbLastCallScore)
|
||
{
|
||
for (uint8 i = 0; i < 3; i++)
|
||
{
|
||
//显示按钮;
|
||
m_pAryBtnCall[i]->setVisible(true);
|
||
|
||
//小于当前的叫分设置为不可用;
|
||
if (i < cbLastCallScore && 255 != cbLastCallScore)
|
||
{
|
||
m_pAryBtnCall[i]->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
m_pAryBtnCall[i]->setEnabled(true);
|
||
}
|
||
}
|
||
m_pBtnNoCall->setVisible(true);
|
||
}
|
||
|
||
//显示当前玩家倒计时;
|
||
m_aryPlayer[wCurViewID]->showClock(m_cbTimeCallScore, [=](void){
|
||
//SendPassCall();
|
||
});
|
||
}
|
||
else
|
||
{
|
||
m_aryPlayer[wCurViewID]->showClock(m_cbTimeCallScore);
|
||
}
|
||
}
|
||
|
||
//更新按钮状态;
|
||
void DDZGameScene::updateButtonsStatus(uint16 wCurChairID, uint8 cbLeftSeconds, bool bTurnOver/* = false*/)
|
||
{
|
||
//转换当前玩家视图;
|
||
uint16 wCurViewID = SwitchViewChairID(wCurChairID);
|
||
CC_ASSERT(wCurViewID < DDZ_GAME_PLAYER);
|
||
|
||
//如果当前玩家是自已则显示出牌面板;
|
||
if (DDZ_SELF_VIEW_ID == wCurViewID)
|
||
{
|
||
m_aryPlayer[wCurViewID]->setPassVisible(false);
|
||
m_aryPlayer[wCurViewID]->setOutCardData(nullptr, 0);
|
||
|
||
m_pBtnPass->setVisible(true);
|
||
m_pBtnPass->setEnabled(!bTurnOver);
|
||
|
||
m_pBtnTips->setVisible(true);
|
||
|
||
m_pBtnOutCard->setVisible(true);
|
||
//m_pBtnOutCard->setEnabled(false);
|
||
|
||
//搜索出牌;
|
||
tagSearchCardResult mCardResult;
|
||
uint8 cbResultCount = m_GameLogic.SearchOutCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID],
|
||
m_cbTurnCardData, m_cbTurnCardCount, &mCardResult);
|
||
|
||
if (cbResultCount==0)
|
||
{
|
||
m_pSprTips->setVisible(true);
|
||
m_pSprTips->setTexture(DDZ_TIPS_ONLY_PASS_PNG_FILE);
|
||
|
||
m_pBtnTips->setEnabled(false);
|
||
m_pBtnOutCard->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
m_pBtnTips->setEnabled(true);
|
||
|
||
checkOutCardButton();
|
||
}
|
||
|
||
//不出回调函数;
|
||
auto callback = [=](){
|
||
if (getSelfChairID() != m_wCurChairID)
|
||
{
|
||
CC_ASSERT(false);
|
||
return;
|
||
}
|
||
|
||
////如果是自已出牌
|
||
//if (m_wTurnWiner == m_wCurChairID && 0 == m_cbTurnCardCount)
|
||
//{
|
||
// uint8 cbLeftCard = m_aryHandCardCount[DDZ_SELF_VIEW_ID];
|
||
// CC_ASSERT(cbLeftCard > 0 && cbLeftCard <= DDZ_MAX_COUNT);
|
||
|
||
// DDZ_CMD_C_OutCard OutCard;
|
||
// zeromemory(&OutCard, sizeof(DDZ_CMD_C_OutCard));
|
||
// OutCard.cbCardCount = 1;
|
||
// OutCard.cbCardData[0] = m_aryHandCardData[cbLeftCard - 1];
|
||
|
||
// uint16 wHeadSize = sizeof(DDZ_CMD_C_OutCard) - sizeof(OutCard.cbCardData);
|
||
// uint16 wSendSize = wHeadSize + sizeof(uint8)*OutCard.cbCardCount;
|
||
// SendSocketData(DDZ_SUB_C_OUT_CARD, &OutCard, wSendSize);
|
||
//}
|
||
//else
|
||
//{
|
||
// SendSocketData(DDZ_SUB_C_PASS_CARD);
|
||
//}
|
||
};
|
||
|
||
//显示自已倒计时;
|
||
m_aryPlayer[wCurViewID]->showClock(cbLeftSeconds, callback);
|
||
}
|
||
else
|
||
{
|
||
//显示其它玩家倒计时;
|
||
m_aryPlayer[wCurViewID]->showClock(cbLeftSeconds);
|
||
}
|
||
}
|
||
|
||
//隐藏出牌按钮;
|
||
void DDZGameScene::hideOutCardButtons()
|
||
{
|
||
m_pSprTips->setVisible(false);
|
||
|
||
m_pBtnPass->setVisible(false);
|
||
m_pBtnTips->setVisible(false);
|
||
m_pBtnOutCard->setVisible(false);
|
||
}
|
||
|
||
//隐藏出牌按钮;
|
||
void DDZGameScene::checkOutCardButton()
|
||
{
|
||
uint8 aryShootCardData[DDZ_MAX_COUNT] = { 0 };
|
||
uint8 cbShootCardCount = 0;
|
||
m_pHandCardLayer->getShootCardData(aryShootCardData, cbShootCardCount);
|
||
|
||
if (cbShootCardCount==0)
|
||
{
|
||
m_pSprTips->setVisible(true);
|
||
m_pSprTips->setTexture(DDZ_TIPS_CHOOSECARD_PNG_FILE);
|
||
|
||
m_pBtnOutCard->setEnabled(false);
|
||
return;
|
||
}
|
||
|
||
uint8 cbCardType = m_GameLogic.GetCardType(aryShootCardData, cbShootCardCount);
|
||
if (cbCardType == DDZ_CT_ERROR)
|
||
{
|
||
m_pSprTips->setVisible(true);
|
||
m_pSprTips->setTexture(DDZ_TIPS_OUT_ERROR_PNG_FILE);
|
||
|
||
m_pBtnOutCard->setEnabled(false);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
m_pSprTips->setVisible(false);
|
||
}
|
||
|
||
if (m_cbTurnCardCount > 0)
|
||
{
|
||
bool bRet = m_GameLogic.CompareCard(m_cbTurnCardData, aryShootCardData, m_cbTurnCardCount, cbShootCardCount);
|
||
if (bRet)
|
||
{
|
||
m_pBtnOutCard->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
m_pBtnOutCard->setEnabled(false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_pBtnOutCard->setEnabled(true);
|
||
}
|
||
}
|
||
|
||
//更新倍数;
|
||
void DDZGameScene::updateMultipleText()
|
||
{
|
||
int nScoreTimes = 1;
|
||
for (uint8 i = 0; i < m_cbBombCount; i++)
|
||
{
|
||
nScoreTimes *= 2;
|
||
}
|
||
|
||
if (m_PrivateRoomInfo.bGameRuleIdex&eDDZRuleEnum_LimitMultiple8)
|
||
{
|
||
nScoreTimes = __min(nScoreTimes, 8);
|
||
}
|
||
|
||
//显示倍数;
|
||
m_pTxtMultiple->setString(utility::toString<int>(m_cbCallScore*nScoreTimes));
|
||
}
|
||
|
||
//设置基分;
|
||
void DDZGameScene::onSubGameSetBaseScore(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
LONG lBaseScore = *(LONG*)pBuffer;
|
||
}
|
||
|
||
//游戏结束;
|
||
void DDZGameScene::onSubGameEnd(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_GameConclude));
|
||
DDZ_CMD_S_GameConclude* pGameEnd = (DDZ_CMD_S_GameConclude*)pBuffer;
|
||
|
||
m_bGameStart = false;
|
||
|
||
m_pBtnReady->setEnabled(true);
|
||
m_pBtnReady->setVisible(true);
|
||
|
||
std::string aryNickName[DDZ_GAME_PLAYER];
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
uint16 wViewID = SwitchViewChairID(i);
|
||
aryNickName[i] = m_aryPlayer[wViewID]->GetNickName();
|
||
|
||
m_aryPlayer[wViewID]->killClock();
|
||
}
|
||
|
||
//if (m_wLandChairID != INVALID_CHAIR)
|
||
{
|
||
// bool bLandWin = false;
|
||
// if (m_wLandChairID != INVALID_CHAIR)
|
||
// {
|
||
// bLandWin = (pGameEnd->lGameScore[m_wLandChairID]>0);
|
||
// }
|
||
|
||
uint16 wMyChairID = getSelfChairID();
|
||
if (pGameEnd->lGameScore[wMyChairID] > 0)
|
||
{
|
||
playSoundEffect(DDZ_ST_WIN);
|
||
}
|
||
else
|
||
{
|
||
playSoundEffect(DDZ_ST_LOSE);
|
||
}
|
||
|
||
int nScoreTimes = 1;
|
||
for (uint8 i = 0; i < m_cbBombCount; i++)
|
||
{
|
||
nScoreTimes *= 2;
|
||
}
|
||
|
||
if (m_PrivateRoomInfo.bGameRuleIdex&eDDZRuleEnum_LimitMultiple8)
|
||
{
|
||
nScoreTimes = __min(nScoreTimes, 8);
|
||
}
|
||
|
||
//m_pResultLayer->show(m_wLandChairID, wMyChairID, aryNickName, pGameEnd->lGameScore, m_cbCallScore, nScoreTimes, m_cbTimeStartGame);
|
||
m_pResultLayer->show(m_wLandChairID, wMyChairID, aryNickName, pGameEnd, m_cbTimeStartGame);
|
||
}
|
||
|
||
}
|
||
|
||
//玩家托管;
|
||
void DDZGameScene::onSubGameTrustee(const void * pBuffer, uint16 wDataSize)
|
||
{
|
||
//校验数据;
|
||
CC_ASSERT(wDataSize == sizeof(DDZ_CMD_S_Trustee));
|
||
DDZ_CMD_S_Trustee* pTrustee = (DDZ_CMD_S_Trustee*)pBuffer;
|
||
|
||
uint16 wViewID = SwitchViewChairID(pTrustee->wTrusteeUser);
|
||
m_aryTrustee[wViewID] = (pTrustee->bTrustee>0);
|
||
|
||
if (DDZ_SELF_VIEW_ID == wViewID)
|
||
{
|
||
if (m_aryTrustee[wViewID])
|
||
{
|
||
m_pPanelTrustee->setVisible(true);
|
||
m_pHandCardLayer->downAllCard();
|
||
}
|
||
else
|
||
{
|
||
m_pPanelTrustee->setVisible(false);
|
||
}
|
||
}
|
||
}
|
||
|
||
//玩家状态改变;
|
||
void DDZGameScene::OnEventUserStatus(GamePlayer * pPlayer)
|
||
{
|
||
if ( pPlayer->GetChairID() == getSelfChairID() )
|
||
{
|
||
//更新准备按钮状态;
|
||
if (pPlayer->GetUserStatus() >= US_READY)
|
||
{
|
||
m_pBtnReady->setVisible(false);
|
||
}
|
||
}
|
||
|
||
//std::string strIps[DDZ_GAME_PLAYER] = {};
|
||
//std::string strNickNames[DDZ_GAME_PLAYER] = {};
|
||
//
|
||
//// 同IP判断;
|
||
//if ((m_PrivateRoomInfo.dwPlayCout <= 0) && !m_PrivateRoomInfo.bStartGame)
|
||
//{
|
||
// IsSameIp();
|
||
//}
|
||
}
|
||
|
||
// 同IP判断;
|
||
void DDZGameScene::IsSameIp()
|
||
{
|
||
std::string strIps[DDZ_GAME_PLAYER] = {};
|
||
std::string strNickNames[DDZ_GAME_PLAYER] = {};
|
||
|
||
// 同IP判断;
|
||
for (WORD i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
GamePlayer* pPlayer = getPlayerByChairID(i);
|
||
if (pPlayer)
|
||
{
|
||
strIps[i] = pPlayer->GetLogonIp();
|
||
strNickNames[i] = pPlayer->GetNickName();
|
||
}
|
||
}
|
||
|
||
bool bSameIp = false;
|
||
for (WORD i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
WORD wNext = (i + 1) % DDZ_GAME_PLAYER;
|
||
if ((strIps[i] != "") && (strIps[i] == strIps[wNext]))
|
||
{
|
||
bSameIp = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (bSameIp)
|
||
{
|
||
IpTipScene::Instance().show(strNickNames, strIps, DDZ_GAME_PLAYER);
|
||
}
|
||
else if (IpTipScene::Instance().isVisible())
|
||
{
|
||
IpTipScene::Instance().setVisible(false);
|
||
}
|
||
}
|
||
|
||
//玩家金币改变;
|
||
void DDZGameScene::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());
|
||
|
||
((DDZPlayer*)pPlayer)->updateScore();
|
||
}
|
||
|
||
// 玩家坐标;
|
||
Vec2 DDZGameScene::GetPlayerPosByUserID(uint32 dwUserID)
|
||
{
|
||
DDZPlayer* pPlayer = (DDZPlayer*)getPlayerByUserID(dwUserID);
|
||
|
||
if (pPlayer == nullptr)
|
||
{
|
||
return Vec2();
|
||
}
|
||
|
||
const Vec2& ptHeadPos = pPlayer->getHeadPos();
|
||
Vec2 ptWorldPos = pPlayer->convertToWorldSpace(ptHeadPos);
|
||
|
||
return Vec2(ptWorldPos);
|
||
}
|
||
|
||
//调用;
|
||
GamePlayer* DDZGameScene::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);
|
||
DDZPlayer* pPlayer = m_aryPlayer[wViewID];
|
||
pPlayer->setUserItem(pIClientUserItem);
|
||
return pPlayer;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
//椅子号视图转换;
|
||
WORD DDZGameScene::SwitchViewChairID(WORD wChairID)
|
||
{
|
||
//参数判断;
|
||
if (wChairID == INVALID_CHAIR) return INVALID_CHAIR;
|
||
|
||
WORD wSelfChairID = getSelfChairID();
|
||
if (wSelfChairID == INVALID_CHAIR) return INVALID_CHAIR;
|
||
|
||
//转换椅子;
|
||
WORD wChairCount = DDZ_GAME_PLAYER;
|
||
WORD wViewChairID = (wChairID + wChairCount * 3 / 2 - wSelfChairID) % wChairCount;
|
||
|
||
return wViewChairID;
|
||
}
|
||
|
||
//本人进入游戏 GameFrameBase.cpp调用;
|
||
void DDZGameScene::upSelfPlayerInfo()
|
||
{
|
||
log("Self Enter!!");
|
||
|
||
return;
|
||
}
|
||
|
||
//不叫消息;
|
||
void DDZGameScene::SendPassCall()
|
||
{
|
||
DDZ_CMD_C_CallScore call;
|
||
call.cbCallScore = 0xFF;
|
||
SendSocketData(DDZ_SUB_C_CALL_SCORE, &call, sizeof(DDZ_CMD_C_CallScore));
|
||
}
|
||
|
||
//发牌;
|
||
void DDZGameScene::moveSendCardSprite(Sprite* pCardSprite, uint16 wViewID, float fDelayTime)
|
||
{
|
||
float fEndPosX = 0.f, fEndPosY = 0.f;
|
||
|
||
if (wViewID == DDZ_SELF_VIEW_ID)
|
||
{
|
||
Node* pHandCardPanel = m_pHandCardLayer->getParent();
|
||
CC_ASSERT(pHandCardPanel!=nullptr);
|
||
|
||
int iHandCardSpace = m_pHandCardLayer->getHandCardSpace(DDZ_NORMAL_COUNT);
|
||
int iStartPosX = pHandCardPanel->getPositionX();// -(iHandCardWidth / 2);
|
||
|
||
fEndPosX = iStartPosX + pCardSprite->getContentSize().width*0.35f + pCardSprite->getTag() / 3 * iHandCardSpace;
|
||
fEndPosY = pHandCardPanel->getPositionY() + pHandCardPanel->getContentSize().height / 2;
|
||
}
|
||
else
|
||
{
|
||
fEndPosX = m_aryPlayer[wViewID]->getCardPos().x;
|
||
fEndPosY = m_aryPlayer[wViewID]->getCardPos().y;
|
||
}
|
||
|
||
//auto pAction = Spawn::create(MoveTo::create(0.2f, Vec2(fEndPosX, fEndPosY)), RotateBy::create(0.2f, 180), nullptr);
|
||
auto pAction = MoveTo::create(0.2f, Vec2(fEndPosX, fEndPosY));
|
||
|
||
auto fnShowAllCard = [=](Node * pNode)
|
||
{
|
||
pNode->stopAllActions();
|
||
|
||
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID], DDZ_ST_ORDER);
|
||
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DDZ_SELF_VIEW_ID]);
|
||
|
||
//更新叫分按钮;
|
||
updateCallButtons(m_wCurChairID, 255);
|
||
};
|
||
|
||
auto callback = [=](Node* pNode)
|
||
{
|
||
m_aryHandCardCount[wViewID]++;
|
||
m_aryPlayer[wViewID]->setHandCardCount(m_aryHandCardCount[wViewID]);
|
||
|
||
pNode->removeFromParent();
|
||
if (wViewID == DDZ_SELF_VIEW_ID) //玩家自己
|
||
{
|
||
m_pHandCardLayer->addSendCard2Panel();
|
||
|
||
//发牌完成,延时0.2秒显示手牌数据
|
||
if (m_aryHandCardCount[wViewID] == DDZ_NORMAL_COUNT)
|
||
{
|
||
this->runAction(Sequence::create(DelayTime::create(0.2f), CallFuncN::create(fnShowAllCard), nullptr));
|
||
}
|
||
}
|
||
|
||
};
|
||
|
||
Action* pCardAction = Sequence::create(DelayTime::create(fDelayTime), pAction, CallFuncN::create(callback), nullptr);
|
||
pCardSprite->runAction(pCardAction);
|
||
}
|
||
|
||
//选牌回调;
|
||
void DDZGameScene::selectCardCallback(uint8* arySelCardData, uint8 cbSelCardCount)
|
||
{
|
||
//播放点牌音效;
|
||
playSoundEffect(DDZ_ST_CLICK_CARD);
|
||
|
||
if ( getSelfChairID()!=m_wCurChairID )
|
||
{
|
||
return;
|
||
}
|
||
|
||
checkOutCardButton();
|
||
}
|
||
|
||
//显示底牌;
|
||
void DDZGameScene::drawBackCardData()
|
||
{
|
||
for (uint8 i = 0; i < DDZ_BACK_COUNT; i++)
|
||
{
|
||
uint8 cbCardData = m_aryBackCardData[i];
|
||
DDZSmallCardSprite* pCardSprite = DDZSmallCardSprite::create(cbCardData);
|
||
pCardSprite->ignoreAnchorPointForPosition(false);
|
||
pCardSprite->setAnchorPoint(Vec2(0.5f, 0.5f));
|
||
pCardSprite->setPosition(29, 33);
|
||
pCardSprite->setName(StringUtils::format("BackCardSprite%d", i));
|
||
m_pPanelBackCard->addChild(pCardSprite);
|
||
pCardSprite->runAction(MoveBy::create(0.4f, Vec2(i * 59, 0)));
|
||
}
|
||
}
|
||
|
||
//翻转底牌;
|
||
void DDZGameScene::flipBackCard()
|
||
{
|
||
for (uint8 i = 0; i < DDZ_BACK_COUNT; i++)
|
||
{
|
||
CallFuncN* callback = CallFuncN::create([=](Node* pNode){
|
||
DDZSmallCardSprite* pCardSprite = static_cast<DDZSmallCardSprite*>(pNode);
|
||
pCardSprite->updateUIData(m_aryBackCardData[i]);
|
||
});
|
||
|
||
Node* pBackCard = m_pPanelBackCard->getChildByName(StringUtils::format("BackCardSprite%d", i));
|
||
CC_ASSERT(pBackCard!=nullptr);
|
||
Action* pAction = Sequence::create(OrbitCamera::create(0.25f, 1, 0, 0, 90, 0, 0), callback, OrbitCamera::create(0.25f, 1, 0, 270, 90, 0, 0), nullptr);
|
||
pBackCard->runAction(pAction);
|
||
}
|
||
}
|
||
|
||
//播放动画
|
||
void DDZGameScene::playAnimate(uint8 cbCardType, uint16 wFromChair, uint16 wToChair)
|
||
{
|
||
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
|
||
uint16 wFromViewID = SwitchViewChairID(wFromChair);
|
||
uint16 wToViewID = SwitchViewChairID(wToChair);
|
||
DDZPlayer* pFromUserItem = (wFromViewID != INVALID_CHAIR)?m_aryPlayer[wFromViewID]:nullptr;
|
||
DDZPlayer* pToUserItem = (wToViewID != INVALID_CHAIR) ? m_aryPlayer[wToViewID] : nullptr;
|
||
|
||
const Size& winSize = Director::getInstance()->getWinSize();
|
||
|
||
//顺子类型;
|
||
if (cbCardType == DDZ_CT_SINGLE_LINE)
|
||
{
|
||
if (pFromUserItem!=nullptr)
|
||
{
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniLine.plist");
|
||
Sprite* pImgLineAni = Sprite::createWithSpriteFrameName("imgAniLine1.png");
|
||
if (wFromViewID == DDZ_LEFT_VIEW_ID)
|
||
{
|
||
pImgLineAni->setAnchorPoint(Vec2(0.0f, 0.5f));
|
||
}
|
||
else if (wFromViewID == DDZ_SELF_VIEW_ID)
|
||
{
|
||
pImgLineAni->setAnchorPoint(Vec2(0.5f, 0.5f));
|
||
}
|
||
else if (wFromViewID == DDZ_RIGHT_VIEW_ID)
|
||
{
|
||
pImgLineAni->setAnchorPoint(Vec2(1.0f, 0.5f));
|
||
}
|
||
|
||
pImgLineAni->setPosition(pFromUserItem->getOutCardPos());
|
||
pFromUserItem->addChild(pImgLineAni);
|
||
auto pLineAni = Animation::create();
|
||
pLineAni->setDelayPerUnit(0.1f);
|
||
for (uint8 i = 1; i <= 10; i++)
|
||
{
|
||
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniLine%d.png", i));
|
||
pLineAni->addSpriteFrame(pSpriteFrame);
|
||
}
|
||
|
||
pImgLineAni->runAction(Sequence::create(Animate::create(pLineAni), RemoveSelf::create(), nullptr));
|
||
}
|
||
}
|
||
else if (cbCardType == DDZ_CT_DOUBLE_LINE) //连对类型;
|
||
{
|
||
if (pFromUserItem != nullptr)
|
||
{
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniDouble.plist");
|
||
auto pImgDoubleAni = Sprite::createWithSpriteFrameName("imgAniDouble1.png");
|
||
if (wFromViewID == DDZ_LEFT_VIEW_ID)
|
||
{
|
||
pImgDoubleAni->setAnchorPoint(Vec2(0, 0.5f));
|
||
}
|
||
else if (wFromViewID == DDZ_SELF_VIEW_ID)
|
||
{
|
||
pImgDoubleAni->setAnchorPoint(Vec2(0.5f, 0.5f));
|
||
}
|
||
else if (wFromViewID == DDZ_RIGHT_VIEW_ID)
|
||
{
|
||
pImgDoubleAni->setAnchorPoint(Vec2(1.0f, 0.5f));
|
||
}
|
||
|
||
pImgDoubleAni->setPosition(pFromUserItem->getOutCardPos());
|
||
pFromUserItem->addChild(pImgDoubleAni);
|
||
auto pDoubleAni = Animation::create();
|
||
pDoubleAni->setDelayPerUnit(0.15f);
|
||
for (uint8 i = 1; i <= 9; i++)
|
||
{
|
||
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniDouble%d.png", i));
|
||
pDoubleAni->addSpriteFrame(pSpriteFrame);
|
||
}
|
||
|
||
pImgDoubleAni->runAction(Sequence::create(Animate::create(pDoubleAni), RemoveSelf::create(), nullptr));
|
||
}
|
||
}
|
||
else if (cbCardType == DDZ_CT_THREE_LINE) //飞机类型
|
||
{
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniPlane.plist");
|
||
auto pImgPlaneSprite = Sprite::createWithSpriteFrameName("imgAniPlane1.png");
|
||
pImgPlaneSprite->setAnchorPoint(Vec2(1.0f, 0.5f));
|
||
pImgPlaneSprite->setPosition(0.0f, winSize.height/2);
|
||
m_rootNode->addChild(pImgPlaneSprite);
|
||
|
||
auto pImgPlaneAni1 = Sprite::createWithSpriteFrameName("imgAniPlane2.png");
|
||
pImgPlaneAni1->setPosition(390, 130);
|
||
pImgPlaneSprite->addChild(pImgPlaneAni1);
|
||
|
||
auto pPlaneAni1 = Animation::create();
|
||
pPlaneAni1->setDelayPerUnit(0.1f);
|
||
pPlaneAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane2.png"));
|
||
pPlaneAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane3.png"));
|
||
pImgPlaneAni1->runAction(RepeatForever::create(Animate::create(pPlaneAni1)));
|
||
|
||
auto pImgPlaneAni2 = Sprite::createWithSpriteFrameName("imgAniPlane4.png");
|
||
pImgPlaneAni2->setPosition(-55, 150);
|
||
pImgPlaneSprite->addChild(pImgPlaneAni2);
|
||
|
||
auto pPlaneAni2 = Animation::create();
|
||
pPlaneAni2->setDelayPerUnit(0.1f);
|
||
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane4.png"));
|
||
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane5.png"));
|
||
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane6.png"));
|
||
pImgPlaneAni2->runAction(RepeatForever::create(Animate::create(pPlaneAni2)));
|
||
|
||
Action* pAction = Sequence::create(MoveBy::create(1.5f, Vec2(winSize.width + 380, 0)), RemoveSelf::create(), nullptr);
|
||
pImgPlaneSprite->runAction(pAction);
|
||
}
|
||
else if (cbCardType == DDZ_CT_BOMB_CARD ) //炸弹类型
|
||
{
|
||
Vec2 ptEndBombPos = Vec2::ZERO;
|
||
if (wFromChair == wToChair)
|
||
{
|
||
ptEndBombPos.x = winSize.width / 2;
|
||
ptEndBombPos.y = winSize.height / 2;
|
||
}
|
||
else
|
||
{
|
||
if (pToUserItem != nullptr)
|
||
{
|
||
ptEndBombPos = pToUserItem->getHeadPos();
|
||
ptEndBombPos = pToUserItem->convertToWorldSpace(ptEndBombPos);
|
||
}
|
||
}
|
||
|
||
if (pFromUserItem != nullptr )
|
||
{
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniBomb.plist");
|
||
Vec2 ptBeginBombPos = pFromUserItem->getHeadPos();
|
||
ptBeginBombPos = pFromUserItem->convertToWorldSpace(ptBeginBombPos);
|
||
Sprite* pImgBombAni = Sprite::createWithSpriteFrameName("imgAniBomb1.png");
|
||
pImgBombAni->setPosition(ptBeginBombPos);
|
||
m_rootNode->addChild(pImgBombAni);
|
||
|
||
ccBezierConfig tabMovePos = { ptEndBombPos, Vec2(winSize.width / 2, winSize.height / 2), ptBeginBombPos };
|
||
EaseSineIn* pMoveAction = EaseSineIn::create(BezierTo::create(0.5f, tabMovePos));
|
||
Spawn* pSpawnAction = Spawn::create(RotateBy::create(0.5f, 720), pMoveAction, nullptr);
|
||
|
||
auto bombFunc = [=](){
|
||
if (wFromChair == wToChair)
|
||
{
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
if (i != wFromViewID)
|
||
{
|
||
Sprite* pImgBombAni2 = Sprite::createWithSpriteFrameName("imgAniBomb15.png");
|
||
const Vec2& ptHeadPos = m_aryPlayer[i]->getHeadPos();
|
||
pImgBombAni2->setScale(1.4f);
|
||
pImgBombAni2->setPositionX(ptHeadPos.x);
|
||
pImgBombAni2->setPositionY(ptHeadPos.y + 4);
|
||
m_aryPlayer[i]->addChild(pImgBombAni2);
|
||
|
||
auto pBombAni2 = Animation::create();
|
||
pBombAni2->setDelayPerUnit(0.1f);
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb15.png"));
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb16.png"));
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb17.png"));
|
||
|
||
Action* pAction = Sequence::create(Repeat::create(Animate::create(pBombAni2), 2), RemoveSelf::create(), nullptr);
|
||
pImgBombAni2->runAction(pAction);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pToUserItem != nullptr)
|
||
{
|
||
Sprite* pImgBombAni2 = Sprite::createWithSpriteFrameName("imgAniBomb15.png");
|
||
const Vec2& ptHeadPos = pToUserItem->getHeadPos();
|
||
pImgBombAni2->setScale(1.4f);
|
||
pImgBombAni2->setPositionX(ptHeadPos.x);
|
||
pImgBombAni2->setPositionY(ptHeadPos.y + 4);
|
||
pToUserItem->addChild(pImgBombAni2);
|
||
|
||
auto pBombAni2 = Animation::create();
|
||
pBombAni2->setDelayPerUnit(0.1f);
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb15.png"));
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb16.png"));
|
||
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb17.png"));
|
||
|
||
Action* pAction = Sequence::create(Repeat::create(Animate::create(pBombAni2), 2), RemoveSelf::create(), nullptr);
|
||
pImgBombAni2->runAction(pAction);
|
||
}
|
||
}
|
||
};
|
||
|
||
auto callback = [=](){
|
||
//震动/闪屏
|
||
m_rootNode->runAction(ShakeBy::create(0.5f, Vec2(10, 10)));
|
||
Device::vibrate(0.5f);
|
||
|
||
Sprite* pImgBombAni1 = Sprite::createWithSpriteFrameName("imgAniBomb3.png");
|
||
if (wFromChair == wToChair)
|
||
{
|
||
pImgBombAni1->setPosition(ptEndBombPos);
|
||
m_rootNode->addChild(pImgBombAni1);
|
||
}
|
||
else
|
||
{
|
||
if (pToUserItem != nullptr)
|
||
{
|
||
pImgBombAni1->setPosition(pToUserItem->getHeadPos());
|
||
}
|
||
pToUserItem->addChild(pImgBombAni1);
|
||
}
|
||
|
||
auto pBombAni1 = Animation::create();
|
||
pBombAni1->setDelayPerUnit(0.1f);
|
||
for (uint8 i = 3; i <= 14; i++)
|
||
{
|
||
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniBomb%d.png", i));
|
||
pBombAni1->addSpriteFrame(pSpriteFrame);
|
||
}
|
||
|
||
Action* pAction = Sequence::create(Animate::create(pBombAni1), RemoveSelf::create(), CallFunc::create(bombFunc), nullptr);
|
||
pImgBombAni1->runAction(pAction);
|
||
};
|
||
|
||
pImgBombAni->runAction(Sequence::create(pSpawnAction, RemoveSelf::create(), CallFunc::create(callback), nullptr));
|
||
}
|
||
}
|
||
else if (cbCardType == DDZ_CT_MISSILE_CARD) //火箭类型
|
||
{
|
||
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniRocket.plist");
|
||
//auto pImgRocketBg = Sprite::createWithSpriteFrameName("imgAniRocket1.png");
|
||
//pImgRocketBg->setPosition(winSize.width/2,winSize.height/2);
|
||
//pImgRocketBg->setScaleX(winSize.width/pImgRocketBg->getContentSize().width);
|
||
//pImgRocketBg->setScaleY(winSize.height/pImgRocketBg->getContentSize().height);
|
||
//m_rootNode->addChild(pImgRocketBg);
|
||
//pImgRocketBg->runAction(RepeatForever::create(cBlink::create(0.5f,1)));
|
||
Sprite* pImgRocketSprite = Sprite::createWithSpriteFrameName("imgAniRocket2.png");
|
||
pImgRocketSprite->setAnchorPoint(Vec2(0.5f, 0.0f));
|
||
pImgRocketSprite->setPosition(winSize.width / 2, 85);
|
||
m_rootNode->addChild(pImgRocketSprite);
|
||
|
||
Sprite* pImgRocketAni1 = Sprite::createWithSpriteFrameName("imgAniRocket5.png");
|
||
pImgRocketAni1->setAnchorPoint(Vec2(0.5f, 1.0f));
|
||
pImgRocketAni1->setPosition(177, 85);
|
||
pImgRocketSprite->addChild(pImgRocketAni1);
|
||
|
||
auto pRocketAni1 = Animation::create();
|
||
pRocketAni1->setDelayPerUnit(0.1f);
|
||
pRocketAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniRocket5.png"));
|
||
pRocketAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniRocket6.png"));
|
||
pImgRocketAni1->runAction(RepeatForever::create(Animate::create(pRocketAni1)));
|
||
|
||
Sprite* pImgRocketAni2 = Sprite::createWithSpriteFrameName("imgAniRocket3.png");
|
||
pImgRocketAni2->setAnchorPoint(Vec2(0.5f, 1.0f));
|
||
pImgRocketAni2->setPosition(177, -30);
|
||
pImgRocketSprite->addChild(pImgRocketAni2);
|
||
|
||
auto pRocketAni2 = Animation::create();
|
||
pRocketAni2->setDelayPerUnit(0.1f);
|
||
pRocketAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniRocket3.png"));
|
||
pRocketAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniRocket4.png"));
|
||
pImgRocketAni2->runAction(RepeatForever::create(Animate::create(pRocketAni2)));
|
||
|
||
auto callback = [=](){
|
||
pImgRocketSprite->runAction(Sequence::create(MoveBy::create(1.0f, Vec2(0, winSize.height + 610)), RemoveSelf::create(), nullptr));
|
||
};
|
||
|
||
pImgRocketAni2->runAction(Sequence::create(DelayTime::create(0.5f), RemoveSelf::create(), CallFunc::create(callback), nullptr));
|
||
|
||
//震动/闪屏
|
||
m_rootNode->runAction(ShakeBy::create(0.5f, Vec2(10, 10)));
|
||
Device::vibrate(0.5f);
|
||
}
|
||
//else if (cbCardType == DDZ_RLT_SPRING)//春天
|
||
//{
|
||
// pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Ani/AniSpring.plist");
|
||
|
||
// auto pSpringNode = CSLoader::createNodeWithVisibleSize("Games/DDZ/Table/SpringAniScene.csb");
|
||
// m_rootNode->addChild(pSpringNode);
|
||
// auto pMainPanel = pSpringNode->getChildByName("MainPanel");
|
||
// auto img9FloweBg = pMainPanel->getChildByName("img9FloweBg");
|
||
// img9FloweBg->setScale(0.0f);
|
||
// img9FloweBg->stopAllActions();
|
||
// img9FloweBg->runAction(ScaleTo::create(0.3f, 1.2f));
|
||
// for (uint8 i=1; i<=8; i++)
|
||
// {
|
||
// auto flower = pMainPanel->getChildByName(StringUtils::format("imgFlower%d", i));
|
||
// flower->setOpacity(0);
|
||
// flower->runAction(FadeIn::create(0.3f));
|
||
|
||
// flower->runAction(RepeatForever::create(RotateBy::create(0.5f, 180)));
|
||
|
||
// auto star = pMainPanel->getChildByName(StringUtils::format("imgStar%d", i));
|
||
// star->runAction(RepeatForever::create(Blink::create(0.5f, 1)));
|
||
// }
|
||
|
||
// pSpringNode->runAction(Sequence::create(DelayTime::create(1.5f), RemoveSelf::create(), nullptr));
|
||
//}
|
||
}
|
||
|
||
void DDZGameScene::playSoundEffect(const uint8 cbCardType, uint8 cbSex/*=1*/, const uint8 cbData/*=0*/)
|
||
{
|
||
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
|
||
|
||
std::string strSoundFile;
|
||
|
||
if (cbSex > 0)
|
||
{
|
||
cbSex--;
|
||
}
|
||
|
||
switch (cbCardType)
|
||
{
|
||
case DDZ_CT_SINGLE:
|
||
{
|
||
int nFlagID = 0;
|
||
if (CARD_LITTLE_JOKER == cbData) //小王
|
||
{
|
||
nFlagID = 14;
|
||
}
|
||
else if (CARD_LITTLE_JOKER == cbData) //大王
|
||
{
|
||
nFlagID = 15;
|
||
}
|
||
else
|
||
{
|
||
nFlagID = m_GameLogic.GetCardValue(cbData);
|
||
}
|
||
|
||
strSoundFile = StringUtils::format(DDZ_DANZHANG_FILE, cbSex, nFlagID);
|
||
break;
|
||
}
|
||
case DDZ_CT_DOUBLE:
|
||
{
|
||
int nFlagID = m_GameLogic.GetCardValue(cbData);
|
||
strSoundFile = StringUtils::format(DDZ_LIANGZHANG_FILE, cbSex, nFlagID);
|
||
break;
|
||
}
|
||
case DDZ_CT_THREE:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_3ZHANG_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_SINGLE_LINE:
|
||
{
|
||
pAudio->playEffect(DDZ_SHUNZI_EFF_FILE);
|
||
strSoundFile = StringUtils::format(DDZ_SHUNZI_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_DOUBLE_LINE:
|
||
{
|
||
pAudio->playEffect(DDZ_LIANDUI_EFF_FILE);
|
||
strSoundFile = StringUtils::format(DDZ_LIANDUI_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_THREE_LINE:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_FEIJI_FILE, cbSex);
|
||
pAudio->playEffect(DDZ_FEIJI_EFF_FILE);
|
||
break;
|
||
}
|
||
case DDZ_CT_THREE_TAKE_ONE:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_3DAI1_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_THREE_TAKE_TWO:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_3DAI2_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_FOUR_TAKE_ONE:
|
||
case DDZ_CT_FOUR_TAKE_TWO:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_4DAI2_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_BOMB_CARD:
|
||
{
|
||
pAudio->playEffect(DDZ_ZHADAN_EFF_FILE);
|
||
strSoundFile = StringUtils::format(DDZ_ZHADAN_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_CT_MISSILE_CARD:
|
||
{
|
||
pAudio->playEffect(DDZ_HUOJIAN_EFF_FILE);
|
||
strSoundFile = StringUtils::format(DDZ_HUOJIAN_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_ST_DEAL_CARD:
|
||
{
|
||
strSoundFile = DDZ_FAPAI_EFF_FILE;
|
||
break;
|
||
}
|
||
case DDZ_ST_PASS:
|
||
{
|
||
int nSoundID = (rand() % 4) + 1;
|
||
strSoundFile = StringUtils::format(DDZ_PASS_FILE, cbSex, nSoundID);
|
||
break;
|
||
}
|
||
case DDZ_ST_CALL:
|
||
{
|
||
if (cbData <= 3)
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_JIAO_FEN_FILE, cbSex, cbData);
|
||
}
|
||
else
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_BUJIAO_FILE, cbSex);
|
||
}
|
||
break;
|
||
}
|
||
case DDZ_ST_CLICK_CARD:
|
||
{
|
||
strSoundFile = DDZ_DIANPAI_EFF_FILE;
|
||
break;
|
||
}
|
||
case DDZ_ST_OUT_CARD:
|
||
{
|
||
strSoundFile = DDZ_CHUPAI_EFF_FILE;
|
||
break;
|
||
}
|
||
case DDZ_ST_LEFT_ONE_CARD:
|
||
{
|
||
strSoundFile = StringUtils::format(DDZ_ZUIHOUYIZHANG_FILE, cbSex);
|
||
break;
|
||
}
|
||
case DDZ_ST_WIN:
|
||
{
|
||
strSoundFile = DDZ_WIN_EFF_FILE;
|
||
break;
|
||
}
|
||
case DDZ_ST_LOSE:
|
||
{
|
||
strSoundFile = DDZ_LOSE_EFF_FILE;
|
||
break;
|
||
}
|
||
}
|
||
|
||
CC_ASSERT(!strSoundFile.empty());
|
||
pAudio->playEffect(strSoundFile.c_str());
|
||
//SimpleAudioEngine::getInstance()->playEffect(fillpath,isRe);
|
||
}
|
||
|
||
/************************************* 语音 ***********************************************************/
|
||
// 按住语音按钮
|
||
void DDZGameScene::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/DDZ/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();
|
||
}
|
||
}
|
||
|
||
/************************************* 房间信息 ***********************************************************/
|
||
// 房间信息消息
|
||
void DDZGameScene::OnSocketSubPrivateRoomInfo(CMD_GF_Private_Room_Info* pNetInfo)
|
||
{
|
||
m_PrivateRoomInfo = *pNetInfo;
|
||
|
||
m_dwRoomID = pNetInfo->dwRoomNum;
|
||
|
||
string strRoomID = StringUtils::format("房号:%d", m_dwRoomID);
|
||
m_txtPrivateRoomID->setString(utility::a_u8(strRoomID));
|
||
m_txtPrivateRoomID->setVisible(true);
|
||
|
||
uint32 dwPlayCout = __max(pNetInfo->dwPlayCout+1, 1);
|
||
dwPlayCout = __min(dwPlayCout, pNetInfo->dwPlayTotal);
|
||
|
||
string strPlayCount = StringUtils::format("局数:%u/%u 局", dwPlayCout, pNetInfo->dwPlayTotal);
|
||
cocos2d::log("dwPlayCout = %d", pNetInfo->dwPlayCout);
|
||
m_txtPrivatePlayCount->setString(utility::a_u8(strPlayCount.c_str()));
|
||
m_txtPrivatePlayCount->setVisible(true);
|
||
|
||
//if (m_PrivateRoomInfo.bGameRuleIdex&eDDZRuleEnum_LimitMultiple8)
|
||
//{
|
||
// m_txtPrivateMultiple->setString(utility::a_u8("封顶:8 倍"));
|
||
// m_txtPrivateMultiple->setVisible(true);
|
||
// m_strGameRuleInfo = "8倍封顶";
|
||
//}
|
||
//else if (m_PrivateRoomInfo.bGameRuleIdex&eDDZRuleEnum_NoLimitMultiple)
|
||
//{
|
||
// m_txtPrivateMultiple->setString(utility::a_u8("封顶:不封顶"));
|
||
// m_txtPrivateMultiple->setVisible(true);
|
||
|
||
// m_strGameRuleInfo = "不封顶";
|
||
//}
|
||
|
||
if (pNetInfo->bStartGame)
|
||
{
|
||
//如果游戏已开始则隐藏“返回大厅”按钮,显示“解散房间”按钮
|
||
m_btnWeiXin->setVisible(false);
|
||
m_pBtnLeave->setVisible(false);
|
||
m_btnDismissRoom->setVisible(true);
|
||
}
|
||
else
|
||
{
|
||
GamePlayer* pPlayer = getSelfGamePlayer();
|
||
//如果房间主人是自已则隐藏“返回大厅”按钮,显示“解散房间”按钮
|
||
if (pPlayer != nullptr && pNetInfo->dwCreateUserID == pPlayer->GetUserID())
|
||
{
|
||
m_pBtnLeave->setVisible(false);
|
||
m_btnDismissRoom->setVisible(true);
|
||
}
|
||
|
||
//游戏未开始显示微信分享按钮
|
||
m_btnWeiXin->setVisible(true);
|
||
}
|
||
}
|
||
|
||
// 私人场结束
|
||
void DDZGameScene::OnSocketSubPrivateEnd(void* data, int dataSize)
|
||
{
|
||
m_bPrivateEnd = true;
|
||
|
||
// 申请解散界面
|
||
DismissScene::Instance().hide();
|
||
|
||
GamePlayer* players[DDZ_GAME_PLAYER];
|
||
|
||
for (int i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
players[i] = getPlayerByChairID(i);
|
||
}
|
||
|
||
if (m_pPrivateScene)
|
||
{
|
||
DataStream kDataStream(data, dataSize);
|
||
DDZ_CMD_S_Private_End_Info kNetInfo;
|
||
kNetInfo.StreamValue(kDataStream, false);
|
||
|
||
//SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
|
||
//m_pPrivateScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);
|
||
// 欢乐场
|
||
if (m_PrivateRoomInfo.cbUnionGoldOpen == 1)
|
||
{
|
||
//SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
|
||
//m_pPrivateScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);
|
||
m_pPrivateScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo, m_PrivateScoreInfo);
|
||
}
|
||
else
|
||
{
|
||
m_pPrivateScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo.cbBaseScore);
|
||
}
|
||
m_pResultLayer->SetShowPrivate();
|
||
|
||
if (m_pResultLayer->isVisible() == false)
|
||
{
|
||
m_pPrivateScene->pushScene();
|
||
}
|
||
}
|
||
}
|
||
|
||
void DDZGameScene::onEventShowPrivate(cocos2d::EventCustom *event)
|
||
{
|
||
if (m_pPrivateScene)
|
||
{
|
||
m_pPrivateScene->pushScene();
|
||
}
|
||
}
|
||
|
||
// 请求解散房间
|
||
void DDZGameScene::OnSocketSubPrivateDismissInfo(CMD_GF_Private_Dismiss_Info* pNetInfo)
|
||
{
|
||
std::string aryName[DDZ_GAME_PLAYER];
|
||
BYTE aryResult[DDZ_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 < DDZ_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 < DDZ_GAME_PLAYER)
|
||
{
|
||
aryResult[dwChairID] = 2;
|
||
}
|
||
|
||
if (dwMyChairID == dwChairID)
|
||
{
|
||
bHasSelf = true;
|
||
}
|
||
}
|
||
|
||
GamePlayer* players[DDZ_GAME_PLAYER];
|
||
|
||
for (int i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
players[i] = getPlayerByChairID(i);
|
||
}
|
||
|
||
DismissScene::Instance().show(aryResult, players, !bHasSelf, DDZ_GAME_PLAYER);
|
||
|
||
//DismissScene::Instance().show(aryName, aryResult, !bHasSelf);
|
||
}
|
||
|
||
void DDZGameScene::OnSocketSubPrivateDismissResult(CMD_GF_Private_Dismiss_Result* pNetInfo)
|
||
{
|
||
if (pNetInfo->bSuccess && false == m_PrivateRoomInfo.bStartGame)
|
||
{
|
||
Director::getInstance()->popScene();
|
||
}
|
||
else
|
||
{
|
||
DismissScene::Instance().hide();
|
||
}
|
||
}
|
||
|
||
|
||
//////////////////////////////// 游戏录像 //////////////////////////////////////////
|
||
// 开始录像播放
|
||
void DDZGameScene::StartGameRecord()
|
||
{
|
||
if (m_GameRecord.playersVec.size() != DDZ_GAME_PLAYER)
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 初始化房间信息;
|
||
OnSocketSubPrivateRoomInfo(&m_GameRecord.roomInfo);
|
||
|
||
m_iActRecordIdex = 0;
|
||
m_txtRecordPercent->setString(utility::toString(m_iActRecordIdex * 100 / m_GameRecord.actionVec.size(), "%"));
|
||
|
||
schedule(schedule_selector(GameFrameBase::NextRecordAction), m_RecordTime);
|
||
|
||
return;
|
||
}
|
||
|
||
void DDZGameScene::NextRecordAction(float dt)
|
||
{
|
||
cocos2d::log("NextRecordAction...m_iActRecordIdex = %d", m_iActRecordIdex);
|
||
|
||
// 已经播放完了
|
||
if (m_iActRecordIdex >= (int)m_GameRecord.actionVec.size() || !isVisible())
|
||
{
|
||
m_txtRecordPercent->setString("100%");
|
||
m_btnPlay->setVisible(true);
|
||
m_btnPause->setVisible(false);
|
||
|
||
unschedule(schedule_selector(GameFrameBase::NextRecordAction));
|
||
return;
|
||
}
|
||
|
||
// 下一个操作记录;
|
||
tagGameRecordOperateResult& kAction = m_GameRecord.actionVec[m_iActRecordIdex];
|
||
|
||
// 游戏开始;
|
||
if (kAction.wSubCmdID == DDZ_SUB_S_GAME_START)
|
||
{
|
||
m_cbTimeOutCard = 15;
|
||
m_cbTimeCallScore = 15;
|
||
m_cbTimeStartGame = 15;
|
||
m_cbTimeHeadOutCard = 15;
|
||
|
||
m_nCellScore = 1;
|
||
m_pTxtBaseScore->setString(utility::toString(m_nCellScore));
|
||
|
||
DDZ_CMD_Record_GameStart recordStart;
|
||
kAction.subMessageData.popValue(&recordStart, sizeof(DDZ_CMD_Record_GameStart));
|
||
|
||
DDZ_CMD_S_GameStart gameStart;
|
||
zeromemory(&gameStart, sizeof(DDZ_CMD_S_GameStart));
|
||
gameStart.wStartUser = recordStart.wStartUser;
|
||
gameStart.wCurrentUser = recordStart.wCurrentUser;
|
||
|
||
CC_ASSERT(m_wRecordSelfChairID!=INVALID_CHAIR);
|
||
tagGameRecordPlayer& kRecordPlayer = m_GameRecord.playersVec[m_wRecordSelfChairID];
|
||
for (int j = 0; j < DDZ_NORMAL_COUNT; j++)
|
||
{
|
||
gameStart.cbCardData[j] = kRecordPlayer.cbCardData[j];
|
||
}
|
||
|
||
for (uint8 i = 0; i < DDZ_GAME_PLAYER; i++)
|
||
{
|
||
uint16 wChairID = (m_wRecordSelfChairID + i) % DDZ_GAME_PLAYER;
|
||
uint16 wViewID = SwitchViewChairID(wChairID);
|
||
|
||
tagGameRecordPlayer& kRecordPlayer2 = m_GameRecord.playersVec[wChairID];
|
||
for (int j = 0; j < DDZ_NORMAL_COUNT; j++)
|
||
{
|
||
m_aryAllHandCardData[wViewID][j] = kRecordPlayer2.cbCardData[j];
|
||
}
|
||
}
|
||
|
||
onSubGameStart(&gameStart, sizeof(DDZ_CMD_S_GameStart));
|
||
}
|
||
// 玩家叫分;
|
||
else if (kAction.wSubCmdID == DDZ_SUB_S_CALL_SCORE)
|
||
{
|
||
DDZ_CMD_S_CallScore callCard;
|
||
kAction.subMessageData.popValue(&callCard, sizeof(DDZ_CMD_S_CallScore));
|
||
|
||
onSubGameCallScore(&callCard, sizeof(DDZ_CMD_S_CallScore));
|
||
}
|
||
// 确认地主;
|
||
else if (kAction.wSubCmdID == DDZ_SUB_S_BANKER_INFO)
|
||
{
|
||
DDZ_CMD_S_BankerInfo bankerInfo;
|
||
kAction.subMessageData.popValue(&bankerInfo, sizeof(DDZ_CMD_S_BankerInfo));
|
||
|
||
onSubGameBankerInfo(&bankerInfo, sizeof(DDZ_CMD_S_BankerInfo));
|
||
}
|
||
// 玩家出牌;
|
||
else if (kAction.wSubCmdID == DDZ_SUB_S_OUT_CARD)
|
||
{
|
||
DDZ_CMD_S_OutCard outCard;
|
||
kAction.subMessageData.popValue(outCard.cbCardCount);
|
||
kAction.subMessageData.popValue(outCard.wCurrentUser);
|
||
kAction.subMessageData.popValue(outCard.wOutCardUser);
|
||
kAction.subMessageData.popValue(outCard.cbCardData, outCard.cbCardCount);
|
||
|
||
uint16 wHeadSize = sizeof(DDZ_CMD_S_OutCard) - sizeof(outCard.cbCardData);
|
||
onSubGameOutCard(&outCard, (wHeadSize + outCard.cbCardCount*sizeof(uint8)));
|
||
}
|
||
// 玩家放弃出牌;
|
||
else if (kAction.wSubCmdID == DDZ_SUB_S_PASS_CARD)
|
||
{
|
||
DDZ_CMD_S_PassCard passCard;
|
||
kAction.subMessageData.popValue(&passCard, sizeof(DDZ_CMD_S_PassCard));
|
||
onSubGamePassCard(&passCard, sizeof(DDZ_CMD_S_PassCard));
|
||
}
|
||
// 游戏结束;
|
||
else if (kAction.wSubCmdID == DDZ_SUB_S_GAME_CONCLUDE)
|
||
{
|
||
DDZ_CMD_S_GameConclude GameEnd;
|
||
kAction.subMessageData.popValue(&GameEnd, sizeof(DDZ_CMD_S_GameConclude));
|
||
|
||
onSubGameEnd(&GameEnd, sizeof(DDZ_CMD_S_GameConclude));
|
||
}
|
||
|
||
m_iActRecordIdex++;
|
||
m_txtRecordPercent->setString(utility::toString(m_iActRecordIdex * 100 / m_GameRecord.actionVec.size(), "%"));
|
||
}
|
||
|
||
|
||
std::string DDZGameScene::getGameRule(uint32 dwGameRule)
|
||
{
|
||
std::string strGameRule = "经典玩法";
|
||
return strGameRule;
|
||
}
|
||
|