//开始按钮 LRESULT CGameClientDlg::OnStart(WPARAM wParam, LPARAM lParam) { //删除定时器 if(!IsLookonMode())KillGameTimer(IDI_START_GAME); //设置界面 m_GameClientView.DisplayType(false); m_GameClientView.SetBankerUser(INVALID_CHAIR); m_GameClientView.m_btStart.ShowWindow(SW_HIDE); m_GameClientView.m_ScoreView.ShowWindow(SW_HIDE); m_GameClientView.SetUserTableScore(INVALID_CHAIR,0L); for (WORD i=0;i<GAME_PLAYER;i++) { m_GameClientView.ShowScore(i,false); m_GameClientView.m_CardControl[i].SetOX(false); m_GameClientView.SetUserOxValue(i,0xff); m_GameClientView.m_CardControl[i].SetCardData(NULL,0); if(i!=m_wViewChairID[GetMeChairID()])m_GameClientView.m_CardControl[i].SetDisplayFlag(false); m_GameClientView.m_CardControlOx[i].SetCardData(NULL,0); } //加注信息 m_lTurnMaxScore=0L; //m_lTurnLessScore=0L;m_cbHandCardData ZeroMemory(m_lTableScore,sizeof(m_lTableScore)); ZeroMemory(m_bUserOxCard,sizeof(m_bUserOxCard)); ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData)); //发送消息 if(!IsLookonMode())SendUserReady(NULL,0); return 0; }
//时间消息 bool CGameClientDlg::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { switch (nTimerID) { case IDI_OUT_CARD: //用户出牌 { //超时判断 if (nElapse==0) { if ((IsLookonMode()==false)&&(wChairID==GetMeChairID())) AutomatismOutCard(); return false; } //播放声音 if (m_bHandCardCount<m_bTurnCardCount) return true; if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } case IDI_START_GAME: //开始游戏 { if (nElapse==0) { if ((IsLookonMode()==false)&&(wChairID==GetMeChairID())) OnStart(0,0); return false; } if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } } return false; }
//时间消息 bool CGameClientDlg::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { switch(nTimerID) { case IDI_START_GAME: { if (nElapse==0) { if ((IsLookonMode()==false)&&(wChairID==GetMeChairID())) PostMessage(WM_CLOSE,0,0); return true; } if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } case IDI_USER_ADD_SCORE: { if (nElapse==0) { if ((IsLookonMode()==false)&&(wChairID==GetMeChairID())) { //删除定时器 KillGameTimer(IDI_USER_ADD_SCORE); OnGiveUp(0,0); } return true; } if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } } return false; }
//用户放弃 bool CGameClientDlg::OnSubGiveUp(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_GiveUp)) return false; CMD_S_GiveUp * pGiveUp=(CMD_S_GiveUp *)pBuffer; //设置变量 m_cbPlayStatus[pGiveUp->wGiveUpUser]=FALSE; //变量定义 WORD wGiveUpUser=pGiveUp->wGiveUpUser; BYTE cbCardData[MAX_COUNT]={0,0,0,0,0}; WORD wViewChairID=SwitchViewChairID(wGiveUpUser); BYTE cbCardCount=(BYTE)m_GameClientView.m_CardControl[wViewChairID].GetCardCount(); //设置扑克 m_GameClientView.m_CardControl[wViewChairID].SetPositively(false); m_GameClientView.m_CardControl[wViewChairID].SetDisplayHead(false); m_GameClientView.m_CardControl[wViewChairID].SetCardData(cbCardData,cbCardCount); //状态设置 if ((IsLookonMode()==false)&&(pGiveUp->wGiveUpUser==GetMeChairID())) { HideScoreControl(); SetGameStatus(GS_FREE); } //环境设置 if (wGiveUpUser==GetTimeChairID()) KillGameTimer(IDI_USER_ADD_SCORE); if ((IsLookonMode()==true)||(wGiveUpUser!=GetMeChairID())) PlayGameSound(AfxGetInstanceHandle(),TEXT("GIVE_UP")); return true; }
//游戏开始 bool CGameClientDlg::OnSubGameStart(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_GameStart)); if (wDataSize!=sizeof(CMD_S_GameStart)) return false; //消息处理 CMD_S_GameStart * pGameStart=(CMD_S_GameStart *)pBuffer; m_wBlackUser=pGameStart->wBlackUser; m_wCurrentUser=pGameStart->wBlackUser; m_cbChessColor=(m_wBlackUser==GetMeChairID())?BLACK_CHESS:WHITE_CHESS; //设置时间 m_wLeftClock[0]=m_wLeftClock[1]=pGameStart->wGameClock; m_GameClientView.SetGameClock(pGameStart->wGameClock); m_GameClientView.SetUserClock(SwitchViewChairID(0),m_wLeftClock[0]); m_GameClientView.SetUserClock(SwitchViewChairID(1),m_wLeftClock[1]); //设置变量 m_cbXSourcePos=255; m_cbYSourcePos=255; m_cbXTargetPos=255; m_cbYTargetPos=255; //设置棋盘 m_GameLogic.ResetChessBorad(); m_GameClientView.m_ChessBorad.SetChessColor(m_cbChessColor); m_GameClientView.m_ChessBorad.SetChessBorad(m_GameLogic.m_ChessBorad); //设置界面 m_GameClientView.m_btPreserve.EnableWindow(TRUE); m_GameClientView.m_GameScoreWnd.ShowWindow(SW_HIDE); m_GameClientView.SetBlackUser(SwitchViewChairID(m_wBlackUser)); //全部玩家 if (IsLookonMode()==false) { m_GameClientView.m_btStart.EnableWindow(FALSE); m_GameClientView.m_btPeace.EnableWindow(TRUE); m_GameClientView.m_btGiveUp.EnableWindow(TRUE); } //玩家设置 if ((IsLookonMode()==false)&&(m_wCurrentUser==GetMeChairID())) { ActiveGameFrame(); CancelChessSelect(); m_GameClientView.m_ChessBorad.SetPositively(true); } //设置定时器 SetTimer(IDI_GAME_TIMER,1000,NULL); //播放声音 PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_START")); return true; }
//发牌完成 LRESULT CGameClientDlg::OnSendCardFinish(WPARAM wParam, LPARAM lParam) { //响应扑克 WORD wMeChairID=GetMeChairID(); if(!IsLookonMode())m_GameClientView.m_CardControl[MY_VIEW_CHAIRID].SetPositively(true); //设置时间 SetGameTimer(wMeChairID,IDI_NULLITY,TIME_USER_OPEN_CARD); //过虑观看 if (IsLookonMode())return 0; //特殊牌型 BYTE bCardType = m_GameLogic.GetCardType(m_cbHandCardData[wMeChairID],MAX_COUNT); if(bCardType >= OX_THREE_SAME) { //提示信息 m_GameClientView.SetUserAction(true); //用户信息 WORD wViewChairID=m_wViewChairID[wMeChairID]; m_GameClientView.m_CardControl[wViewChairID].ShootAllCard(false); //发送消息 CMD_C_OxCard OxCard; OxCard.bOX=TRUE; SendData(SUB_C_OPEN_CARD,&OxCard,sizeof(OxCard)); //预先处理 m_GameClientView.ShowOpenCard(wViewChairID); m_GameClientView.m_CardControl[wViewChairID].SetPositively(false); //显示牌型 m_GameClientView.SetUserOxValue(wViewChairID,bCardType); //保存牛信息 m_bUserOxCard[wMeChairID]=OxCard.bOX; return 0; } //控件处理 if(!m_GameClientView.m_CardControl[MY_VIEW_CHAIRID].GetKey()) { m_GameClientView.m_btOx.EnableWindow(FALSE); } m_GameClientView.m_btOpenCard.ShowWindow(SW_SHOW); m_GameClientView.m_btHintOx.ShowWindow(SW_SHOW); //等待标志 m_GameClientView.m_bOpenCard=true; //时间设置 SetTimer(IDI_TIME_OPEN_CARD,TIME_USER_OPEN_CARD*1000,NULL); return 0; }
//放弃出牌 bool CGameClientDlg::OnSubPassCard(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_PassCard)) return false; CMD_S_PassCard * pPassCard=(CMD_S_PassCard *)pBuffer; //删除定时器 KillGameTimer(IDI_OUT_CARD); //玩家设置 if ((IsLookonMode()==true)||(pPassCard->wPassUser!=GetMeChairID())) { WORD wViewChairID=SwitchViewChairID(pPassCard->wPassUser); m_GameClientView.SetPassFlag(wViewChairID,true); m_GameClientView.m_UserCardControl[wViewChairID].SetCardData(NULL,0); } //一轮判断 if (pPassCard->bNewTurn==TRUE) { m_bTurnCardCount=0; m_bTurnOutType=CT_ERROR; memset(m_bTurnCardData,0,sizeof(m_bTurnCardData)); } //设置界面 WORD wViewChairID=SwitchViewChairID(pPassCard->wCurrentUser); m_GameClientView.SetPassFlag(wViewChairID,false); m_GameClientView.m_UserCardControl[wViewChairID].SetCardData(NULL,0); //玩家设置 if ((IsLookonMode()==false)&&(pPassCard->wCurrentUser==GetMeChairID())) { ActiveGameFrame(); m_GameClientView.m_btOutCard.ShowWindow(SW_SHOW); m_GameClientView.m_btPassCard.ShowWindow(SW_SHOW); m_GameClientView.m_btOutPrompt.ShowWindow(SW_SHOW); m_GameClientView.m_btPassCard.EnableWindow((m_bTurnCardCount>0)?TRUE:FALSE); m_GameClientView.m_btOutCard.EnableWindow((VerdictOutCard()==true)?TRUE:FALSE); m_GameClientView.m_btOutPrompt.EnableWindow(m_bTurnCardCount>0?TRUE:FALSE); } //播放声音 if ((IsLookonMode()==true)||(pPassCard->wPassUser!=GetMeChairID())) PlayGameSound(AfxGetInstanceHandle(),TEXT("OUT_CARD")); //设置时间 if (m_bTurnCardCount!=0) { WORD wTimeCount=30; if (m_GameClientView.m_btPassCard.IsWindowEnabled()) wTimeCount=10; SetGameTimer(pPassCard->wCurrentUser,IDI_OUT_CARD,wTimeCount); } else SetGameTimer(pPassCard->wCurrentUser,IDI_OUT_CARD,30); return true; }
//发送扑克 bool CGameClientDlg::OnSubSendCard(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_SendCard)); if (wDataSize!=sizeof(CMD_S_SendCard)) return false; //变量定义 CMD_S_SendCard * pSendCard=(CMD_S_SendCard *)pBuffer; //设置数据 m_bHandCardCount=CountArray(pSendCard->bCardData); CopyMemory(m_bHandCardData,pSendCard->bCardData,sizeof(pSendCard->bCardData)); for (WORD i=0;i<GAME_PLAYER;i++) m_bCardCount[i]=CountArray(pSendCard->bCardData); //设置界面 for (WORD i=0;i<GAME_PLAYER;i++) { m_GameClientView.SetLandScore(i,0); m_GameClientView.SetPassFlag(i,false); m_GameClientView.SetCardCount(i,m_bCardCount[i]); m_GameClientView.m_UserCardControl[i].SetCardData(NULL,0); } if (IsLookonMode()==true) { m_GameClientView.SetLandUser(INVALID_CHAIR,0); m_GameClientView.m_ScoreView.ShowWindow(SW_HIDE); m_GameClientView.m_LeaveCardControl[0].SetCardData(NULL,0); m_GameClientView.m_LeaveCardControl[1].SetCardData(NULL,0); } m_GameClientView.ShowLandTitle(true); m_GameClientView.SetBombTime(m_wBombTime); //设置扑克 BYTE bBackCard[LEFT_CARD_NUM /*3*/]={0,0,0,0}; m_GameClientView.m_HandCardControl.SetCardData(pSendCard->bCardData, ONE_USER_GET_CARD_NUM /*17*/); m_GameClientView.m_BackCardControl.SetCardData(bBackCard,CountArray(bBackCard)); if (IsLookonMode()==true) m_GameClientView.m_HandCardControl.SetDisplayFlag(false); //当前玩家 if ((IsLookonMode()==false)&&(pSendCard->wCurrentUser==GetMeChairID())) { ActiveGameFrame(); m_GameClientView.m_btOneScore.ShowWindow(SW_SHOW); m_GameClientView.m_btTwoScore.ShowWindow(SW_SHOW); m_GameClientView.m_btThreeScore.ShowWindow(SW_SHOW); m_GameClientView.m_btGiveUpScore.ShowWindow(SW_SHOW); } //播放声音 PlayGameSound(AfxGetInstanceHandle(),TEXT("KAI_WA")); //设置时间 SetGameTimer(pSendCard->wCurrentUser,IDI_LAND_SCORE,30); return true; }
//移动棋子 bool CGameClientDlg::OnSubMoveChess(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_MoveChess)); if (wDataSize!=sizeof(CMD_S_MoveChess)) return false; //消息处理 CMD_S_MoveChess * pMoveChess=(CMD_S_MoveChess *)pBuffer; m_wCurrentUser=pMoveChess->wCurrentUser; //设置时间 CopyMemory(m_wLeftClock,pMoveChess->wLeftClock,sizeof(m_wLeftClock)); //记录棋谱 WORD wMoveUser=(pMoveChess->wCurrentUser+1)%GAME_PLAYER; //设置界面 m_ShamView=false; WORD wMeChairID=GetMeChairID(); if ((IsLookonMode()==true)||(wMoveUser!=wMeChairID)) { //变量定义 BYTE cbXSourcePos=pMoveChess->cbXSourcePos,cbYSourcePos=pMoveChess->cbYSourcePos; BYTE cbXTargetPos=pMoveChess->cbXTargetPos,cbYTargetPos=pMoveChess->cbYTargetPos; //播放声音 const tagChessItem * pSourceChessItem=m_GameLogic.GetChessItem(cbXSourcePos,cbYSourcePos); const tagChessItem * pTargetChessItem=m_GameLogic.GetChessItem(cbXTargetPos,cbYTargetPos); if ((pTargetChessItem!=NULL)&&(pSourceChessItem->cbColor!=pTargetChessItem->cbColor)) { if (pSourceChessItem->cbColor==m_cbChessColor) PlayGameSound(AfxGetInstanceHandle(),TEXT("CHESS_EAT")); else PlayGameSound(AfxGetInstanceHandle(),TEXT("CHESS_DEAD")); } else PlayGameSound(AfxGetInstanceHandle(),TEXT("PLACE_CHESS")); //移动棋子 m_GameLogic.MoveChess(cbXSourcePos,cbYSourcePos,cbXTargetPos,cbYTargetPos,pMoveChess->cbSwitchChess); //设置棋盘 m_GameClientView.m_ChessBorad.SetChessBorad(m_GameLogic.m_ChessBorad); m_GameClientView.m_ChessBorad.SetChessFrame(cbXSourcePos,cbYSourcePos,cbXTargetPos,cbYTargetPos); } //玩家设置 if ((IsLookonMode()==false)&&(pMoveChess->wCurrentUser==wMeChairID)) { //设置界面 ActiveGameFrame(); CancelChessSelect(); m_GameClientView.m_ChessBorad.SetPositively(true); m_GameClientView.m_ChessBorad.SetSelectChess(m_cbXSourcePos,m_cbYSourcePos); } return true; }
//悔棋结果 bool CGameClientDlg::OnSubRegretResult(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_RegretResult)); if (wDataSize!=sizeof(CMD_S_RegretResult)) return false; //变量定义 CMD_S_RegretResult * pRegretResult=(CMD_S_RegretResult *)pBuffer; CopyMemory(m_wLeftClock,pRegretResult->wLeftClock,sizeof(m_wLeftClock)); //调整次数 if (m_ShamView==true) { m_ShamView=false; pRegretResult->cbRegretCount++; } //设置棋盘 m_GameLogic.RegretChess(pRegretResult->cbRegretCount); m_GameClientView.m_ChessBorad.SetChessBorad(m_GameLogic.m_ChessBorad); //设置框架 const tagChessManual * pChessManual=m_GameLogic.GetLastChessManual(); if (pChessManual!=NULL) { BYTE cbXPosStart=pChessManual->cbXSourceChessPos; BYTE cbYPosStart=pChessManual->cbYSourceChessPos; BYTE cbXPosTerminal=pChessManual->cbXTargetChessPos; BYTE cbYPosTerminal=pChessManual->cbYTargetChessPos; m_GameClientView.m_ChessBorad.SetChessFrame(cbXPosStart,cbYPosStart,cbXPosTerminal,cbYPosTerminal); } else m_GameClientView.m_ChessBorad.SetChessFrame(255,255,255,255); //玩家设置 WORD wMeChairID=GetMeChairID(); m_wCurrentUser=pRegretResult->wCurrentUser; if ((IsLookonMode()==false)&&(pRegretResult->wCurrentUser==wMeChairID)) { ActiveGameFrame(); CancelChessSelect(); m_GameClientView.m_ChessBorad.SetPositively(true); } //悔棋控制 if (IsLookonMode()==false) { WORD wStepCount=m_GameLogic.GetStepCount((GetMeChairID()==m_wBlackUser)?BLACK_CHESS:WHITE_CHESS); if (wStepCount==0) m_GameClientView.m_btRegret.EnableWindow(FALSE); if ((wStepCount>0)&&(pRegretResult->wRegretUser==wMeChairID)) m_GameClientView.m_btRegret.EnableWindow(TRUE); } return true; }
//游戏开始 bool CGameClientDlg::OnSubGameStart(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_SendCard)); if (wDataSize!=sizeof(CMD_S_SendCard)) return false; //消息处理 CMD_S_SendCard * pGameStart=(CMD_S_SendCard *)pBuffer; //设置变量 m_bTurnCardCount=0; m_bTurnOutType=CT_INVALID; ZeroMemory(m_bTurnCardData,sizeof(m_bTurnCardData)); //设置界面 m_GameClientView.SetCardCount(SwitchViewChairID(pGameStart->wCurrentEnthronement),m_bCardCount[pGameStart->wCurrentEnthronement]); ////地主设置 //if (pGameStart->wCurrentEnthronement==GetMeChairID()) //{ // m_GameClientView.m_HandCardControl.SetCardData(m_bHandCardData,m_bHandCardCount); //} //玩家设置 if (IsLookonMode()==false) m_GameClientView.m_HandCardControl.SetPositively(true); //当前玩家 if ((IsLookonMode()==false)&&(pGameStart->wCurrentUser==GetMeChairID())) { ActiveGameFrame(); m_GameClientView.m_btOutCard.EnableWindow(FALSE); m_GameClientView.m_btOutCard.ShowWindow(SW_SHOW); m_GameClientView.m_btPassCard.EnableWindow(FALSE); m_GameClientView.m_btPassCard.ShowWindow(SW_SHOW); m_GameClientView.m_btAutoOutCard.ShowWindow(SW_SHOW); m_GameClientView.m_btAutoOutCard.EnableWindow(FALSE); } // m_GameClientView.m_LeaveCardControl[0].SetBackCard(m_bCardCount[0]);//.SetCardData(m_GameClientView.m_byZerodata,m_bCardCount[0]); // m_GameClientView.m_LeaveCardControl[1].SetBackCard(m_bCardCount[1]);//.SetCardData(m_GameClientView.m_byZerodata,m_bCardCount[1]); //播放声音 PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_START")); //设置时间 SetGameTimer(pGameStart->wCurrentUser,IDI_OUT_CARD,30); m_GameClientView.m_bGamePlaying = true; return true; }
//定时器消息 void CGameClientDlg::OnTimer(UINT nIDEvent) { if ((nIDEvent==IDI_MOST_CARD)&&(m_wMostUser!=INVALID_CHAIR)) { //变量定义 WORD wCurrentUser=m_wMostUser; m_wMostUser=INVALID_CHAIR; //删除定时器 KillTimer(IDI_MOST_CARD); //设置界面 m_GameClientView.SetPassFlag(INVALID_CHAIR,false); for (WORD i=0;i<GAME_PLAYER;i++) m_GameClientView.m_UserCardControl[i].SetCardData(NULL,0); //玩家设置 if ((IsLookonMode()==false)&&(wCurrentUser==GetMeChairID())) { ActiveGameFrame(); m_GameClientView.m_btOutCard.ShowWindow(SW_SHOW); m_GameClientView.m_btPassCard.ShowWindow(SW_SHOW); m_GameClientView.m_btPassCard.EnableWindow(FALSE); m_GameClientView.m_btAutoOutCard.ShowWindow(SW_SHOW); m_GameClientView.m_btAutoOutCard.EnableWindow(FALSE); m_GameClientView.m_btOutCard.EnableWindow((VerdictOutCard()==true)?TRUE:FALSE); } //设置时间 SetGameTimer(wCurrentUser,IDI_OUT_CARD,30); return; } __super::OnTimer(nIDEvent); }
//显示控制 bool CGameClientDlg::ShowOperateControl(BYTE cbUserAction, BYTE cbActionCard) { //变量定义 tagGangCardResult GangCardResult; ZeroMemory(&GangCardResult,sizeof(GangCardResult)); //杠牌判断 if ((cbUserAction&WIK_GANG)!=0) { //桌面杆牌 if (cbActionCard!=0) { GangCardResult.cbCardCount=1; GangCardResult.cbCardData[0]=cbActionCard; } //自己杆牌 if (cbActionCard==0) { WORD wMeChairID=GetMeChairID(); m_GameLogic.AnalyseGangCard(m_cbCardIndex,m_WeaveItemArray[wMeChairID],m_cbWeaveCount[wMeChairID],GangCardResult); } } //显示界面 if (IsLookonMode()==false) m_GameClientView.m_ControlWnd.SetControlInfo(cbActionCard,cbUserAction,GangCardResult); return true; }
//旁观控制 bool __cdecl CClientKernel::AllowUserLookon(DWORD dwUserID, bool bAllowLookon) { //设置变量 if (dwUserID==0L) { m_bAllowUserLookon=bAllowLookon; AfxGetApp()->WriteProfileInt(TEXT("GameOption"),TEXT("AllowLookon"),(m_bAllowUserLookon==true)?TRUE:FALSE); } //发送消息 if (IsLookonMode()==false) { //构造数据 CMD_GF_LookonControl LookonControl; ZeroMemory(&LookonControl,sizeof(LookonControl)); //设置变量 LookonControl.dwUserID=dwUserID; LookonControl.bAllowLookon=(bAllowLookon==true)?TRUE:FALSE; //发送消息 SendSocketData(MDM_GF_FRAME,SUB_GF_LOOKON_CONTROL,&LookonControl,sizeof(LookonControl)); } return true; }
//连接处理 bool CGameClientDlg::OnSubLink(const void * pBuffer, WORD wDataSize) { if (wDataSize!=sizeof(CMD_S_Link)) return false; CMD_S_Link * pslink=(CMD_S_Link *)pBuffer; WORD id = SwitchViewChairID(pslink->nCurrentPlayer); if(id ==2) { if(IsLookonMode()) { m_GameClientView.LinkPro(CPoint(pslink->nFirst_X,pslink->nFirst_Y), CPoint(pslink->nEnd_X,pslink->nEnd_Y),id); //播放声音 OnPlayMusic(IDM_MUSIC_LINK,0); OnPlayMusic(IDM_MUSIC_BOMB,0); } else { if(pslink->nPropType != ERROR_ALL) { m_GameClientView.m_MyListView.m_ImplementCount[pslink->nPropType] = pslink->nPropCount; m_GameClientView.m_MyListView.UpdateImplementState(); } } } else { m_GameClientView.OtherPlayLinkPro(CPoint(pslink->nFirst_X,pslink->nFirst_Y), CPoint(pslink->nEnd_X,pslink->nEnd_Y),id); } return true; }
//重列处理 bool CGameClientDlg::OnSubRealign(const void * pBuffer, WORD wDataSize) { if (wDataSize!=sizeof(CMD_S_Realign)) return false; CMD_S_Realign * psRealign=(CMD_S_Realign *)pBuffer; WORD id = SwitchViewChairID(psRealign->nCurrentPlayer); if(id ==2) { if(IsLookonMode()) { memcpy(m_GameClientView.m_wndD3D.m_Chess[id],psRealign->nChess , sizeof(psRealign->nChess)); m_GameClientView.m_wndD3D.UpdateBackSurface(); //效果 m_GameClientView.m_wndD3D.m_PointSprite_Star.On(); //播放声音 OnPlayMusic(IDM_MUSIC_FLYSTAR,0); } else { m_GameClientView.m_MyListView.m_ImplementCount[PROP_RESET] = psRealign->nPropCount; m_GameClientView.m_MyListView.UpdateImplementState(); } } else { memcpy(m_GameClientView.m_wndD3D.m_Chess[id],psRealign->nChess , sizeof(psRealign->nChess)); m_GameClientView.m_wndD3D.UpdateChessSmall(id); } return true; }
//用户加注 bool CGameClientDlg::OnSubPlaceJetton(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_PlaceJetton)); if (wDataSize!=sizeof(CMD_S_PlaceJetton)) return false; //消息处理 CMD_S_PlaceJetton * pPlaceJetton=(CMD_S_PlaceJetton *)pBuffer; //加注界面 m_GameClientView.PlaceUserJetton(pPlaceJetton->cbJettonArea,pPlaceJetton->lJettonScore); //播放声音 if (IsEnableSound()) { if (pPlaceJetton->wChairID!=GetMeChairID() || IsLookonMode()) { if (pPlaceJetton->lJettonScore==5000000) PlayGameSound(AfxGetInstanceHandle(),TEXT("ADD_GOLD_EX")); else PlayGameSound(AfxGetInstanceHandle(),TEXT("ADD_GOLD")); m_DTSDCheer[rand()%3].Play(); } } return true; }
//申请消息 LRESULT CGameClientDlg::OnApplyBanker(WPARAM wParam, LPARAM lParam) { //合法判断 tagUserData const *pMeUserData = GetUserData( GetMeChairID() ); if (pMeUserData->lScore < m_lApplyBankerCondition) return true; //旁观判断 if (IsLookonMode()) return true; //转换变量 bool bApplyBanker = wParam ? true:false; //当前判断 if (m_wCurrentBanker == GetMeChairID() && bApplyBanker) return true; if (bApplyBanker) { //发送消息 SendData(SUB_C_APPLY_BANKER, NULL, 0); m_bMeApplyBanker=true; } else { //发送消息 SendData(SUB_C_CANCEL_BANKER, NULL, 0); m_bMeApplyBanker=false; } //设置按钮 UpdateButtonContron(); return true; }
//取消做庄 bool CGameClientDlg::OnSubUserCancelBanker(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_CancelBanker)); if (wDataSize!=sizeof(CMD_S_CancelBanker)) return false; //消息处理 CMD_S_ApplyBanker * pCancelyBanker=(CMD_S_ApplyBanker *)pBuffer; //获取玩家 tagUserData const *pUserData=GetUserData(pCancelyBanker->wApplyUser); //删除玩家 tagApplyUser ApplyUser; ApplyUser.strUserName=pUserData->szName; ApplyUser.lUserScore=pUserData->lScore; m_GameClientView.m_ApplyUser.DeleteUser(ApplyUser); //自己判断 if (IsLookonMode()==false && GetMeChairID()==pCancelyBanker->wApplyUser) m_bMeApplyBanker=false; //更新控件 UpdateButtonContron(); return true; }
//用户叫庄 bool CGameClientDlg::OnSubCallBanker(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_CallBanker)) return false; CMD_S_CallBanker * pCallBanker=(CMD_S_CallBanker *)pBuffer; //首次叫庄 if(pCallBanker->bFirstTimes) { //用户信息 for (WORD i=0;i<GAME_PLAYER;i++) { //视图位置 m_wViewChairID[i]=SwitchViewChairID(i); //获取用户 const tagUserData * pUserData=GetUserData(i); if (pUserData==NULL) continue; //游戏信息 m_cbPlayStatus[i]=TRUE; //用户名字 lstrcpyn(m_szAccounts[i],pUserData->szName,CountArray(m_szAccounts[i])); } //旁观者清理数据 if (IsLookonMode()) OnStart(0,0); } //删除定时器/按钮 if(m_GameClientView.m_btIdler.IsWindowVisible()==TRUE) { KillGameTimer(IDI_CALL_BANKER); m_GameClientView.m_btIdler.ShowWindow(SW_HIDE); m_GameClientView.m_btBanker.ShowWindow(SW_HIDE); } //用户控件显示 if(IsCurrentUser(pCallBanker->wCallBanker)) { m_GameClientView.m_btBanker.ShowWindow(SW_SHOW); m_GameClientView.m_btIdler.ShowWindow(SW_SHOW); } //等待标志 WORD wViewID=m_wViewChairID[pCallBanker->wCallBanker]; m_GameClientView.SetWaitCall((BYTE)wViewID); //实际定时器 if(pCallBanker->wCallBanker==GetMeChairID()) { SetGameTimer(pCallBanker->wCallBanker,IDI_CALL_BANKER,TIME_USER_CALL_BANKER); } else SetGameTimer(pCallBanker->wCallBanker,IDI_NULLITY,TIME_USER_CALL_BANKER); return true; }
//切换庄家 bool CGameClientDlg::OnSubChangeBanker(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_ChangeBanker)); if (wDataSize!=sizeof(CMD_S_ChangeBanker)) return false; //消息处理 CMD_S_ChangeBanker * pChangeBanker=(CMD_S_ChangeBanker *)pBuffer; //显示图片 m_GameClientView.ShowChangeBanker(m_wCurrentBanker!=pChangeBanker->wBankerUser); //自己判断 if (m_wCurrentBanker==GetMeChairID() && IsLookonMode() == false && pChangeBanker->wBankerUser!=GetMeChairID()) { m_bMeApplyBanker=false; } else if (IsLookonMode() == false && pChangeBanker->wBankerUser==GetMeChairID()) { m_bMeApplyBanker=true; } //庄家信 SetBankerInfo(pChangeBanker->wBankerUser,pChangeBanker->lBankerScore); m_GameClientView.SetBankerScore(0,0); //删除玩家 if (m_wCurrentBanker!=INVALID_CHAIR) { tagUserData const *pBankerUserData=GetUserData(m_wCurrentBanker); if (pBankerUserData != NULL) { tagApplyUser ApplyUser; ApplyUser.strUserName = pBankerUserData->szName; m_GameClientView.m_ApplyUser.DeleteUser(ApplyUser); } } //更新界面 UpdateButtonContron(); m_GameClientView.UpdateGameView(NULL); return true; }
//时间消息 bool CGameClientDlg::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { switch (nTimerID) { case IDI_START_GAME: //开始定时器 { //中止判断 if (nElapse==0) { PostMessage(WM_CLOSE,0,0); return false; } //警告通知 if (nElapse<=5) PlayGameSound(AfxGetInstanceHandle(),TEXT("START_WARN")); return true; } case IDI_USER_ADD_SCORE: //加注定时器 { //获取位置 WORD wViewChairID=SwitchViewChairID(wChairID); //中止判断 if (nElapse==0) { if ((IsLookonMode()==false)&&(wViewChairID==2)) OnGiveUp(1,1); return false; } //警告通知 if ((nElapse<=3)&&(wViewChairID==2)&&(IsLookonMode()==false)) { PlayGameSound(AfxGetInstanceHandle(),TEXT("TIME_END")); return true; } return true; } } return false; }
//时间消息 bool CGameClientDlg::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { if ( nTimerID == IDI_START_GAME ) { if (wChairID == GetMeChairID() && ! IsLookonMode()) //开始游戏 { if (nElapse==0) { SendMessage(WM_CLOSE,0,0); return false; } if ((nElapse<=10)&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } } return false; }
//游戏开始 bool CGameClientDlg::OnSubGameStart(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_GameStart)) return false; CMD_S_GameStart * pGameStart=(CMD_S_GameStart *)pBuffer; //删除定时器/按钮 if(m_GameClientView.m_btIdler.IsWindowVisible()==TRUE) { KillGameTimer(IDI_CALL_BANKER); m_GameClientView.m_btIdler.ShowWindow(SW_HIDE); m_GameClientView.m_btBanker.ShowWindow(SW_HIDE); } //设置变量 m_lTurnMaxScore=pGameStart->lTurnMaxScore; m_wBankerUser=pGameStart->wBankerUser; m_GameClientView.SetWaitCall(0xff); //设置筹码 if (!IsLookonMode() && pGameStart->lTurnMaxScore>0) { LONGLONG lUserMaxScore[GAME_PLAYER]; ZeroMemory(lUserMaxScore,sizeof(lUserMaxScore)); LONGLONG lTemp=m_lTurnMaxScore; for (WORD i=0;i<GAME_PLAYER;i++) { if(i>0)lTemp/=2; lUserMaxScore[i]=__max(lTemp,1L); } //更新控件 //ActiveGameFrame(); UpdateScoreControl(lUserMaxScore,SW_SHOW); //实际定时器 SetTimer(IDI_TIME_USER_ADD_SCORE,(TIME_USER_ADD_SCORE)*1000,NULL); } //庄家标志 WORD wID=m_wViewChairID[m_wBankerUser]; m_GameClientView.SetBankerUser(wID); //等待标志 m_GameClientView.SetWaitInvest(true); //辅助显示中心时钟 SetGameTimer(GetMeChairID(),IDI_NULLITY,TIME_USER_ADD_SCORE); //环境设置 PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_START")); return true; }
//游戏场景 bool CGameClientDlg::OnGameSceneMessage(BYTE cbGameStation, bool bLookonOther, const void * pBuffer, WORD wDataSize) { switch (cbGameStation) { case GS_FREE: //空闲状态 { m_GameClientView.m_MyListView.m_btStart.EnableWindow(TRUE); return true; } case GS_PLAYING: //游戏状态 { if (wDataSize!=sizeof(CMD_S_GameState)) return false; CMD_S_GameState * psGameState = (CMD_S_GameState *)pBuffer; int id; //装入棋盘 for(int i=0; i<GAME_PLAYER; i++) { id = SwitchViewChairID(i); m_GameClientView.m_wndD3D.m_bPlayState[id] = psGameState->bPlayState[i]; memcpy(m_GameClientView.m_wndD3D.m_Chess[id],psGameState->map[i],sizeof(psGameState->map[i])); } if(IsLookonMode() || !psGameState->bPlayState[GetMeChairID()]) { m_GameClientView.m_wndD3D.m_bCanGame = false; m_GameClientView.m_wndD3D.m_bGameLose[2] = false; } else { memcpy(m_GameClientView.m_MyListView.m_ImplementCount,psGameState->bPropCnt,sizeof(psGameState->bPropCnt)); //重设定时器 m_GameClientView.m_wndD3D.m_nTimeCounter = psGameState->nLeaveTime; m_GameClientView.m_wndD3D.m_bCanGame = true; if(psGameState->nLeaveTime>=30) m_GameClientView.m_wndD3D.m_bGameLose[2] = true; } m_GameClientView.m_wndD3D.UpdateBackSurface(); m_GameClientView.m_MyListView.UpdateImplementState(); //关闭练习按钮 m_GameClientView.m_MyListView.m_btStart.EnableWindow(FALSE); m_GameClientView.m_MyListView.m_btExercise.EnableWindow(FALSE); OnPlayMusic(IDM_MUSIC_BG,0); return true; } default: return true; } return true; }
//用户叫分 bool CGameClientDlg::OnSubLandScore(const void * pBuffer, WORD wDataSize) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sOnSubLandScore.log",strTime); strTemp.Format("into OnSubLandScore"); theApp.WriteLog(strFile, strTemp); //效验数据 ASSERT(wDataSize==sizeof(CMD_S_LandScore)); if (wDataSize!=sizeof(CMD_S_LandScore)) return false; //消息处理 CMD_S_LandScore * pLandScore=(CMD_S_LandScore *)pBuffer; //设置界面 WORD wViewChairID=SwitchViewChairID(pLandScore->bLandUser); m_GameClientView.SetLandScore(wViewChairID,pLandScore->bLandScore); //玩家设置 if ((IsLookonMode()==false)&&(pLandScore->wCurrentUser==GetMeChairID())) { ActiveGameFrame(); m_GameClientView.m_btGiveUpScore.ShowWindow(SW_SHOW); m_GameClientView.m_btOneScore.ShowWindow(pLandScore->bCurrentScore<=0?SW_SHOW:SW_HIDE); m_GameClientView.m_btTwoScore.ShowWindow(pLandScore->bCurrentScore<=1?SW_SHOW:SW_HIDE); m_GameClientView.m_btThreeScore.ShowWindow(pLandScore->bCurrentScore<=2?SW_SHOW:SW_HIDE); } CString showMsg; showMsg.Format("s %d", pLandScore->bCurrentScore); strTemp.Format("into OnSubLandScore %d", pLandScore->bCurrentScore); theApp.WriteLog(strFile, strTemp); // PlayGameSound(AfxGetInstanceHandle(),TEXT("WA_1")); //AfxMessageBox(showMsg); //叫分声音 int voType = pLandScore->bCurrentScore; PlayJiaoSound( voType); //播放声音 // PlayGameSound(AfxGetInstanceHandle(),TEXT("OUT_CARD")); //设置时间 SetGameTimer(pLandScore->wCurrentUser,IDI_LAND_SCORE,30); return true; }
//操作提示 bool CGameClientDlg::OnSubOperateNotify(const void * pBuffer, WORD wDataSize) { //效验数据 ASSERT(wDataSize==sizeof(CMD_S_OperateNotify)); if (wDataSize!=sizeof(CMD_S_OperateNotify)) return false; //变量定义 CMD_S_OperateNotify * pOperateNotify=(CMD_S_OperateNotify *)pBuffer; //用户界面 if ((IsLookonMode()==false)&&(pOperateNotify->cbActionMask!=WIK_NULL)) { //获取变量 WORD wMeChairID=GetMeChairID(); BYTE cbActionMask=pOperateNotify->cbActionMask; BYTE cbActionCard=pOperateNotify->cbActionCard; //变量定义 tagGangCardResult GangCardResult; ZeroMemory(&GangCardResult,sizeof(GangCardResult)); //杠牌判断 if ((cbActionMask&WIK_GANG)!=0) { //桌面杆牌 if ((m_wCurrentUser==INVALID_CHAIR)&&(cbActionCard!=0)) { GangCardResult.cbCardCount=1; GangCardResult.cbCardData[0]=cbActionCard; } //自己杆牌 if ((m_wCurrentUser==wMeChairID)||(cbActionCard==0)) { WORD wMeChairID=GetMeChairID(); m_GameLogic.AnalyseGangCard(m_cbCardIndex,m_WeaveItemArray[wMeChairID],m_cbWeaveCount[wMeChairID],GangCardResult); } } //设置界面 ActiveGameFrame(); m_GameClientView.m_ControlWnd.SetControlInfo(cbActionCard,cbActionMask,GangCardResult); //设置时间 m_GameClientView.SetCurrentUser(INVALID_CHAIR); SetGameTimer(GetMeChairID(),IDI_OPERATE_CARD,TIME_OPERATE_CARD); } return true; }
//用户出牌 bool CGameClientDlg::OnSubOutCard(const void * pBuffer, WORD wDataSize) { //效验消息 ASSERT(wDataSize==sizeof(CMD_S_OutCard)); if (wDataSize!=sizeof(CMD_S_OutCard)) return false; //消息处理 CMD_S_OutCard * pOutCard=(CMD_S_OutCard *)pBuffer; //变量定义 WORD wMeChairID=GetMeChairID(); WORD wOutViewChairID=SwitchViewChairID(pOutCard->wOutCardUser); //设置变量 m_wCurrentUser=INVALID_CHAIR; m_wOutCardUser=pOutCard->wOutCardUser; m_cbOutCardData=pOutCard->cbOutCardData; //其他用户 if ((IsLookonMode()==true)||(pOutCard->wOutCardUser!=wMeChairID)) { //环境设置 KillGameTimer(IDI_OPERATE_CARD); PlayCardSound(pOutCard->wOutCardUser,pOutCard->cbOutCardData); //出牌界面 m_GameClientView.SetUserAction(INVALID_CHAIR,0); m_GameClientView.SetOutCardInfo(wOutViewChairID,pOutCard->cbOutCardData); //设置扑克 if (wOutViewChairID==2) { //删除扑克 BYTE cbCardData[MAX_COUNT]; m_GameLogic.RemoveCard(m_cbCardIndex,pOutCard->cbOutCardData); //设置扑克 BYTE cbCardCount=m_GameLogic.SwitchToCardData(m_cbCardIndex,cbCardData); m_GameClientView.m_HandCardControl.SetCardData(cbCardData,cbCardCount,0); } else { WORD wUserIndex=(wOutViewChairID>2)?2:wOutViewChairID; m_GameClientView.m_UserCard[wUserIndex].SetCurrentCard(false); } } return true; }
//发牌结束 LRESULT CGameClientDlg::OnSendFinish(WPARAM wParam,LPARAM lParam) { //控制界面 if ((IsLookonMode()==false)&&(m_wCurrentUser==GetMeChairID())) { ActiveGameFrame(); UpdateScoreControl(); } if(m_wCurrentUser<GAME_PLAYER) { SetGameTimer(m_wCurrentUser,IDI_USER_ADD_SCORE,TIME_USER_ADD_SCORE); } return 0; }
//出牌操作 LRESULT CGameClientDlg::OnOutCard(WPARAM wParam, LPARAM lParam) { //出牌判断 if ((IsLookonMode()==true)||(m_wCurrentUser!=GetMeChairID())) return 0; //听牌判断 if (((m_bHearStatus==true)||(m_bWillHearStatus==true))&&(VerdictOutCard((BYTE)wParam)==false)) { InsertSystemString(TEXT("出此牌不符合游戏规则!")); return 0; } //听牌设置 if (m_bWillHearStatus==true) { m_bHearStatus=true; m_bWillHearStatus=false; } //设置变量 m_wCurrentUser=INVALID_CHAIR; BYTE cbOutCardData=(BYTE)wParam; m_GameLogic.RemoveCard(m_cbCardIndex,cbOutCardData); //设置扑克 BYTE cbCardData[MAX_COUNT]; BYTE cbCardCount=m_GameLogic.SwitchToCardData(m_cbCardIndex,cbCardData); m_GameClientView.m_HandCardControl.SetCardData(cbCardData,cbCardCount,0); //设置界面 KillGameTimer(IDI_OPERATE_CARD); m_GameClientView.UpdateGameView(NULL); m_GameClientView.SetStatusFlag(false,false); m_GameClientView.SetUserAction(INVALID_CHAIR,0); m_GameClientView.SetOutCardInfo(2,cbOutCardData); m_GameClientView.m_ControlWnd.ShowWindow(SW_HIDE); //播放声音 PlayCardSound(GetMeChairID(),cbOutCardData); //发送数据 CMD_C_OutCard OutCard; OutCard.cbCardData=cbOutCardData; SendData(SUB_C_OUT_CARD,&OutCard,sizeof(OutCard)); return 0; }