//时间消息 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::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; }
//移动棋子 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::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { static int num = 0; if ((nTimerID==IDI_PLACE_JETTON)&&(nElapse==0)) { num = 0; //设置光标 m_GameClientView.SetCurrentJetton(0L); //禁止按钮 m_GameClientView.m_btJetton100.EnableWindow(FALSE); m_GameClientView.m_btJetton1000.EnableWindow(FALSE); m_GameClientView.m_btJetton10000.EnableWindow(FALSE); m_GameClientView.m_btJetton100000.EnableWindow(FALSE); m_GameClientView.m_btJetton1000000.EnableWindow(FALSE); m_GameClientView.m_btJetton5000000.EnableWindow(FALSE); m_GameClientView.m_btJetton10000000.EnableWindow(FALSE); //庄家按钮 m_GameClientView.m_btApplyBanker.EnableWindow( FALSE ); m_GameClientView.m_btCancelBanker.EnableWindow( FALSE ); } if ((nTimerID==IDI_PLACE_JETTON)&&IsEnableSound()) { if (nElapse<=2&&nElapse>1) PlayGameSound(HORSE_READY); } if (nTimerID == IDI_HORSE_RUN && nElapse > 11 && (nElapse%3) == 0) { m_GameClientView.SetEveryHorseSpeed(8- (nElapse-11)/3); } if (nTimerID == IDI_HORSE_RUN) { if (nElapse == 34) { PlayGameSound(RACE_RUN); } if (IsEnableSound() && m_GameClientView.GetIsFinishRace()) { num ++; if (num == 3) { PlayGameSound(RACE_OVER); } } } 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("GAME_WARN")); return true; } case IDI_NULLITY: //过滤时器 { //中止判断 if (nElapse==0) { KillGameTimer(IDI_NULLITY); return false; } //警告通知 if (nElapse<=5) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } case IDI_CALL_BANKER: //叫庄定时 { //中止判断 if (nElapse==0) { //测试代码 //放弃做庄 OnBanker(0,0); return false; } //警告通知 if (nElapse<=5) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN")); return true; } } return false; }
//加注按钮 LRESULT CGameClientDlg::OnAddScore(WPARAM wParam, LPARAM lParam) { //删除定时器 KillTimer(IDI_TIME_USER_ADD_SCORE); //获取筹码 WORD wMeChairID=GetMeChairID(); BYTE bTemp=(BYTE)wParam; LONGLONG lCurrentScore=0; if(bTemp==1)lCurrentScore=__max(m_lTurnMaxScore/8,1L); else if(bTemp==2)lCurrentScore=__max(m_lTurnMaxScore/4,1L); else if(bTemp==3)lCurrentScore=__max(m_lTurnMaxScore/2,1L); else if(bTemp==4)lCurrentScore=__max(m_lTurnMaxScore,1L); //控制按钮 UpdateScoreControl(NULL,SW_HIDE); //界面设置 m_lTableScore[wMeChairID]=lCurrentScore; m_GameClientView.SetUserTableScore(m_wViewChairID[wMeChairID],m_lTableScore[wMeChairID]); PlayGameSound(AfxGetInstanceHandle(),TEXT("ADD_SCORE")); //发送消息 CMD_C_AddScore AddScore; AddScore.lScore=lCurrentScore; SendData(SUB_C_ADD_SCORE,&AddScore,sizeof(AddScore)); return 0; }
//加注按钮 LRESULT CGameClientDlg::OnAddScore(WPARAM wParam, LPARAM lParam) { //取消按钮 if( lParam == -1 ) { UpdateScoreControl(); return 0; } else if( lParam == 0 ) { //不加或跟注 return OnFollow(0,0); } //获取筹码 WORD wMeChairID=GetMeChairID(); LONG lCurrentScore=m_lTurnLessScore-m_lTableScore[wMeChairID*2+1]+m_lCellScore*(lParam); //加注设置 m_bAddScore=true; HideScoreControl(); m_GameClientView.m_PlayerJeton[2].SetScore(lCurrentScore); //界面设置 KillGameTimer(IDI_USER_ADD_SCORE); m_GameClientView.UpdateGameView(NULL); PlayGameSound(AfxGetInstanceHandle(),TEXT("ADD_SCORE")); //发送消息 CMD_C_AddScore AddScore; AddScore.lScore=lCurrentScore; SendData(SUB_C_ADD_SCORE,&AddScore,sizeof(AddScore)); return 0; }
//用户放弃 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::OnTimerMessage(WORD wChairID, UINT nElapse, UINT nTimerID) { if ((nTimerID==IDI_PLACE_JETTON)&&(nElapse==0)) { //设置光标 m_GameClientView.SetCurrentJetton(0L); //禁止按钮 m_GameClientView.m_btJetton100.EnableWindow(FALSE); m_GameClientView.m_btJetton1000.EnableWindow(FALSE); m_GameClientView.m_btJetton10000.EnableWindow(FALSE); m_GameClientView.m_btJetton50000.EnableWindow(FALSE); m_GameClientView.m_btJetton100000.EnableWindow(FALSE); m_GameClientView.m_btJetton500000.EnableWindow(FALSE); m_GameClientView.m_btJetton1000000.EnableWindow(FALSE); m_GameClientView.m_btJetton5000000.EnableWindow(FALSE); //庄家按钮 m_GameClientView.m_btApplyBanker.EnableWindow( FALSE ); m_GameClientView.m_btCancelBanker.EnableWindow( FALSE ); } if (IsEnableSound()) { if (nTimerID==IDI_PLACE_JETTON&&nElapse<=5) PlayGameSound(AfxGetInstanceHandle(),TEXT("TIME_WARIMG")); } return true; }
/** ** Check if enough resources for are available. ** ** @param costs How many costs. ** ** @return False if all enough, otherwise a bit mask. ** ** @note The return values of the PlayerCheck functions are inconsistent. */ int CPlayer::CheckCosts(const int *costs, bool notify) const { //Wyrmgus start bool sound_played = false; //Wyrmgus end int err = 0; for (int i = 1; i < MaxCosts; ++i) { if (this->Resources[i] + this->StoredResources[i] >= costs[i]) { continue; } if (notify) { const char *name = DefaultResourceNames[i].c_str(); const char *actionName = DefaultActions[i].c_str(); //Wyrmgus start // Notify(_("Not enough %s...%s more %s."), _(name), _(actionName), _(name)); Notify(_("Not enough %s... %s more %s."), _(name), _(actionName), _(name)); //added extra space to look better //Wyrmgus end //Wyrmgus start // if (this == ThisPlayer && GameSounds.NotEnoughRes[this->Race][i].Sound) { if (this == ThisPlayer && GameSounds.NotEnoughRes[this->Race][i].Sound && !sound_played) { sound_played = true; //Wyrmgus end PlayGameSound(GameSounds.NotEnoughRes[this->Race][i].Sound, MaxSampleVolume); } } err |= 1 << i; } return err; }
//用户下注 bool CGameClientDlg::OnSubAddScore(const void * pBuffer, WORD wDataSize) { //效验数据 if (wDataSize!=sizeof(CMD_S_AddScore)) return false; CMD_S_AddScore * pAddScore=(CMD_S_AddScore *)pBuffer; //删除定时器/控制按钮 if(IsCurrentUser(pAddScore->wAddScoreUser) && m_GameClientView.m_btOneScore.IsWindowVisible()==TRUE) { KillTimer(IDI_TIME_USER_ADD_SCORE); UpdateScoreControl(NULL,SW_HIDE); } //变量定义 WORD wAddScoreUser=pAddScore->wAddScoreUser; WORD wViewChairID=m_wViewChairID[wAddScoreUser]; //加注界面 m_lTableScore[pAddScore->wAddScoreUser]=pAddScore->lAddScoreCount; m_GameClientView.SetUserTableScore(wViewChairID,pAddScore->lAddScoreCount); //播放声音 if (!IsCurrentUser(pAddScore->wAddScoreUser) && m_cbPlayStatus[wAddScoreUser]==TRUE) PlayGameSound(AfxGetInstanceHandle(),TEXT("ADD_SCORE")); return true; }
//开始按钮 LRESULT CGameClientDlg::OnStart(WPARAM wParam, LPARAM lParam) { //设置变量 m_wTimeOutCount=0; m_bHandCardCount=0; m_bTurnCardCount=0; m_bTurnOutType=CT_INVALID; m_wMostUser=INVALID_CHAIR; memset(m_bHandCardData,0,sizeof(m_bHandCardData)); memset(m_bTurnCardData,0,sizeof(m_bTurnCardData)); //设置界面 KillGameTimer(IDI_START_GAME); m_GameClientView.SetCardCount(INVALID_CHAIR,0); m_GameClientView.SetPassFlag(INVALID_CHAIR,false); //隐藏控件 m_GameClientView.m_btStart.ShowWindow(FALSE); m_GameClientView.m_ScoreView.ShowWindow(SW_HIDE); //设置扑克 m_GameClientView.m_HandCardControl.SetCardData(NULL,0); m_GameClientView.m_HandCardControl.SetPositively(false); // m_GameClientView.m_LeaveCardControl[0].SetCardData(NULL,0); // m_GameClientView.m_LeaveCardControl[1].SetCardData(NULL,0); for (WORD i=0;i<GAME_PLAYER;i++) m_GameClientView.m_UserCardControl[i].SetCardData(NULL,0); //发送消息 SendUserReady(NULL,0); PlayGameSound(AfxGetInstanceHandle(),TEXT("Ready")); return 0; }
//出牌消息 LRESULT CGameClientDlg::OnOutCard(WPARAM wParam, LPARAM lParam) { //状态判断 if ((m_GameClientView.m_btOutCard.IsWindowEnabled()==FALSE) ||(m_GameClientView.m_btOutCard.IsWindowVisible()==FALSE)) return 0; //设置界面 KillGameTimer(IDI_OUT_CARD); m_GameClientView.m_btOutCard.ShowWindow(SW_HIDE); m_GameClientView.m_btOutCard.EnableWindow(FALSE); m_GameClientView.m_btPassCard.ShowWindow(SW_HIDE); m_GameClientView.m_btPassCard.EnableWindow(FALSE); m_GameClientView.m_btOutPrompt.ShowWindow(SW_HIDE); m_GameClientView.m_btOutPrompt.EnableWindow(FALSE); //发送数据 CMD_C_OutCard OutCard; OutCard.bCardCount=(BYTE)m_GameClientView.m_HandCardControl.GetShootCard(OutCard.bCardData,CountArray(OutCard.bCardData)); m_GameLogic.SortCardList(OutCard.bCardData,OutCard.bCardCount); SendData(SUB_C_OUT_CART,&OutCard,sizeof(OutCard)-sizeof(OutCard.bCardData)+OutCard.bCardCount*sizeof(BYTE)); //预先显示 PlayGameSound(AfxGetInstanceHandle(),TEXT("OUT_CARD")); m_GameClientView.m_UserCardControl[2].SetCardData(OutCard.bCardData,OutCard.bCardCount); //预先删除 BYTE bSourceCount=m_bHandCardCount; m_bHandCardCount-=OutCard.bCardCount; m_GameLogic.RemoveCard(OutCard.bCardData,OutCard.bCardCount,m_bHandCardData,bSourceCount); m_GameClientView.m_HandCardControl.SetCardData(m_bHandCardData,m_bHandCardCount); return 0; }
//放弃出牌 LRESULT CGameClientDlg::OnPassCard(WPARAM wParam, LPARAM lParam) { //状态判断 if (m_GameClientView.m_btPassCard.IsWindowEnabled()==FALSE) return 0; //设置界面 KillGameTimer(IDI_OUT_CARD); m_GameClientView.m_btOutCard.ShowWindow(SW_HIDE); m_GameClientView.m_btOutCard.EnableWindow(FALSE); m_GameClientView.m_btPassCard.ShowWindow(SW_HIDE); m_GameClientView.m_btPassCard.EnableWindow(FALSE); m_GameClientView.m_btOutPrompt.ShowWindow(SW_HIDE); m_GameClientView.m_btOutPrompt.EnableWindow(FALSE); //发送数据 SendData(SUB_C_PASS_CARD); //预先显示 m_GameClientView.m_UserCardControl[2].SetCardData(NULL,0); m_GameClientView.SetPassFlag(2,true); PlayGameSound(AfxGetInstanceHandle(),TEXT("OUT_CARD")); m_GameClientView.m_HandCardControl.SetCardData(m_bHandCardData,m_bHandCardCount); return 0; }
//自动出牌 bool CGameClientDlg::AutomatismOutCard() { //先出牌者 if (m_bTurnCardCount==0) { //控制界面 KillGameTimer(IDI_OUT_CARD); m_GameClientView.m_btOutCard.ShowWindow(SW_HIDE); m_GameClientView.m_btOutCard.EnableWindow(FALSE); m_GameClientView.m_btPassCard.ShowWindow(SW_HIDE); m_GameClientView.m_btPassCard.EnableWindow(FALSE); m_GameClientView.m_btAutoOutCard.ShowWindow(SW_HIDE); m_GameClientView.m_btAutoOutCard.EnableWindow(FALSE); //发送数据 CMD_C_OutCard OutCard; OutCard.bCardCount=1; OutCard.bCardData[0]=m_bHandCardData[m_bHandCardCount-1]; SendData(SUB_C_OUT_CART,&OutCard,sizeof(OutCard)-sizeof(OutCard.bCardData)+OutCard.bCardCount*sizeof(BYTE)); //预先处理 PlayGameSound(AfxGetInstanceHandle(),TEXT("OUT_CARD")); m_GameClientView.m_UserCardControl[1].SetCardData(OutCard.bCardData,OutCard.bCardCount); //预先删除 BYTE bSourceCount=m_bHandCardCount; m_bHandCardCount-=OutCard.bCardCount; m_GameLogic.RemoveCard(OutCard.bCardData,OutCard.bCardCount,m_bHandCardData,bSourceCount); m_GameClientView.m_HandCardControl.SetCardData(m_bHandCardData,m_bHandCardCount); } else OnPassCard(0,0); 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; }
//放弃出牌 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; }
/** ** Ask the sound system to play the specified sound. ** ** @param l Lua state. */ static int CclPlaySound(lua_State *l) { CSound *id; LuaCheckArgs(l, 1); id = CclGetSound(l); PlayGameSound(id, MaxSampleVolume); return 0; }
//时间消息 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::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; }
static void NetworkExecCommand_Chat(const CNetworkCommandQueue &ncq) { Assert((ncq.Type & 0x7F) == MessageChat); CNetworkChat nc; nc.Deserialize(&ncq.Data[0]); SetMessage("%s", nc.Text.c_str()); PlayGameSound(GameSounds.ChatMessage.Sound, MaxSampleVolume); CommandLog("chat", NoUnitP, FlushCommands, -1, -1, NoUnitP, nc.Text.c_str(), -1); }
/** ** Check if enough resources for are available. ** ** @param costs How many costs. ** ** @return False if all enough, otherwise a bit mask. ** ** @note The return values of the PlayerCheck functions are inconsistent. */ int CPlayer::CheckCosts(const int *costs) const { int err = 0; for (int i = 1; i < MaxCosts; ++i) { if (this->Resources[i] < costs[i]) { Notify(NotifyYellow, -1, -1, "Not enough %s...%s more %s.", DefaultResourceNames[i].c_str(), DefaultActions[i].c_str(), DefaultResourceNames[i].c_str()); err |= 1 << i; if (i==1) if (GameSounds.NotEnough1[this->Race].Sound) PlayGameSound(GameSounds.NotEnough1[this->Race].Sound, MaxSampleVolume); if (i==2) if (GameSounds.NotEnough2[this->Race].Sound) PlayGameSound(GameSounds.NotEnough2[this->Race].Sound, MaxSampleVolume); } } return err; }
/** ** Research upgrade. ** ** @return true when finished. */ /* virtual */ void COrder_Research::Execute(CUnit &unit) { const CUpgrade &upgrade = this->GetUpgrade(); const CUnitType &type = *unit.Type; //Wyrmgus start // UnitShowAnimation(unit, type.Animations->Research ? type.Animations->Research : type.Animations->Still); UnitShowAnimation(unit, unit.GetAnimations()->Research ? unit.GetAnimations()->Research : unit.GetAnimations()->Still); //Wyrmgus end if (unit.Wait) { unit.Wait--; return ; } #if 0 if (unit.Anim.Unbreakable) { return ; } #endif //Wyrmgus start // CPlayer &player = *unit.Player; CPlayer &player = Players[this->Player]; // player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, player.SpeedResearch / SPEEDUP_FACTOR); player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, (player.SpeedResearch + unit.Variable[TIMEEFFICIENCYBONUS_INDEX].Value + unit.Variable[RESEARCHSPEEDBONUS_INDEX].Value) / SPEEDUP_FACTOR); //Wyrmgus end if (player.UpgradeTimers.Upgrades[upgrade.ID] >= upgrade.Costs[TimeCost]) { if (upgrade.Name.empty()) { //Wyrmgus start // player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), type.Name.c_str()); player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), type.GetDefaultName(player).c_str()); //Wyrmgus end } else { player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), upgrade.Name.c_str()); } if (&player == ThisPlayer) { //Wyrmgus start // CSound *sound = GameSounds.ResearchComplete[player.Race].Sound; CSound *sound = GameSounds.ResearchComplete[unit.Player->Race].Sound; //Wyrmgus end if (sound) { PlayGameSound(sound, MaxSampleVolume); } } if (player.AiEnabled) { AiResearchComplete(unit, &upgrade); } UpgradeAcquire(player, &upgrade); this->Finished = true; return ; } unit.Wait = CYCLES_PER_SECOND / 6; }
/** ** Spell cast! ** ** @param caster Unit that casts the spell ** @param spell Spell-type pointer ** @param target Target unit that spell is addressed to ** @param goalPos coord of target spot when/if target does not exist ** ** @return !=0 if spell should/can continue or 0 to stop */ int SpellCast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos) { Vec2i pos = goalPos; caster.Variable[INVISIBLE_INDEX].Value = 0;// unit is invisible until attacks // FIXME: Must be configurable if (target) { pos = target->tilePos; } // // For TargetSelf, you target.... YOURSELF // if (spell.Target == TargetSelf) { pos = caster.tilePos; target = &caster; } DebugPrint("Spell cast: (%s), %s -> %s (%d,%d)\n" _C_ spell.Ident.c_str() _C_ caster.Type->Name.c_str() _C_ target ? target->Type->Name.c_str() : "none" _C_ pos.x _C_ pos.y); if (CanCastSpell(caster, spell, target, pos)) { int cont = 1; // Should we recast the spell. bool mustSubtractMana = true; // false if action which have their own calculation is present. // // Ugly hack, CastAdjustVitals makes it's own mana calculation. // PlayGameSound(spell.SoundWhenCast.Sound, MaxSampleVolume); for (std::vector<SpellActionType *>::const_iterator act = spell.Action.begin(); act != spell.Action.end(); ++act) { if ((*act)->ModifyManaCaster) { mustSubtractMana = false; } cont = cont & (*act)->Cast(caster, spell, target, pos); } if (mustSubtractMana) { caster.Variable[MANA_INDEX].Value -= spell.ManaCost; } caster.Player->SubCosts(spell.Costs); caster.SpellCoolDownTimers[spell.Slot] = spell.CoolDown; // // Spells like blizzard are casted again. // This is sort of confusing, we do the test again, to // check if it will be possible to cast again. Otherwise, // when you're out of mana the caster will try again ( do the // anim but fail in this proc. // if (spell.RepeatCast && cont) { return CanCastSpell(caster, spell, target, pos); } } // // Can't cast, STOP. // return 0; }
//放弃按钮 LRESULT CGameClientDlg::OnGiveUp(WPARAM wParam, LPARAM lParam) { //界面设置 KillGameTimer(IDI_USER_ADD_SCORE); PlayGameSound(AfxGetInstanceHandle(),TEXT("GIVE_UP")); //发送消息 SendData(SUB_C_GIVE_UP); HideScoreControl(); return 0; }
//初始函数 bool CGameClientDlg::InitGameFrame() { //设置图标 HICON hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME)); SetIcon(hIcon,TRUE); SetIcon(hIcon,FALSE); HINSTANCE hInstance = AfxGetInstanceHandle(); //读取配置 m_dwCardHSpace=AfxGetApp()->GetProfileInt(TEXT("GameOption"),TEXT("CardSpace"),DEFAULT_PELS); //调整参数 if ((m_dwCardHSpace>MAX_PELS)||(m_dwCardHSpace<LESS_PELS)) m_dwCardHSpace=18; //配置控件 for (int i=0;i<GAME_PLAYER;i++) { m_GameClientView.m_CardControlOx[i].SetDisplayFlag(true); m_GameClientView.m_CardControlOx[i].SetCardSpace(m_dwCardHSpace); m_GameClientView.m_CardControl[i].SetCardSpace(m_dwCardHSpace); } //测试代码 #ifdef _DEBUG //m_GameClientView.m_btShortcut.ShowWindow(SW_SHOW); //BYTE bTemp[]={1,2,3,4,5}; //for (BYTE i=0;i<GAME_PLAYER;i++) //{ // m_GameClientView.m_CardControl[i].SetDisplayFlag(true); // m_GameClientView.m_CardControl[i].SetCardData(bTemp,5); // //m_GameClientView.m_CardControlOx[i].SetDisplayFlag(true); // //m_GameClientView.m_CardControlOx[i].SetCardData(bTemp,2); //} //m_GameClientView.m_CardControl[2].SetPositively(true); #endif //加载声音 VERIFY(m_DTSDBackground.Create(TEXT("BACK_GROUND"))); if (IsEnableSound()) { PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_START")); //m_DTSDBackground.Play(0,true); } return true; }
//播放叫分声音 void CGameClientDlg::PlayJiaoSound(int voType) { //播放叫分声音 switch(voType) { case 1: { PlayGameSound(AfxGetInstanceHandle(),TEXT("WA_1")); } break; case 2: { PlayGameSound(AfxGetInstanceHandle(),TEXT("WA_2")); } break; case 3: { PlayGameSound(AfxGetInstanceHandle(),TEXT("WA_3")); } break; }//End switch(pLandScore->bCurrentScore) }
//摊牌按钮 LRESULT CGameClientDlg::OnOpenCard(WPARAM wParam, LPARAM lParam) { if(m_GameClientView.m_btOx.IsWindowEnabled()==TRUE) { //牛牛 m_GameClientView.m_CardControl[MY_VIEW_CHAIRID].SetOX(true); //取消响应 m_GameClientView.m_CardControl[MY_VIEW_CHAIRID].SetPositively(false); //分类牛牌 OnSortCard(0,0); m_GameClientView.m_btOx.EnableWindow(FALSE); } //删除时间 KillTimer(IDI_TIME_OPEN_CARD); //处理控件 m_GameClientView.m_btOx.ShowWindow(SW_HIDE); m_GameClientView.m_btOpenCard.ShowWindow(SW_HIDE); m_GameClientView.m_btHintOx.ShowWindow(SW_HIDE); m_GameClientView.m_btReSort.ShowWindow(SW_HIDE); m_GameClientView.m_btShortcut.ShowWindow(SW_HIDE); WORD wViewChairID=MY_VIEW_CHAIRID; //发送消息 CMD_C_OxCard OxCard; OxCard.bOX=(m_GameClientView.m_CardControl[wViewChairID].GetOX())?TRUE:FALSE; SendData(SUB_C_OPEN_CARD,&OxCard,sizeof(OxCard)); //预先处理 if(OxCard.bOX==FALSE) { //显示不构成牛牛 m_GameClientView.m_CardControl[wViewChairID].ShootAllCard(false); m_GameClientView.SetUserOxValue(wViewChairID,0); } m_GameClientView.ShowOpenCard(wViewChairID); m_GameClientView.m_CardControl[wViewChairID].SetPositively(false); //保存牛信息 m_bUserOxCard[GetMeChairID()]=OxCard.bOX; PlayGameSound(AfxGetInstanceHandle(),TEXT("OPEN_CARD")); return 0; }