牛牛-带机器人【源码】
http://img.woaidaima.com//upload/image/20170509/1494312129532028626.jpghttp://img.woaidaima.com//upload/image/20170509/1494312131479057306.jpg#include "Stdafx.h"#include "AndroidUserItemSink.h"
//////////////////////////////////////////////////////////////////////////
//辅助时间
#define TIME_LESS 1 //最少时间
//游戏时间
#define TIME_USER_CALL_BANKER 2 //叫庄定时器
#define TIME_USER_START_GAME 3 //开始定时器
#define TIME_USER_ADD_SCORE 3 //下注定时器
#define TIME_USER_OPEN_CARD 12 //摊牌定时器
//游戏时间
#define IDI_ANDROID_ITEM_SINK 100
#define IDI_START_GAME (IDI_ANDROID_ITEM_SINK+0) //开始时间
#define IDI_CALL_BANKER (IDI_ANDROID_ITEM_SINK+1) //叫庄时间
#define IDI_USER_ADD_SCORE (IDI_ANDROID_ITEM_SINK+2) //下注时间
#define IDI_OPEN_CARD (IDI_ANDROID_ITEM_SINK+3) //开牌时间
//////////////////////////////////////////////////////////////////////////
//构造函数
CAndroidUserItemSink::CAndroidUserItemSink()
{
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
//接口变量
m_pIAndroidUserItem=NULL;
return;
}
//析构函数
CAndroidUserItemSink::~CAndroidUserItemSink()
{
}
//接口查询
void *CAndroidUserItemSink::QueryInterface(REFGUID Guid, DWORD dwQueryVer)
{
QUERYINTERFACE(IAndroidUserItemSink,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IAndroidUserItemSink,Guid,dwQueryVer);
return NULL;
}
//初始接口
boolCAndroidUserItemSink::Initialization(IUnknownEx * pIUnknownEx)
{
//查询接口
ASSERT(QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem)!=NULL);
m_pIAndroidUserItem=QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem);
//错误判断
if (m_pIAndroidUserItem==NULL)
{
ASSERT(FALSE);
return false;
}
return true;
}
//重置接口
boolCAndroidUserItemSink::RepositionSink()
{
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
return true;
}
//时间消息
boolCAndroidUserItemSink::OnEventTimer(UINT nTimerID)
{
switch (nTimerID)
{
case IDI_START_GAME: //开始定时器
{
//发送准备
m_pIAndroidUserItem->SendUserReady(NULL,0);
return true;
}
case IDI_CALL_BANKER: //叫庄定时
{
//设置变量
CMD_C_CallBanker CallBanker;
CallBanker.bBanker = rand()%2;
//发送信息
m_pIAndroidUserItem->SendSocketData(SUB_C_CALL_BANKER,&CallBanker,sizeof(CallBanker));
return true;
}
case IDI_USER_ADD_SCORE: //加注定时
{
//可下注筹码
LONGLONG lUserMaxScore;
ZeroMemory(lUserMaxScore,sizeof(lUserMaxScore));
LONGLONG lTemp=m_lTurnMaxScore;
for (WORD i=0;i<GAME_PLAYER;i++)
{
if(i>0)lTemp/=2;
lUserMaxScore=__max(lTemp,1L);
}
//发送消息
CMD_C_AddScore AddScore;
AddScore.lScore=lUserMaxScore;
m_pIAndroidUserItem->SendSocketData(SUB_C_ADD_SCORE,&AddScore,sizeof(AddScore));
return true;
}
case IDI_OPEN_CARD: //开牌定时
{
//发送消息
CMD_C_OxCard OxCard;
OxCard.bOX=(m_GameLogic.GetCardType(m_HandCardData,MAX_COUNT)>0)?TRUE:FALSE;
m_pIAndroidUserItem->SendSocketData(SUB_C_OPEN_CARD,&OxCard,sizeof(OxCard));
return true;
}
}
return false;
}
//游戏消息
boolCAndroidUserItemSink::OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
switch (wSubCmdID)
{
case SUB_S_CALL_BANKER: //用户叫庄
{
//消息处理
return OnSubCallBanker(pData,wDataSize);
}
case SUB_S_GAME_START: //游戏开始
{
//消息处理
return OnSubGameStart(pData,wDataSize);
}
case SUB_S_ADD_SCORE: //用户下注
{
//消息处理
return OnSubAddScore(pData,wDataSize);
}
case SUB_S_SEND_CARD: //发牌消息
{
//消息处理
return OnSubSendCard(pData,wDataSize);
}
case SUB_S_OPEN_CARD: //用户摊牌
{
//消息处理
return OnSubOpenCard(pData,wDataSize);
}
case SUB_S_PLAYER_EXIT: //用户强退
{
//消息处理
return OnSubPlayerExit(pData,wDataSize);
}
case SUB_S_GAME_END: //游戏结束
{
//消息处理
return OnSubGameEnd(pData,wDataSize);
}
}
//错误断言
ASSERT(FALSE);
return true;
}
//游戏消息
boolCAndroidUserItemSink::OnEventFrameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
return true;
}
//场景消息
boolCAndroidUserItemSink::OnEventSceneMessage(BYTE cbGameStatus, bool bLookonOther, VOID * pData, WORD wDataSize)
{
switch (cbGameStatus)
{
case GS_TK_FREE: //空闲状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusFree)) return false;
//开始时间
UINT nElapse=rand()%(3)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
return true;
}
case GS_TK_CALL: // 叫庄状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusCall)) return false;
CMD_S_StatusCall * pStatusCall=(CMD_S_StatusCall *)pData;
//始叫用户
if(pStatusCall->wCallBanker==m_pIAndroidUserItem->GetChairID())
{
//叫庄时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_BANKER,nElapse);
}
return true;
}
case GS_TK_SCORE: //下注状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusScore)) return false;
CMD_S_StatusScore * pStatusScore=(CMD_S_StatusScore *)pData;
//设置变量
m_lTurnMaxScore=pStatusScore->lTurnMaxScore;
WORD wMeChairId = m_pIAndroidUserItem->GetChairID();
//设置筹码
if (pStatusScore->lTurnMaxScore>0L && pStatusScore->lTableScore==0L)
{
//下注时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_USER_ADD_SCORE,nElapse);
}
return true;
}
case GS_TK_PLAYING: //游戏状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusPlay)) return false;
CMD_S_StatusPlay * pStatusPlay=(CMD_S_StatusPlay *)pData;
//设置变量
m_lTurnMaxScore=pStatusPlay->lTurnMaxScore;
WORD wMeChiarID=m_pIAndroidUserItem->GetChairID();
CopyMemory(m_HandCardData,pStatusPlay->cbHandCardData,MAX_COUNT);
//控件处理
if(pStatusPlay->bOxCard==0xff)
{
//开牌时间
UINT nElapse=rand()%(6)+TIME_LESS*2;
m_pIAndroidUserItem->SetGameTimer(IDI_OPEN_CARD,nElapse);
}
return true;
}
}
ASSERT(FALSE);
return false;
}
//用户进入
voidCAndroidUserItemSink::OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户离开
voidCAndroidUserItemSink::OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户积分
voidCAndroidUserItemSink::OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户状态
voidCAndroidUserItemSink::OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户段位
voidCAndroidUserItemSink::OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户叫庄
bool CAndroidUserItemSink::OnSubCallBanker(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_CallBanker)) return false;
CMD_S_CallBanker * pCallBanker=(CMD_S_CallBanker *)pBuffer;
//始叫用户
if(pCallBanker->wCallBanker==m_pIAndroidUserItem->GetChairID())
{
//叫庄时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_BANKER,nElapse);
}
return true;
}
//游戏开始
bool CAndroidUserItemSink::OnSubGameStart(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_GameStart)) return false;
CMD_S_GameStart * pGameStart=(CMD_S_GameStart *)pBuffer;
//设置变量
m_lTurnMaxScore=pGameStart->lTurnMaxScore;
//设置筹码
if (pGameStart->lTurnMaxScore>0)
{
//下注时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_USER_ADD_SCORE,nElapse);
}
return true;
}
//用户下注
bool CAndroidUserItemSink::OnSubAddScore(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_AddScore)) return false;
CMD_S_AddScore * pAddScore=(CMD_S_AddScore *)pBuffer;
return true;
}
//发牌消息
bool CAndroidUserItemSink::OnSubSendCard(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_SendCard)) return false;
CMD_S_SendCard * pSendCard=(CMD_S_SendCard *)pBuffer;
//设置数据
WORD wMeChiarID=m_pIAndroidUserItem->GetChairID();
CopyMemory(m_HandCardData,pSendCard->cbCardData,sizeof(m_HandCardData));
//开牌时间
UINT nElapse=rand()%(6)+TIME_LESS*2;
m_pIAndroidUserItem->SetGameTimer(IDI_OPEN_CARD,nElapse);
return true;
}
//用户摊牌
bool CAndroidUserItemSink::OnSubOpenCard(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_Open_Card)) return false;
CMD_S_Open_Card * pOpenCard=(CMD_S_Open_Card *)pBuffer;
return true;
}
//用户强退
bool CAndroidUserItemSink::OnSubPlayerExit(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_PlayerExit)) return false;
CMD_S_PlayerExit * pPlayerExit=(CMD_S_PlayerExit *)pBuffer;
return true;
}
//游戏结束
bool CAndroidUserItemSink::OnSubGameEnd(const void * pBuffer, WORD wDataSize)
{
//效验参数
if (wDataSize!=sizeof(CMD_S_GameEnd)) return false;
CMD_S_GameEnd * pGameEnd=(CMD_S_GameEnd *)pBuffer;
//删除定时器
m_pIAndroidUserItem->KillGameTimer(IDI_CALL_BANKER);
m_pIAndroidUserItem->KillGameTimer(IDI_USER_ADD_SCORE);
m_pIAndroidUserItem->KillGameTimer(IDI_OPEN_CARD);
//开始时间
UINT nElapse=rand()%(3)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
//清理变量
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
return true;
}
//组件创建函数
DECLARE_CREATE_MODULE(AndroidUserItemSink);
//////////////////////////////////////////////////////////////////////////
页:
[1]