游戏开始每人发4张牌,由玩家自己组合成两组牌,每组2张,所以在客户端设计一个分牌按扭,按下按扭后4张扑克分为两组
//分牌按钮
LRESULT CGameClientDlg::OnFenPai(WPARAM wParam, LPARAM lParam)
{
//获取扑克
//用户分牌
CMD_S_FenPai myfenpai;
BYTE bTiCount,bNoChuCount;
BYTE NoTiCardData[4];
bNoChuCount=m_GameClientView.m_CardControl[SwitchViewChairID(GetMeChairID())].GetNoShootCard(NoTiCardData,2);
if (bNoChuCount==2)
{
bTiCount=m_GameClientView.m_CardControl[SwitchViewChairID(GetMeChairID())].GetShootCard(myfenpai.bfCardData,2);
bNoChuCount=m_GameClientView.m_CardControl[SwitchViewChairID(GetMeChairID())].GetNoShootCard(myfenpai.bnCardData,2);
if (m_GameLogic.CompareCard(myfenpai.bfCardData,myfenpai.bnCardData,2)==true)
{
BYTE tempcarddata[2];
memcpy(tempcarddata,myfenpai.bfCardData,sizeof(tempcarddata));
memcpy(myfenpai.bfCardData,myfenpai.bnCardData,sizeof(tempcarddata));
memcpy(myfenpai.bnCardData,tempcarddata,sizeof(tempcarddata));
}
m_GameClientView.m_FenCardControl[SwitchViewChairID(GetMeChairID())][0].SetCardData(myfenpai.bfCardData,2);
m_GameClientView.m_FenCardControl[SwitchViewChairID(GetMeChairID())][1].SetCardData(myfenpai.bnCardData,2);
m_GameClientView.m_FenCardControl[SwitchViewChairID(GetMeChairID())][0].SetDisplayFlag(true);
m_GameClientView.m_FenCardControl[SwitchViewChairID(GetMeChairID())][1].SetDisplayFlag(true);
m_GameClientView.m_CardControl[SwitchViewChairID(GetMeChairID())].ShowWindow(false);
SendData(SUB_C_FENPAI,&myfenpai,sizeof(myfenpai));
m_GameClientView.m_btFenpai.ShowWindow(SW_HIDE);
//m_GameClientView.m_btAddGold.ShowWindow(SW_SHOW);
KillGameTimer(IDI_FENPAI_TIME);
}
return 0;
}
分牌后发送SUB_C_FENPAI给服务器
服务器收到SUB_C_FENPAI消息后进行如下处理
//分牌事件
bool CTableFrameSink::OnUserFenPai(BYTE bfCardData[2],BYTE bnCardData[2],WORD wChairID)
{
memcpy(m_bTableCardFenArray[wChairID][0],bfCardData,2);
memcpy(m_bTableCardFenArray[wChairID][1],bnCardData,2);
bBoolfen[wChairID]=true;
bool fenover=true;
for (WORD i=0;i<m_wPlayerCount;i++)
{
if (m_pITableFrame->GetServerUserItem(i)!=NULL)
{
if (bBoolfen==false)
fenover=false;
}
}
if (fenover)
{
m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_XIA_ZHU);
}
return true;
}
收到消息后,把分牌扑克数据保存到服务器数组,然后循环判断是不是都已经分牌了,如果都分牌了,就发送SUB_S_XIA_ZHU消息给客户端,客户端收到后进行下注处理,下一编讲下注处理部