想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "StdAfx.h"
#include "Resource.h"
#include "GameClient.h"
#include "GameClientEngine.h"
//////////////////////////////////////////////////////////////////////////////////
//超时次数
#define MAX_TIME_OUT 3 //超时次数
//时间标识
#define IDI_OUT_CARD 200 //出牌定时器
#define IDI_CALL_CARD 201 //叫牌定时器
#define IDI_START_GAME 202 //开始定时器
#define IDI_SEND_CONCEAL 203 //底牌定时器
//时间范围
#define TIME_OUT_CARD 30 //出牌时间
#define TIME_CALL_CARD 10 //叫牌时间
#define TIME_START_GAME 30 //开始时间
#define TIME_SEND_CONCEAL 40 //留底时间
//功能定时器
#define IDI_CONCEAL_CARD 300 //底牌定时器
#define IDI_DISPATCH_CARD 301 //发牌定时器
#define IDI_LAST_TURN_CARD 302 //上轮定时器
#define IDI_THROW_CARD_RESULT 303 //甩牌定时器
#define IDI_SHOW_SCORE 304 //成绩定时器
BEGIN_MESSAGE_MAP(CGameClientEngine, CGameFrameEngine)
ON_WM_TIMER()
ON_MESSAGE(IDM_START,OnStart)
ON_MESSAGE(IDM_OUT_CARD,OnOutCard)
ON_MESSAGE(IDM_CALL_CARD,OnCallCard)
ON_MESSAGE(IDM_OUT_PROMPT,OnOutPrompt)
ON_MESSAGE(IDM_SEND_CONCEAL,OnSendConceal)
ON_MESSAGE(IDM_CONCEAL_CARD,OnConcealCard)
ON_MESSAGE(IDM_REQUEST_LEAVE,OnRuquestLeave)
ON_MESSAGE(IDM_LAST_TURN_CARD,OnLastTurnCard)
ON_MESSAGE(IDM_TRUSTEE_CONTROL,OnStusteeControl)
ON_MESSAGE(IDM_LEFT_HIT_CARD,OnLeftHitCard)
ON_MESSAGE(IDM_RIGHT_HIT_CARD,OnRightHitCard)
ON_MESSAGE(IDM_RESPONSE_LEAVE,OnMessageResponseLeave)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////////////
//构造函数
CGameClientEngine::CGameClientEngine()
{
//逻辑变量
m_cbPackCount=0;
m_cbMainColor=COLOR_ERROR;
m_cbMainValue=VALUE_ERROR;
//叫牌信息
m_cbCallCard=0;
m_cbCallCount=0;
m_wCallCardUser=INVALID_CHAIR;
//状态变量
m_wBankerUser=INVALID_CHAIR;
m_wCurrentUser=INVALID_CHAIR;
m_bBatchCard = false;
//得分信息
m_cbScoreCardCount=0;
ZeroMemory(m_cbScoreCardData,sizeof(m_cbScoreCardData));
//甩牌变量
m_bThrowCard=false;
m_cbResultCardCount=0;
m_wThrowCardUser=INVALID_CHAIR;
ZeroMemory(m_cbResultCardData,sizeof(m_cbResultCardData));
//出牌变量
m_bLastTurn=false;
m_wFirstOutUser=INVALID_CHAIR;
ZeroMemory(m_cbOutCardData,sizeof(m_cbOutCardData));
ZeroMemory(m_cbOutCardCount,sizeof(m_cbOutCardCount));
//底牌扑克
m_cbConcealCount=0;
ZeroMemory(m_cbConcealCard,sizeof(m_cbConcealCard));
//用户扑克
m_cbHandCardCount = 0;
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
//配置变量
m_bStustee=false;
m_dwCardHSpace=18;//DEFAULT_PELS;
m_wTimeOutCount = 0;
//辅助变量
m_cbRemnantCardCount=0;
m_cbDispatchCardCount=0;
ZeroMemory(m_cbDispatchCardData,sizeof(m_cbDispatchCardData));
return;
}
//析构函数
CGameClientEngine::~CGameClientEngine()
{
}
//创建引擎
bool CGameClientEngine::OnInitGameEngine()
{
//设置属性
HICON hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
m_pIClientKernel->SetGameAttribute(KIND_ID,GAME_PLAYER,VERSION_CLIENT,hIcon,GAME_NAME);
//配置控件
m_GameClientView.m_HandCardControl.SetCardSpace(m_dwCardHSpace,0,DEF_CARD_SHOOT);
//设置接口
m_DlgRequestLeave.SetGameFrameEngine(this);
return true;
}
//重置函数
bool CGameClientEngine::OnResetGameEngine()
{
//逻辑变量
m_cbPackCount=0;
m_cbMainColor=COLOR_ERROR;
m_cbMainValue=VALUE_ERROR;
//叫牌信息
m_cbCallCard=0;
m_cbCallCount=0;
m_wCallCardUser=INVALID_CHAIR;
//状态变量
m_wBankerUser=INVALID_CHAIR;
m_wCurrentUser=INVALID_CHAIR;
m_bBatchCard = false;
//得分信息
m_cbScoreCardCount=0;
ZeroMemory(m_cbScoreCardData,sizeof(m_cbScoreCardData));
//甩牌变量
m_bThrowCard=false;
m_cbResultCardCount=0;
m_wThrowCardUser=INVALID_CHAIR;
ZeroMemory(m_cbResultCardData,sizeof(m_cbResultCardData));
//出牌变量
m_bLastTurn=false;
m_wFirstOutUser=INVALID_CHAIR;
ZeroMemory(m_cbOutCardData,sizeof(m_cbOutCardData));
ZeroMemory(m_cbOutCardCount,sizeof(m_cbOutCardCount));
//底牌扑克
m_cbConcealCount=0;
ZeroMemory(m_cbConcealCard,sizeof(m_cbConcealCard));
//用户扑克
m_cbHandCardCount = 0;
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
//配置变量
m_bStustee=false;
m_wTimeOutCount = 0;
//辅助变量
m_cbRemnantCardCount=0;
m_cbDispatchCardCount=0;
ZeroMemory(m_cbDispatchCardData,sizeof(m_cbDispatchCardData));
//删除定时器
KillTimer(IDI_CONCEAL_CARD);
KillTimer(IDI_DISPATCH_CARD);
KillTimer(IDI_LAST_TURN_CARD);
KillTimer(IDI_THROW_CARD_RESULT);
return true;
}
//时钟删除
bool CGameClientEngine::OnEventGameClockKill(WORD wChairID)
{
return true;
}
//时钟信息
bool CGameClientEngine::OnEventGameClockInfo(WORD wChairID, UINT nElapse, WORD wClockID)
{
switch (wClockID)
{
case IDI_OUT_CARD: //用户出牌
{
//超时判断
if ((nElapse==0)||((m_bStustee==true)&&(nElapse<(TIME_OUT_CARD))))
{
if ((IsLookonMode()==false)&&(wChairID==GetMeChairID()))
{
if( !m_bStustee && ++m_wTimeOutCount>=MAX_TIME_OUT)
{
m_wTimeOutCount = 0;
OnStusteeControl((WPARAM)TRUE,0);
//提示信息
if(m_pIStringMessage!=NULL)
m_pIStringMessage->InsertSystemString(TEXT("由于您多次超时,切换为“系统托管”模式"));
}
AutomatismOutCard();
}
return true;
}
//播放声音
if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN"));
return true;
}
case IDI_CALL_CARD: //用户叫牌
{
//超时判断
if ((nElapse==0)||((m_bStustee==true)&&(nElapse<(TIME_CALL_CARD))))
{
//隐藏控件
m_GameClientView.m_CallCardWnd.ShowWindow(SW_HIDE);
m_GameClientView.m_CallCardWnd.UpdateCallControl(CALL_NONE);
//发送消息
if (IsLookonMode()==false)
{
SendSocketData(SUB_C_CALL_FINISH);
KillGameClock(IDI_CALL_CARD);
}
return true;
}
return true;
}
case IDI_START_GAME: //开始游戏
{
if ((nElapse==0)||((m_bStustee==true)&&(nElapse<(TIME_START_GAME))))
{
if ((IsLookonMode()==false)&&(wChairID==GetMeChairID()))
{
if( m_bStustee )
OnStart(0,0);
else
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
return true;
}
if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN"));
return true;
}
case IDI_SEND_CONCEAL: //发送底牌
{
if ((nElapse==0)||((m_bStustee==true)&&(nElapse<(TIME_SEND_CONCEAL))))
{
//自动留底
if ((IsLookonMode()==false)&&(wChairID==GetMeChairID()))
{
//删除定时器
KillGameClock(IDI_SEND_CONCEAL);
//删除扑克
m_cbHandCardCount-=m_cbConcealCount;
m_GameLogic.RemoveCard(m_cbConcealCard,m_cbConcealCount,m_cbHandCardData,m_cbHandCardCount+m_cbConcealCount);
//设置界面
m_GameClientView.m_btSendConceal.ShowWindow(SW_HIDE);
m_GameClientView.m_btSendConceal.EnableWindow(FALSE);
SetHandCardControl(m_cbHandCardData,m_cbHandCardCount);
//构造数据
CMD_C_ConcealCard ConcealCard;
ConcealCard.cbConcealCount=m_cbConcealCount;
CopyMemory(ConcealCard.cbConcealCard,m_cbConcealCard,m_cbConcealCount*sizeof(BYTE));
//发送数据
SendSocketData(SUB_C_CONCEAL_CARD,&ConcealCard,sizeof(ConcealCard));
//提示信息
if (m_bStustee==false && m_pIStringMessage!=NULL)
m_pIStringMessage->InsertSystemString(TEXT("限定的时间到了,系统为您自动埋底牌"));
return false;
}
return true;
}
if ((nElapse<=3)&&(wChairID==GetMeChairID())&&(IsLookonMode()==false)) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WARN"));
return true;
}
}
return false;
}
//旁观消息
bool CGameClientEngine::OnEventLookonMode(VOID * pData, WORD wDataSize)
{
//扑克控制
m_GameClientView.m_HandCardControl.SetDisplayFlag((IsAllowLookon()==true));
if( m_cbRemnantCardCount > 0 )
{
m_GameLogic.SortCardList(m_cbDispatchCardData,m_cbDispatchCardCount);
SetHandCardControl(m_cbDispatchCardData,m_cbDispatchCardCount);
}
else SetHandCardControl(m_cbHandCardData,m_cbHandCardCount);
//功能按钮
m_GameClientView.m_btConcealCard.EnableWindow(((m_cbConcealCount>0)&&((IsLookonMode==false)||(IsAllowLookon()==true)))?TRUE:FALSE);
return true;
}
//游戏消息
bool CGameClientEngine::OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
switch (wSubCmdID)
{
case SUB_S_GAME_START: //游戏开始
{
return OnSubGameStart(pData,wDataSize);
}
case SUB_S_SEND_CARD: //发送扑克
{
return OnSubSendCard(pData,wDataSize);
}
case SUB_S_CALL_CARD: //用户叫牌
{
return OnSubCallCard(pData,wDataSize);
}
case SUB_S_SEND_CONCEAL: //发送底牌
{
return OnSubSendConceal(pData,wDataSize);
}
case SUB_S_GAME_PLAY: //游戏开始
{
return OnSubGamePlay(pData,wDataSize);
}
case SUB_S_OUT_CARD: //用户出牌
{
return OnSubOutCard(pData,wDataSize);
}
case SUB_S_THROW_RESULT: //甩牌结果
{
return OnSubThrowResult(pData,wDataSize);
}
case SUB_S_TURN_BALANCE: //一轮结算
{
return OnSubTurnBalance(pData,wDataSize);
}
case SUB_S_GAME_END: //游戏结束
{
return OnSubGameEnd(pData,wDataSize);
}
case SUB_S_STRUSTEE: //用户托管
{
return OnSubStrustee(pData,wDataSize);
}
case SUB_S_REQUEST_LEAVE: //请求离开
{
return OnSubRequestLeave(pData,wDataSize);
}
case SUB_S_BATCH_CARD: //批量出牌
{
return OnSubBatchCard(pData,wDataSize);
}
}
return true;
}
|