357 lines
8.8 KiB
C++
357 lines
8.8 KiB
C++
|
|
//
|
|||
|
|
// GameScene.cpp
|
|||
|
|
// MyGame
|
|||
|
|
//
|
|||
|
|
// Created by wh on 15/5/26.
|
|||
|
|
//
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#include "WN_GameOver.h"
|
|||
|
|
#include "cocostudio/CocoStudio.h"
|
|||
|
|
#include "ui/CocosGUI.h"
|
|||
|
|
#include "GameDefine.h"
|
|||
|
|
#include "GameMission.h"
|
|||
|
|
#include "ImagicDownManager.h"
|
|||
|
|
#include "JniFun.h"
|
|||
|
|
|
|||
|
|
USING_NS_CC;
|
|||
|
|
using namespace ui;
|
|||
|
|
using namespace std;
|
|||
|
|
|
|||
|
|
using namespace WNMJ_SPACE;
|
|||
|
|
|
|||
|
|
WN_OverNode::WN_OverNode()
|
|||
|
|
{
|
|||
|
|
m_pRootNode = nullptr;
|
|||
|
|
m_wChairID = INVALID_CHAIR;
|
|||
|
|
m_spriteBanker = nullptr;
|
|||
|
|
m_ResultType = nullptr;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WN_OverNode::~WN_OverNode()
|
|||
|
|
{
|
|||
|
|
m_pRootNode = nullptr;
|
|||
|
|
m_wChairID = INVALID_CHAIR;
|
|||
|
|
m_spriteBanker = nullptr;
|
|||
|
|
m_ResultType = nullptr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_OverNode::Init(WORD wChairID)
|
|||
|
|
{
|
|||
|
|
if (nullptr == m_pRootNode) return;
|
|||
|
|
|
|||
|
|
m_wChairID = wChairID; // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>֮<EFBFBD><EFBFBD><F3B2BBBB>ı<EFBFBD>
|
|||
|
|
|
|||
|
|
m_spriteBanker = (Sprite*)m_pRootNode->getChildByName("Banker");
|
|||
|
|
ASSERT(m_spriteBanker);
|
|||
|
|
m_spriteBanker->setVisible(false);
|
|||
|
|
|
|||
|
|
m_txtUserName = (Text*)m_pRootNode->getChildByName("txtUserName");
|
|||
|
|
ASSERT(m_txtUserName);
|
|||
|
|
m_txtUserName->setString("");
|
|||
|
|
|
|||
|
|
m_txtResultType = (Text*)m_pRootNode->getChildByName("txtResultType");
|
|||
|
|
ASSERT(m_txtResultType);
|
|||
|
|
m_txtResultType->setString("");
|
|||
|
|
|
|||
|
|
m_txtScore = (Text*)m_pRootNode->getChildByName("txtScore");
|
|||
|
|
ASSERT(m_txtScore);
|
|||
|
|
m_txtScore->setString("");
|
|||
|
|
|
|||
|
|
m_ResultType = (Sprite*)m_pRootNode->getChildByName("ResultType");
|
|||
|
|
ASSERT(m_ResultType);
|
|||
|
|
m_ResultType->setVisible(false);
|
|||
|
|
|
|||
|
|
m_PanelCard = (Layout*)m_pRootNode->getChildByName("PanelCard");
|
|||
|
|
ASSERT(m_PanelCard);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_OverNode::ShowInfo(tagClientScoreInfo &ScoreInfo)
|
|||
|
|
{
|
|||
|
|
if (m_wChairID != ScoreInfo.wChairID) return;
|
|||
|
|
|
|||
|
|
ReSet();
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
|
m_txtUserName->setString(utility::a_u8(ScoreInfo.szNickName));
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
|
string strScore = utility::ScoreToString(ScoreInfo.lGameScore);
|
|||
|
|
m_txtScore->setString(utility::a_u8(strScore));
|
|||
|
|
|
|||
|
|
// ׯ<><D7AF>
|
|||
|
|
if (m_wChairID == ScoreInfo.wBankerUser)
|
|||
|
|
{
|
|||
|
|
m_spriteBanker->setVisible(true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
|
if (ScoreInfo.dwChiHuKind != CHK_NULL)
|
|||
|
|
{
|
|||
|
|
m_ResultType->setVisible(true);
|
|||
|
|
|
|||
|
|
std::string strHuKind = WN_CGameLogic::getInstance()->GetHuKind(ScoreInfo.dwChiHuKind);
|
|||
|
|
std::string strHuRight = WN_CGameLogic::getInstance()->GetHuRight(ScoreInfo.dwChiHuRight);
|
|||
|
|
|
|||
|
|
std::string strHuType = StringUtils::format("%s %s", strHuKind.c_str(), strHuRight.c_str());
|
|||
|
|
m_txtResultType->setString(utility::a_u8(strHuType));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_ResultType->setVisible(false);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
|
if (m_wChairID == ScoreInfo.wProvideUser)
|
|||
|
|
{
|
|||
|
|
m_txtResultType->setString(utility::a_u8("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (m_PanelCard == nullptr) return;
|
|||
|
|
m_PanelCard->removeAllChildren();
|
|||
|
|
|
|||
|
|
// <20><>ʾ<EFBFBD><CABE>
|
|||
|
|
Point pos;
|
|||
|
|
|
|||
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
for (int w = 0; w < ScoreInfo.cbWeaveItemCount; w++)
|
|||
|
|
{
|
|||
|
|
tagWeaveItem* pWeaveItem = &ScoreInfo.WeaveItemArray[w];
|
|||
|
|
|
|||
|
|
WN_WeaveCard* pWeaveCard = WN_WeaveCard::create();
|
|||
|
|
ASSERT(pWeaveCard);
|
|||
|
|
pWeaveCard->SetCardData(pWeaveItem->cbCenterCard, pWeaveItem->wWeaveKind);
|
|||
|
|
m_PanelCard->addChild(pWeaveCard);
|
|||
|
|
|
|||
|
|
// λ<>ü<EFBFBD><C3BC><EFBFBD>
|
|||
|
|
Point tmpos;
|
|||
|
|
tmpos.x = pos.x + NCMJ_WEAVE_SELF * w;
|
|||
|
|
tmpos.y = pos.y;
|
|||
|
|
pWeaveCard->setPosition(tmpos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool isFindHuCard = false;
|
|||
|
|
uint8 cbShowCardCount = 0;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
for (int c = 0; c < ScoreInfo.cbCardCount; c++)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
if (ScoreInfo.dwChiHuKind != CHK_NULL)
|
|||
|
|
{
|
|||
|
|
// <20><>һ<EFBFBD>źͺ<C5BA><CDBA><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>ʾ;
|
|||
|
|
if (!isFindHuCard && ScoreInfo.cbCardData[c] == ScoreInfo.cbChiHuCard)
|
|||
|
|
{
|
|||
|
|
isFindHuCard = true;
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WN_SparrowCard* pCardSprite = WN_SparrowCard::createWithDirection(ScoreInfo.cbCardData[c], SP_ENDCARD);
|
|||
|
|
ASSERT(pCardSprite);
|
|||
|
|
pCardSprite->setAnchorPoint(Point(0, 0));
|
|||
|
|
m_PanelCard->addChild(pCardSprite);
|
|||
|
|
|
|||
|
|
Point tmpos;
|
|||
|
|
tmpos.x = pos.x + NCMJ_WEAVE_SELF * ScoreInfo.cbWeaveItemCount + cbShowCardCount * NCMJ_OPP_HAND_CARD_WIDHT + 10;
|
|||
|
|
tmpos.y = pos.y;
|
|||
|
|
pCardSprite->setPosition(tmpos);
|
|||
|
|
|
|||
|
|
cbShowCardCount++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
if ((ScoreInfo.dwChiHuKind != CHK_NULL) && isFindHuCard && (0x0 != ScoreInfo.cbChiHuCard))
|
|||
|
|
{
|
|||
|
|
SparrowCard* pCardSprite = WN_SparrowCard::createWithDirection(ScoreInfo.cbChiHuCard, SP_ENDCARD);
|
|||
|
|
ASSERT(pCardSprite);
|
|||
|
|
pCardSprite->setAnchorPoint(Point(0, 0));
|
|||
|
|
m_PanelCard->addChild(pCardSprite);
|
|||
|
|
|
|||
|
|
Point tmpos;
|
|||
|
|
tmpos.x = NCMJ_WEAVE_SELF * ScoreInfo.cbWeaveItemCount + cbShowCardCount * NCMJ_OPP_HAND_CARD_WIDHT + NCMJ_OPP_HAND_CARD_WIDHT;
|
|||
|
|
tmpos.y = 0;
|
|||
|
|
pCardSprite->setPosition(tmpos);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_OverNode::ReSet()
|
|||
|
|
{
|
|||
|
|
ASSERT(m_spriteBanker);
|
|||
|
|
m_spriteBanker->setVisible(false);
|
|||
|
|
m_txtUserName->setString("");
|
|||
|
|
m_txtResultType->setString("");
|
|||
|
|
m_txtScore->setString("");
|
|||
|
|
m_ResultType->setVisible(false);
|
|||
|
|
m_PanelCard->removeAllChildren();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Point WN_OverNode::getPosition()
|
|||
|
|
{
|
|||
|
|
return m_pRootNode->getPosition();
|
|||
|
|
}
|
|||
|
|
//////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
WN_GameOver::WN_GameOver()
|
|||
|
|
{
|
|||
|
|
m_pRootLayout = nullptr; // <20><><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
//m_btnleave = nullptr; // <20>û<EFBFBD><C3BB>뿪
|
|||
|
|
m_btnStart = nullptr; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
|
|||
|
|
m_btnShow = nullptr; // <20><><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
m_wSelfChairID = INVALID_CHAIR;
|
|||
|
|
memset(m_ClientScoreInfoEx, 0x0, sizeof(m_ClientScoreInfoEx));
|
|||
|
|
zeromemory(m_bActiveStatus, sizeof(m_bActiveStatus));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WN_GameOver::~WN_GameOver()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool WN_GameOver::init()
|
|||
|
|
{
|
|||
|
|
if (!Node::init()) {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_pRootLayout = static_cast<Layout*>(CSLoader::createNode("Games/WNMJ/GameOverScene.csb"));
|
|||
|
|
this->addChild(m_pRootLayout);
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC>ť
|
|||
|
|
m_btnStart = (Button*)m_pRootLayout->getChildByName("btnStart");
|
|||
|
|
ASSERT(m_btnStart);
|
|||
|
|
m_btnStart->addClickEventListener([=](Ref *pSender){
|
|||
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(NJSP_START_GAME);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
|
m_btnShow = (Button*)m_pRootLayout->getChildByName("btnShow");
|
|||
|
|
ASSERT(m_btnShow);
|
|||
|
|
m_btnShow->addClickEventListener([=](Ref *pSender){
|
|||
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(WEIXIN_SHOW);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ;
|
|||
|
|
m_btnPrivate = (Button*)m_pRootLayout->getChildByName("btnPrivate");
|
|||
|
|
ASSERT(m_btnPrivate);
|
|||
|
|
m_btnPrivate->setVisible(false);
|
|||
|
|
m_btnPrivate->addClickEventListener([=](Ref *pSender){
|
|||
|
|
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(SHOW_PRIVATE_END);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// ̧ͷ
|
|||
|
|
m_Title = (Sprite*)m_pRootLayout->getChildByName("title");
|
|||
|
|
ASSERT(m_Title);
|
|||
|
|
|
|||
|
|
m_over_player = (Sprite*)m_pRootLayout->getChildByName("over_player");
|
|||
|
|
ASSERT(m_over_player);
|
|||
|
|
|
|||
|
|
std::string ctrl = "";
|
|||
|
|
for (int i = 0; i < GAME_PLAYER; i++)
|
|||
|
|
{
|
|||
|
|
ctrl = __String::createWithFormat("UserNode_%d", i)->getCString();
|
|||
|
|
auto node = (Node*)m_pRootLayout->getChildByName(ctrl);
|
|||
|
|
m_OverNode[i].SetRootNode((ImageView*)node->getChildByName("Image_bg"));
|
|||
|
|
m_OverNode[i].Init(i);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::onEnter()
|
|||
|
|
{
|
|||
|
|
Node::onEnter();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::onEnterTransitionDidFinish()
|
|||
|
|
{
|
|||
|
|
Node::onEnterTransitionDidFinish();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::onExit()
|
|||
|
|
{
|
|||
|
|
Node::onExit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::ResetDlg()
|
|||
|
|
{
|
|||
|
|
m_wSelfChairID = INVALID_CHAIR;
|
|||
|
|
m_wShowChairID = INVALID_CHAIR;
|
|||
|
|
memset(m_ClientScoreInfoEx, 0x0, sizeof(tagClientScoreInfo)*GAME_PLAYER);
|
|||
|
|
zeromemory(m_bActiveStatus, sizeof(m_bActiveStatus));
|
|||
|
|
|
|||
|
|
for (int i = 0; i < GAME_PLAYER; i++)
|
|||
|
|
{
|
|||
|
|
m_OverNode[i].ReSet();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::SetGameResultData(WORD wChairID, tagClientScoreInfo &ScoreInfo, bool isSelfData)
|
|||
|
|
{
|
|||
|
|
cocos2d::log("**************GameOver::SetGameResultData wChairID=%d ********************", wChairID);
|
|||
|
|
if (wChairID < 0 || wChairID > GAME_PLAYER) return;
|
|||
|
|
if (isSelfData) m_wSelfChairID = wChairID;
|
|||
|
|
|
|||
|
|
m_bActiveStatus[wChairID] = true;
|
|||
|
|
|
|||
|
|
CopyMemory(&m_ClientScoreInfoEx[wChairID], &ScoreInfo, sizeof(ScoreInfo));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::ShowGameResult(bool isGameRecord /*= false*/)
|
|||
|
|
{
|
|||
|
|
cocos2d::log("**************GameOver::ShowGameResult ********************");
|
|||
|
|
|
|||
|
|
for (WORD i = 0; i < GAME_PLAYER; i++)
|
|||
|
|
{
|
|||
|
|
cocos2d::log("m_ClientScoreInfoEx[%d].wViewChairID = %d", i, m_ClientScoreInfoEx[i].wChairID);
|
|||
|
|
|
|||
|
|
if (!m_bActiveStatus[i]) continue;
|
|||
|
|
|
|||
|
|
ASSERT(i == m_ClientScoreInfoEx[i].wChairID);
|
|||
|
|
m_OverNode[i].ShowInfo(m_ClientScoreInfoEx[i]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
if (m_wSelfChairID < 0 || m_wSelfChairID > GAME_PLAYER) return;
|
|||
|
|
if (m_wSelfChairID != m_ClientScoreInfoEx[m_wSelfChairID].wChairID) return;
|
|||
|
|
|
|||
|
|
if (m_over_player) m_over_player->setTexture("Games/WNMJ/GamePrivate/over_ku.png");
|
|||
|
|
|
|||
|
|
// ̧ͷ
|
|||
|
|
if (m_ClientScoreInfoEx[m_wSelfChairID].lGameScore > 0)
|
|||
|
|
{
|
|||
|
|
m_Title->setTexture("Games/WNMJ/GamePrivate/over_hupai.png");
|
|||
|
|
|
|||
|
|
if (m_over_player)
|
|||
|
|
{
|
|||
|
|
m_over_player->setTexture("Games/WNMJ/GamePrivate/over_xiao.png");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (m_ClientScoreInfoEx[m_wSelfChairID].lGameScore < 0)
|
|||
|
|
{
|
|||
|
|
m_Title->setTexture("Games/WNMJ/GamePrivate/over_shule.png");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_Title->setTexture("Games/WNMJ/GamePrivate/over_peida.png");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
auto txtGameTime = (Text*)m_pRootLayout->getChildByName("txtGameTime");
|
|||
|
|
ASSERT(txtGameTime != nullptr);
|
|||
|
|
if (txtGameTime)
|
|||
|
|
{
|
|||
|
|
std::string strSystemTime = JniFun::getDataTime();
|
|||
|
|
txtGameTime->setString(utility::a_u8("ʱ<EFBFBD>䣺"+strSystemTime));
|
|||
|
|
txtGameTime->setVisible(!isGameRecord);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WN_GameOver::SetShowPrivate()
|
|||
|
|
{
|
|||
|
|
m_btnStart->setVisible(false);
|
|||
|
|
m_btnPrivate->setVisible(true);
|
|||
|
|
}
|