您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 网狐棋牌游戏挖坑游戏源码
  所属分类: C
  开发工具:
  文件大小: 2mb
  下载次数: 0
  上传时间: 2011-01-29
  提 供 者: ri***
 详细说明: #include "StdAfx.h" #include "TableFrameSink.h" ////////////////////////////////////////////////////////////////////////// //静态变量 const WORD CTableFrameSink::m_wPlayerCount=GAME_PLAYER; //游戏人数 const enStartMode CTableFrameSink::m_GameStartMode=enStartMode_FullReady; //开始模式 ////////////////////////////////////////////////////////////////////////// //构造函数 CTableFrameSink::CTableFrameSink() { //游戏变量 m_bCavernScore=0; m_wFirstUser=INVALID_CHAIR; m_wCavernUser=INVALID_CHAIR; m_wCurrentUser=INVALID_CHA IR; memset(m_bScoreInfo,0,sizeof(m_bScoreInfo)); //运行信息 m_bCount1=0; m_bCount2=0; m_bCount3=0; m_bTurnCardCount=0; m_wTurnWiner=INVALID_CHAIR; memset(m_bTurnCardData,0,sizeof(m_bTurnCardData)); //扑克信息 memset(m_bBackCard,0,sizeof(m_bBackCard)); memset(m_bCardCount,0,sizeof(m_bCardCount)); memset(m_bHandCardData,0,sizeof(m_bHandCardData)); //组件变量 m_pITableFrame=NULL; m_pGameServiceOption=NULL; return; } //析构函数 CTableFrameSink::~CTableFrameSink(void) { } //接口查询 void * __cdecl CTableFrameSink::QueryInterface(const IID & Guid, DWORD dwQueryVer) { QUERYINTERFACE(ITableFrameSink,Guid,dwQueryVer); QUERYINTERFACE_IUNKNOWNEX(ITableFrameSink,Guid,dwQueryVer); return NULL; } //初始化 bool __cdecl CTableFrameSink::InitTableFrameSink(IUnknownEx * pIUnknownEx) { //查询接口 ASSERT(pIUnknownEx!=NULL); m_pITableFrame=QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,ITableFrame); if (m_pITableFrame==NULL) return false; //获取参数 m_pGameServiceOption=m_pITableFrame->GetGameServiceOption(); ASSERT(m_pGameServiceOption!=NULL); return true; } //复位桌子 void __cdecl CTableFrameSink::RepositTableFrameSink() { //游戏变量 m_bCavernScore=0; m_wFirstUser=INVALID_CHAIR; m_wCavernUser=INVALID_CHAIR; m_wCurrentUser=INVALID_CHAIR; memset(m_bScoreInfo,0,sizeof(m_bScoreInfo)); //运行信息 m_bCount1=0; m_bCount2=0; m_bCount3=0; m_bTurnCardCount=0; m_wTurnWiner=INVALID_CHAIR; memset(m_bTurnCardData,0,sizeof(m_bTurnCardData)); //扑克信息 memset(m_bBackCard,0,sizeof(m_bBackCard)); memset(m_bCardCount,0,sizeof(m_bCardCount)); memset(m_bHandCardData,0,sizeof(m_bHandCardData)); return; } //开始模式 enStartMode __cdecl CTableFrameSink::GetGameStartMode() { return m_GameStartMode; } //游戏状态 bool __cdecl CTableFrameSink::IsUserPlaying(WORD wChairID) { return true; } //游戏开始 bool __cdecl CTableFrameSink::OnEventGameStart() { //设置状态 m_pITableFrame->SetGameStatus(GS_WK_SCORE); //混乱扑克 BYTE bRandCard[52]; m_GameLogic.RandCardList(bRandCard,sizeof(bRandCard)/sizeof(bRandCard[0])); //分发扑克 for (WORD i=0;i=4)&&(bCardValue<=7)) bHaveFlagCard[bCardValue-4]=true; } } for (BYTE i=0;i<4;i++) { if (bHaveFlagCard[i]==false) { bFlagCard=0x24+i; break; } } //寻找挖坑 bool bFind=false; BYTE bBaseValue=m_GameLogic.GetCardValue(bFlagCard); for (WORD i=0;i=0;j--) { if (m_GameLogic.GetCardValue(m_bHandCardData[i][j])>bBaseValue) break; if (m_bHandCardData[i][j]==bFlagCard) { bFind=true; m_wFirstUser=i; m_wCurrentUser=i; break; } } if (bFind==true) break; } ASSERT(bFind==true); //发送扑克 CMD_S_SendCard SendCard; SendCard.wCurrentUser=m_wCurrentUser; for (WORD i=0;iSendTableData(i,SUB_S_SEND_CARD,&SendCard,sizeof(SendCard)); m_pITableFrame->SendLookonData(i,SUB_S_SEND_CARD,&SendCard,sizeof(SendCard)); } return true; } //游戏结束 bool __cdecl CTableFrameSink::OnEventGameEnd(WORD wChairID, IServerUserItem * pIServerUserItem, BYTE cbReason) { switch (cbReason) { case GER_DISMISS: //游戏解散 { //效验参数 ASSERT(pIServerUserItem!=NULL); ASSERT(wChairIDSendTableData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); //结束游戏 m_pITableFrame->ConcludeGame(); return true; } case GER_NORMAL: //常规结束 { //定义变量 CMD_S_GameEnd GameEnd; memset(&GameEnd,0,sizeof(GameEnd)); tagScoreInfo ScoreInfo[m_wPlayerCount]; memset(&ScoreInfo,0,sizeof(ScoreInfo)); LONG lTax=0; //剩余扑克 BYTE bCardPos=0; for (WORD i=0;ilCellScore; bool bCavernWin=(m_bCardCount[m_wCavernUser]==0)?true:false; //统计积分 for (WORD i=0;iwServerType&GAME_GENRE_GOLD) { for (WORD i=0;i=100L) { lTax=GameEnd.lGameScore[i] *m_pGameServiceOption->wRevenue /100L; GameEnd.lGameTax+=lTax; GameEnd.lGameScore[i]-=lTax; } } } //发送信息 m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); //修改积分 for (WORD i=0;i0L)?enScoreKind_Win:enScoreKind_Lost; m_pITableFrame->WriteUserScore(i,ScoreInfo[i].lScore ,ScoreInfo[i].lRevenue ,ScoreInfo[i].ScoreKind ); } //m_pITableFrame->WriteTableScore(ScoreInfo,m_wPlayerCount,GameEnd.lGameTax); //结束游戏 m_pITableFrame->ConcludeGame(); return true; } case GER_USER_LEFT: //用户强退 { //效验参数 ASSERT(pIServerUserItem!=NULL); ASSERT(wChairIDlCellScore; //剩余扑克 BYTE bCardPos=0; for (WORD i=0;iSendTableData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GAME_END,&GameEnd,sizeof(GameEnd)); //修改积分 tagScoreInfo ScoreInfo; ZeroMemory(&ScoreInfo,sizeof(ScoreInfo)); ScoreInfo.ScoreKind=enScoreKind_Draw; ScoreInfo.lScore=GameEnd.lGameScore[wChairID]; m_pITableFrame->WriteUserScore(wChairID,ScoreInfo.lScore ,ScoreInfo.lRevenue ,ScoreInfo.ScoreKind ); //结束游戏 m_pITableFrame->ConcludeGame(); return true; } } ASSERT(FALSE); return false; } //发送场景 bool __cdecl CTableFrameSink::SendGameScene(WORD wChiarID, IServerUserItem * pIServerUserItem, BYTE cbGameStatus, bool bSendSecret) { switch (cbGameStatus) { case GS_WK_FREE: //空闲状态 { //构造数据 CMD_S_StatusFree StatusFree; memset(&StatusFree,0,sizeof(StatusFree)); //设置变量 StatusFree.lBaseScore=m_pGameServiceOption->lCellScore; //发送场景 return m_pITableFrame->SendGameScene(pIServerUserItem,&StatusFree,sizeof(StatusFree)); } case GS_WK_SCORE: //叫分状态 { //构造数据 CMD_S_StatusScore StatusScore; memset(&StatusScore,0,sizeof(StatusScore)); //设置变量 StatusScore.bCavernScore=m_bCavernScore; StatusScore.wCurrentUser=m_wCurrentUser; StatusScore.lBaseScore=m_pGameServiceOption->lCellScore; CopyMemory(StatusScore.bScoreInfo,m_bScoreInfo,sizeof(m_bScoreInfo)); CopyMemory(StatusScore.bCardData,m_bHandCardData[wChiarID],m_bCardCount[wChiarID]); //发送场景 return m_pITableFrame->SendGameScene(pIServerUserItem,&StatusScore,sizeof(StatusScore)); } case GS_WK_PLAYING: //游戏状态 { //构造数据 CMD_S_StatusPlay StatusPlay; memset(&StatusPlay,0,sizeof(StatusPlay)); //设置变量 StatusPlay.wLastOutUser=m_wTurnWiner; StatusPlay.wCavernUser=m_wCavernUser; StatusPlay.wCurrentUser=m_wCurrentUser; StatusPlay.bCavernScore=m_bCavernScore; StatusPlay.bTurnCardCount=m_bTurnCardCount; StatusPlay.lBaseScore=m_pGameServiceOption->lCellScore; CopyMemory(StatusPlay.bBackCard,m_bBackCard,sizeof(m_bBackCard)); CopyMemory(StatusPlay.bCardCount,m_bCardCount,sizeof(m_bCardCount)); CopyMemory(StatusPlay.bTurnCardData,m_bTurnCardData,sizeof(BYTE)*m_bTurnCardCount); CopyMemory(StatusPlay.bCardData,m_bHandCardData[wChiarID],sizeof(BYTE)*m_bCardCount[wChiarID]); //发送场景 return m_pITableFrame->SendGameScene(pIServerUserItem,&StatusPlay,sizeof(StatusPlay)); } } return false; } //定时器事件 bool __cdecl CTableFrameSink::OnTimerMessage(WORD wTimerID, WPARAM wBindParam) { return false; } //游戏消息处理 bool __cdecl CTableFrameSink::OnGameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem) { switch (wSubCmdID) { case SUB_C_CAVERN_SCORE: //用户叫分 { //效验数据 ASSERT(wDataSize==sizeof(CMD_C_CavernScore)); if (wDataSize!=sizeof(CMD_C_CavernScore)) return false; //用户效验 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; //消息处理 CMD_C_CavernScore * pCavernScore=(CMD_C_CavernScore *)pDataBuffer; return OnUserCavernScore(pUserData->wChairID,pCavernScore->bCavernScore); } case SUB_C_OUT_CART: //用户出牌 { //变量定义 CMD_C_OutCard * pOutCard=(CMD_C_OutCard *)pDataBuffer; WORD wHeadSize=sizeof(CMD_C_OutCard)-sizeof(pOutCard->bCardData); //效验数据 ASSERT(wDataSize>=wHeadSize); if (wDataSizebCardCount*sizeof(pOutCard->bCardData[0]))); if (wDataSize!=(wHeadSize+pOutCard->bCardCount*sizeof(pOutCard->bCardData[0]))) return false; //用户效验 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; //消息处理 return OnUserOutCard(pUserData->wChairID,pOutCard->bCardData,pOutCard->bCardCount); } case SUB_C_PASS_CARD: { //用户效验 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; //消息处理 return OnUserPassCard(pUserData->wChairID); } } return true; } //框架消息处理 bool __cdecl CTableFrameSink::OnFrameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem) { return false; } //叫分事件 bool CTableFrameSink::OnUserCavernScore(WORD wChairID, BYTE bCavernScore) { //效验状态 if (m_pITableFrame->GetGameStatus()!=GS_WK_SCORE) return true; if (wChairID!=m_wCurrentUser) return false; //效验参数 if (((bCavernScore>3)&&(bCavernScore!=255))||(bCavernScore<=m_bCavernScore)) return false; //设置变量 if (bCavernScore!=255) { m_bCavernScore=bCavernScore; m_wCavernUser=m_wCurrentUser; } m_bScoreInfo[wChairID]=bCavernScore; //开始判断 if ((m_bCavernScore==3)||(m_wFirstUser==(wChairID+1)%m_wPlayerCount)) { //设置变量 if (m_bCavernScore==0) m_bCavernScore=1; if (m_wCavernUser==INVALID_CHAIR) m_wCavernUser=m_wFirstUser; //设置状态 m_pITableFrame->SetGameStatus(GS_WK_PLAYING); //发送底牌 m_bCardCount[m_wCavernUser]=20; CopyMemory(&m_bHandCardData[m_wCavernUser][16],m_bBackCard,sizeof(m_bBackCard)); m_GameLogic.SortCardList(m_bHandCardData[m_wCavernUser],m_bCardCount[m_wCavernUser]); //出牌信息 m_bTurnCardCount=0; m_wTurnWiner=m_wFirstUser; m_wCurrentUser=m_wFirstUser; //发送消息 CMD_S_GameStart GameStart; GameStart.wCavernUser=m_wCavernUser; GameStart.bCavernScore=m_bCavernScore; GameStart.wCurrentUser=m_wCurrentUser; CopyMemory(GameStart.bBackCard,m_bBackCard,sizeof(m_bBackCard)); m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_GAME_START,&GameStart,sizeof(GameStart)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GAME_START,&GameStart,sizeof(GameStart)); return true; } //设置用户 m_wCurrentUser=(wChairID+1)%m_wPlayerCount; //发送消息 CMD_S_CavernScore CavernScore; CavernScore.bCavernUser=wChairID; CavernScore.bCavernScore=bCavernScore; CavernScore.wCurrentUser=m_wCurrentUser; CavernScore.bCurrentScore=m_bCavernScore; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_CAVERN_SCORE,&CavernScore,sizeof(CavernScore)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_CAVERN_SCORE,&CavernScore,sizeof(CavernScore)); return true; } //用户出牌 bool CTableFrameSink::OnUserOutCard(WORD wChairID, BYTE bCardData[], BYTE bCardCount) { //效验状态 if (m_pITableFrame->GetGameStatus()!=GS_WK_PLAYING) return true; if (wChairID!=m_wCurrentUser) return false; //类型判断 BYTE bCardType=m_GameLogic.GetCardType(bCardData,bCardCount); if (bCardType==CT_INVALID) return false; //更随出牌 if (m_bTurnCardCount!=0) { if (m_bTurnCardCount!=bCardCount) return false; if (m_GameLogic.CompareCard(bCardData,m_bTurnCardData,m_bTurnCardCount)==false) return false; } else m_bTurnCardCount=bCardCount; //删除扑克 if (m_GameLogic.RemoveCard(bCardData,bCardCount,m_bHandCardData[wChairID],m_bCardCount[wChairID])==false) return false; m_bCardCount[wChairID]-=bCardCount; //大牌判断 bool bMostest=false; BYTE bLogicValue=m_GameLogic.GetCardValue(bCardData[0]); if ((bLogicValue==3)||((bLogicValue==13)&&(bCardType>=CT_ONE_LINE))) bMostest=true; else if ((bLogicValue==2)&&((m_bCount3+bCardCount)>4)) bMostest=true; else if ((bLogicValue==1)&&((m_bCount2+bCardCount)>4)&&((m_bCount3+bCardCount)>4)) bMostest=true; else if ((bLogicValue==1)&&((m_bCount1+bCardCount)>4)&&((m_bCount2+bCardCount)>4)&&((m_bCount3+bCardCount)>4)) bMostest=true; //出牌记录 for (BYTE i=0;iSendTableData(INVALID_CHAIR,SUB_S_OUT_CARD,&OutCard,wSendSize); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_OUT_CARD,&OutCard,wSendSize); //出牌最大 if (bMostest==true) m_bTurnCardCount=0; //判断结束游戏 if (m_wCurrentUser==INVALID_CHAIR) OnEventGameEnd(wChairID,NULL,GER_NORMAL); return true; } //用户放弃 bool CTableFrameSink::OnUserPassCard(WORD wChairID) { //效验状态 if (m_pITableFrame->GetGameStatus()!=GS_WK_PLAYING) return true; if ((wChairID!=m_wCurrentUser)||(m_bTurnCardCount==0)) return false; //设置变量 m_wCurrentUser=(m_wCurrentUser+1)%m_wPlayerCount; if (m_wCurrentUser==m_wTurnWiner) m_bTurnCardCount=0; //发送数据 CMD_S_PassCard PassCard; PassCard.wPassUser=wChairID; PassCard.wCurrentUser=m_wCurrentUser; PassCard.bNewTurn=(m_bTurnCardCount==0)?TRUE:FALSE; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_PASS_CARD,&PassCard,sizeof(PassCard)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_PASS_CARD,&PassCard,sizeof(PassCard)); return true; } ////////////////////////////////////////////////////////////////////////// ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 挖坑
 输入关键字,在本站1000多万海量源码库中尽情搜索: