开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2011-01-29
详细说明: #include "StdAfx.h" #include "TableFrameSink.h" ////////////////////////////////////////////////////////////////////////// #define IDI_GAME_END 1 //结束标识 ////////////////////////////////////////////////////////////////////////// //静态变量 __int64 CTableFrameSink::g_lMaxScore=100000000L; //最大变化 __int64 CTableFrameSink::g_lMaxWinScore=100000000L; //最大赢分 __int64 CTableFrameSink::g_lMaxLoseScore=-100000000L; //最大输分 //用户索引 CBlacklistIDMap CTableFrameSink::g_BlacklistIDMap; //限制用 户 CScoreHistoryMap CTableFrameSink::g_ScoreHistoryMap; //历史记录 //静态变量 const WORD CTableFrameSink::m_wPlayerCount=GAME_PLAYER; //游戏人数 const enStartMode CTableFrameSink::m_GameStartMode=enStartMode_AllReady; //开始模式 ////////////////////////////////////////////////////////////////////////// //构造函数 CTableFrameSink::CTableFrameSink() { //游戏变量 m_wOperaCount=0; m_bSendCardCount=0; m_wCurrentUser=INVALID_CHAIR; memset(m_cbCardCount,0,sizeof(m_cbCardCount)); memset(m_cbHandCardData,0,sizeof(m_cbHandCardData)); m_cbGameEndReason = GER_NORMAL; //金币信息 m_lMaxGold=0; m_lTurnBasicGold=0; m_lBasicGold = 0; memset(m_lTableGold,0,sizeof(m_lTableGold)); //辅助变量 memset(m_cbPlayStatus,0,sizeof(m_cbPlayStatus)); //组件变量 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_wOperaCount=0; m_bSendCardCount=0; m_wCurrentUser=INVALID_CHAIR; memset(m_cbPlayStatus,0,sizeof(m_cbPlayStatus)); memset(m_cbHandCardData,0,sizeof(m_cbHandCardData)); memset(m_cbCardCount,0,sizeof(m_cbCardCount)); m_cbGameEndReason = GER_NORMAL; //金币变量 m_lMaxGold=0L; m_lTurnBasicGold=0L; m_lBasicGold = 0; memset(m_lTableGold,0,sizeof(m_lTableGold)); return; } //开始模式 enStartMode __cdecl CTableFrameSink::GetGameStartMode() { return m_GameStartMode; } //游戏状态 bool __cdecl CTableFrameSink::IsUserPlaying(WORD wChairID) { ASSERT(wChairIDSetGameStatus(GS_PLAYING); //变量定义 const tagUserScore * pUserScore=NULL; IServerUserItem * pIServerUserItem=NULL; //计算下注 bool bCalculateGold=false; for (WORD i=0;iGetServerUserItem(i); if (pIServerUserItem!=NULL) { m_cbPlayStatus[i]=true; if (bCalculateGold==false) { bCalculateGold=true; pUserScore=pIServerUserItem->GetUserScore(); ASSERT(pUserScore->lScore>m_pGameServiceOption->lCellScore); m_lMaxGold=pUserScore->lScore; } else { pUserScore=pIServerUserItem->GetUserScore(); ASSERT(pUserScore->lScore>1L); m_lMaxGold=__min(m_lMaxGold,pUserScore->lScore); } } } m_lBasicGold = __max(m_lMaxGold/100L,m_pGameServiceOption->lCellScore); for( WORD i = 0; i < m_wPlayerCount; i++ ) { if( m_cbPlayStatus[i] ) { m_lTableGold[i*2+1]=m_lBasicGold; } } //分发扑克 m_bSendCardCount=2; m_GameLogic.RandCardList(m_cbHandCardData[0],sizeof(m_cbHandCardData)/sizeof(m_cbHandCardData[0][0])); for (WORD i=0;iGetServerUserItem(i); if (pIServerUserItem==NULL) continue; //积分判断 tagScoreHistory * pScoreHistory=NULL; if ((g_ScoreHistoryMap.Lookup(pIServerUserItem->GetUserID(),pScoreHistory)==TRUE)&&(pScoreHistory!=NULL)) { if ((g_lMaxScore!=0L)&&(pScoreHistory->lScore>g_lMaxScore)) bChangeCard=true; if ((g_lMaxWinScore!=0L)&&(pScoreHistory->lWinScore>g_lMaxWinScore)) bChangeCard=true; if ((g_lMaxLoseScore!=0L)&&(pScoreHistory->lLoseScoreGetUserID(),dwUserID)==TRUE)&&(dwUserID!=0L)) bChangeCard=true; //交换扑克 if (bChangeCard==true) { //获取输牌 WORD wLoseIndex=EstimateLoser(0,4); //交换扑克 if (wLoseIndex!=i) { BYTE cbTempCardData[5]; CopyMemory(cbTempCardData,m_cbHandCardData[i],5*sizeof(BYTE)); CopyMemory(m_cbHandCardData[i],m_cbHandCardData[wLoseIndex],5*sizeof(BYTE)); CopyMemory(m_cbHandCardData[wLoseIndex],cbTempCardData,5*sizeof(BYTE)); } break; } } } //设置用户 m_wCurrentUser=EstimateWinner(1,1); //发送开始 CMD_S_GameStart GameStart; memset(&GameStart,0,sizeof(GameStart)); GameStart.wCurrentUser=m_wCurrentUser; GameStart.lMaxGold=m_lMaxGold; GameStart.lTurnMaxGold=m_lMaxGold/4L; GameStart.lTurnBasicGold=m_lTurnBasicGold; GameStart.lBasicGold = m_lBasicGold; for (WORD i=0;iSendTableData(i,SUB_S_GAME_START,&GameStart,sizeof(GameStart)); } m_pITableFrame->SendLookonData(i,SUB_S_GAME_START,&GameStart,sizeof(GameStart)); } 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: //常规结束 case GER_NO_PLAYER: //没有玩家 { //定义变量 CMD_S_GameEnd GameEnd; ZeroMemory(&GameEnd,sizeof(GameEnd)); //计算总注 LONG lAllGold=0L; for (WORD i=0;i0L)?enScoreKind_Win:enScoreKind_Lost; //计算税收 if (m_pGameServiceOption->wServerType==GAME_GENRE_GOLD) { //扣税变量 BYTE cbRevenue=m_pGameServiceOption->wRevenue; if (GameEnd.lGameGold[i]>=100L) { //计算税收 lRevenue=GameEnd.lGameGold[i]*cbRevenue/100L; //成绩变量 GameEnd.lTax+=lRevenue; GameEnd.lGameGold[i]=GameEnd.lGameGold[i]-lRevenue; //写分变量 lRevenue=lRevenue; lScore=lScore-lRevenue; } } //写入积分 if (m_cbPlayStatus[i]==TRUE) { m_pITableFrame->WriteUserScore(i,lScore,lRevenue,ScoreKind); } //成绩记录 if (m_cbPlayStatus[i]==TRUE) { //获取用户 IServerUserItem * pIServerUserItem=m_pITableFrame->GetServerUserItem(i); if (pIServerUserItem==NULL) continue; //搜索用户 tagScoreHistory * pScoreHistory=NULL; g_ScoreHistoryMap.Lookup(pIServerUserItem->GetUserID(),pScoreHistory); //获取时间 SYSTEMTIME SystemTime; GetLocalTime(&SystemTime); //增加用户 if (pScoreHistory==NULL) { //创建对象 pScoreHistory=new tagScoreHistory; g_ScoreHistoryMap[pIServerUserItem->GetUserID()]=pScoreHistory; //设置变量 pScoreHistory->lScore=0L; pScoreHistory->lWinScore=0L; pScoreHistory->lLoseScore=0L; pScoreHistory->RecordTime=SystemTime; } //还原判断 if (pScoreHistory->RecordTime.wDay!=SystemTime.wDay) { pScoreHistory->lScore=0L; pScoreHistory->lWinScore=0L; pScoreHistory->lLoseScore=0L; pScoreHistory->RecordTime=SystemTime; } //记录积分 pScoreHistory->lScore+=lScore; if (lScore>0L) pScoreHistory->lWinScore+=lScore; if (lScore<0L) pScoreHistory->lLoseScore+=lScore; } } //发送信息 m_pITableFrame->SendTableData(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_USER_LEFT: //用户强退 { //效验参数 ASSERT(pIServerUserItem!=NULL); ASSERT(wChairIDSendGameScene(pIServerUserItem,&StatusFree,sizeof(StatusFree)); } case GS_PLAYING: //游戏状态 { //构造数据 CMD_S_StatusPlay StatusPlay; memset(&StatusPlay,0,sizeof(StatusPlay)); StatusPlay.wCurrentUser=m_wCurrentUser; StatusPlay.lMaxGold=m_lMaxGold; StatusPlay.lTurnBasicGold=m_lTurnBasicGold; StatusPlay.lBasicGold=m_lBasicGold; CopyMemory(StatusPlay.bPlayStatus,m_cbPlayStatus,sizeof(m_cbPlayStatus)); CopyMemory(StatusPlay.lTableGold,m_lTableGold,sizeof(m_lTableGold)); //设置下注 if (m_bSendCardCount<=2) StatusPlay.lTurnMaxGold=m_lMaxGold/4L; else if (m_bSendCardCount==3) StatusPlay.lTurnMaxGold=m_lMaxGold/2L; else StatusPlay.lTurnMaxGold=m_lMaxGold; //设置扑克 for (WORD i=0;iGetServerUserItem(i)!=NULL); StatusPlay.bTableCardCount[i]=m_cbCardCount[i]; if (i==wChiarID) StatusPlay.bTableCardArray[i][0]=m_cbHandCardData[i][0]; CopyMemory(&StatusPlay.bTableCardArray[i][1],&m_cbHandCardData[i][1],(m_cbCardCount[i]-1)*sizeof(BYTE)); } } //发送场景 return m_pITableFrame->SendGameScene(pIServerUserItem,&StatusPlay,sizeof(StatusPlay)); } } //效验结果 ASSERT(FALSE); return false; } //定时器事件 bool __cdecl CTableFrameSink::OnTimerMessage(WORD wTimerID, WPARAM wBindParam) { switch (wTimerID) { case IDI_GAME_END: //游戏结束 { if (m_pITableFrame->GetGameStatus()==GS_PLAYING) { OnEventGameEnd(INVALID_CHAIR,NULL,m_cbGameEndReason); return true; } } } return false; } //游戏消息处理 bool __cdecl CTableFrameSink::OnGameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem) { switch (wSubCmdID) { case SUB_C_ADD_GOLD: //用户加注 { //效验数据 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; if (m_cbPlayStatus[pUserData->wChairID]==FALSE) return true; //消息处理 CMD_C_AddGold * pAddGold=(CMD_C_AddGold *)pDataBuffer; OnUserAddGold(pUserData->wChairID,pAddGold->lGold,false); return true; } case SUB_C_GIVE_UP: //用户放弃 { //效验数据 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; if (m_cbPlayStatus[pUserData->wChairID]==FALSE) return true; //消息处理 OnUserGiveUp(pUserData->wChairID); return true; } } return false; } //框架消息处理 bool __cdecl CTableFrameSink::OnFrameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem) { return false; } //放弃事件 bool CTableFrameSink::OnUserGiveUp(WORD wChairID) { //状态判断 ASSERT(m_cbPlayStatus[wChairID]==TRUE); if (m_cbPlayStatus[wChairID]==FALSE) return false; //设置数据 m_cbPlayStatus[wChairID]=FALSE; m_cbCardCount[wChairID]=0; //发送放弃消息 CMD_S_GiveUp GiveUp; GiveUp.wUserChairID=wChairID; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); //变量定义 LONG lScore=0; LONG lRevenue=0; enScoreKind ScoreKind; //设置变量 ScoreKind=enScoreKind_Lost; lScore=-m_lTableGold[wChairID*2]-m_lTableGold[wChairID*2+1]; //用户写分 m_pITableFrame->WriteUserScore(wChairID,lScore,lRevenue,ScoreKind); //判断结束 WORD wPlayerCount=0; for (WORD i=0;i=2) { if (m_wCurrentUser==wChairID) OnUserAddGold(wChairID,0L,true); } else OnEventGameEnd(INVALID_CHAIR,NULL,GER_NO_PLAYER); return true; } //加注事件 bool CTableFrameSink::OnUserAddGold(WORD wChairID, LONG lGold, bool bCancel) { bool bShowHand = false; //设置数据 if (bCancel==false) { //效验数据 ASSERT(m_wCurrentUser==wChairID); if (m_wCurrentUser!=wChairID) return false; //计算限注 LONG lMaxGold=0L; if (m_bSendCardCount<=2) lMaxGold=m_lMaxGold/4L; else lMaxGold=m_lMaxGold; //计算剩下的金币 LONG lLeaveGold=lMaxGold-m_lTableGold[wChairID*2+1]; m_lTableGold[wChairID*2]=__min(lLeaveGold,__max(lGold,m_lTurnBasicGold)); if( m_lTableGold[wChairID*2]+m_lTableGold[wChairID*2+1] >= m_lMaxGold ) bShowHand = true; } //操作次数 bool bFinishTurn=false; WORD wNextUser=INVALID_CHAIR; for (WORD i=0;i=m_wPlayerCount) { LONG lTableGold=0L; for (WORD i=0;iSendTableData(INVALID_CHAIR,SUB_S_ADD_GOLD,&GoldResult,sizeof(GoldResult)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_ADD_GOLD,&GoldResult,sizeof(GoldResult)); //累计金币 for (WORD i=0;i=3)?m_lMaxGold:m_lMaxGold/2L; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_SEND_CARD,&SendCard,sizeof(SendCard)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_SEND_CARD,&SendCard,sizeof(SendCard)); //结束游戏 if ( m_bSendCardCount == 5 && m_lMaxGold <= m_lTableGold[wChairID*2+1] ) { m_cbGameEndReason = GER_NORMAL; m_pITableFrame->SetGameTimer(IDI_GAME_END,2000,1,0); } } else { m_cbGameEndReason = GER_NORMAL; m_pITableFrame->SetGameTimer(IDI_GAME_END,2000,1,0); } } else { //设置变量 m_wCurrentUser=wNextUser; m_lTurnBasicGold=__max(m_lTableGold[wChairID*2],m_lTurnBasicGold); //发送数据 CMD_S_AddGold AddGold; AddGold.wLastChairID=wChairID; AddGold.wCurrentUser=m_wCurrentUser; AddGold.lCurrentLessGold=m_lTurnBasicGold; AddGold.lLastAddGold=m_lTableGold[wChairID*2]; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_ADD_GOLD,&AddGold,sizeof(AddGold)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_ADD_GOLD,&AddGold,sizeof(AddGold)); } return true; } bool CTableFrameSink::OnUserGetWinner(IServerUserItem * pIServerUserItem) { //获取胜者 IServerUserItem * pIWinnerUserItem=m_pITableFrame->GetServerUserItem(EstimateWinner(0,4)); if (pIWinnerUserItem==NULL) return true; //构造消息 TCHAR szMessage[128]; _snprintf(szMessage,CountArray(szMessage),TEXT("本局的胜利玩家是:%s"),pIWinnerUserItem->GetAccounts()); //发送消息 m_pITableFrame->SendGameMessage(pIServerUserItem,szMessage,SMT_INFO); return true; } //推断输者 WORD CTableFrameSink::EstimateLoser(BYTE cbStartPos, BYTE cbConcludePos) { //保存扑克 BYTE cbUserCardData[GAME_PLAYER][MAX_COUNT]; CopyMemory(cbUserCardData,m_cbHandCardData,sizeof(cbUserCardData)); //寻找玩家 for (WORD wLoser=0;wLoser
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.