📄 gameclientview.cpp
字号:
#include "StdAfx.h"
#include "Resource.h"
#include "GameClientView.h"
#include "GameClientDlg.h"
//////////////////////////////////////////////////////////////////////////
//按钮标识
#define IDC_START 100 //开始按钮
#define IDC_ADD_GOLD 101 //加注按钮
#define IDC_GIVE_UP 102 //放弃按钮
#define IDC_FOLLOW 103 //跟注按钮
#define IDC_SHOW_HAND 104 //梭哈按钮
//定时器标识
#define IDI_SEND_CARD 107 //发牌定时器
#define IDI_SHOW_CARD 108 //
#define IDI_USER_SHOW_HAND 109 //
#define SPEED_MOVE_CARD 30 //
#define TIME_USER_SHOW_HAND 3000 //
//发牌定义
#define SEND_STEP_COUNT 6 //步数
#define SPEED_SEND_CARD 30 //发牌速度
#define MAX_COUNT 5
#define SHOW_CARD_ANIMATE //设置看牌动画,如果要取消动画,则注释掉
//////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CGameClientView, CGameFrameView)
ON_WM_CREATE()
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_FOLLOW, OnFollow)
ON_BN_CLICKED(IDC_GIVE_UP, OnGiveUp)
ON_BN_CLICKED(IDC_ADD_GOLD, OnAddGold)
ON_BN_CLICKED(IDC_SHOW_HAND, OnShowHand)
ON_WM_TIMER()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////
//构造函数
CGameClientView::CGameClientView(void) : CGameFrameView(true,24)
{
//设置变量
m_lMaxGold=0L;
m_lBasicGold=0L;
m_bUserShowHand = false;
ZeroMemory( m_lUserGold,sizeof(m_lUserGold) );
//动画变量
m_SendCardPos.SetPoint(0,0);
m_SendCardCurPos = m_SendCardPos;
m_nStepCount = SEND_STEP_COUNT;
m_nXStep = 0;
m_nYStep = 0;
//加载位图
HINSTANCE hInstance=AfxGetInstanceHandle();
m_ImageTitle.SetLoadInfo(IDB_TITLE,hInstance);
m_ImageViewFill.SetLoadInfo(IDB_VIEW_FILL,hInstance);
m_ImageViewCenter.SetLoadInfo(IDB_BACK_GROUND,hInstance);
m_ImageCardBack.SetLoadInfo(IDB_CARD,hInstance);
m_PngShowHand.LoadImage( hInstance,TEXT("SHOW_HAND") );
return;
}
//析构函数
CGameClientView::~CGameClientView(void)
{
}
//建立消息
int CGameClientView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (__super::OnCreate(lpCreateStruct)==-1) return -1;
//创建控件
CRect CreateRect(0,0,0,0);
m_GoldControl.Create(NULL,NULL,WS_CHILD|WS_CLIPSIBLINGS,CreateRect,this,8,NULL);
m_ScoreView.Create(NULL,NULL,WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,CreateRect,this,9);
//创建按钮
m_btStart.Create(NULL,WS_CHILD,CreateRect,this,IDC_START);
m_btFollow.Create(NULL,WS_CHILD,CreateRect,this,IDC_FOLLOW);
m_btGiveUp.Create(NULL,WS_CHILD,CreateRect,this,IDC_GIVE_UP);
m_btAddGold.Create(NULL,WS_CHILD,CreateRect,this,IDC_ADD_GOLD);
m_btShowHand.Create(NULL,WS_CHILD,CreateRect,this,IDC_SHOW_HAND);
//加载位图
HINSTANCE hInstance=AfxGetInstanceHandle();
m_btStart.SetButtonImage(IDB_BT_START,hInstance,false);
m_btFollow.SetButtonImage(IDB_BT_FOLLOW,hInstance,false);
m_btGiveUp.SetButtonImage(IDB_BT_GIVE_UP,hInstance,false);
m_btAddGold.SetButtonImage(IDB_BT_ADD_GOLD,hInstance,false);
m_btShowHand.SetButtonImage(IDB_BT_SHOW_HAND,hInstance,false);
//test
//BYTE byCard[] = {
// 0x01,0x09,0x0a,0x0b,0x0c
//};
//for( WORD i = 0; i < GAME_PLAYER; i++ )
//{
// m_CardControl[i].SetCardData( byCard,5 );
// //SetUserGoldInfo( i,false,1 );
// //SetUserGoldInfo( i,true,456 );
//}
//m_CardControl[2].AllowPositively( true );
//end test
return 0;
}
//开始按钮
void CGameClientView::OnStart()
{
AfxGetMainWnd()->SendMessage(IDM_START,0,0);
return;
}
//跟注按钮
void CGameClientView::OnFollow()
{
AfxGetMainWnd()->SendMessage(IDM_FOLLOW,0,0);
return;
}
//放弃按钮
void CGameClientView::OnGiveUp()
{
AfxGetMainWnd()->SendMessage(IDM_GIVE_UP,0,0);
return;
}
//加注按钮
void CGameClientView::OnAddGold()
{
AfxGetMainWnd()->SendMessage(IDM_ADD_GOLD,0,0);
return;
}
//梭哈按钮
void CGameClientView::OnShowHand()
{
AfxGetMainWnd()->SendMessage(IDM_SHOWHAND,0,0);
return;
}
//重置界面
void CGameClientView::ResetGameView()
{
//设置变量
m_lMaxGold=0L;
m_lBasicGold=0L;
m_bUserShowHand = false;
ZeroMemory( m_lUserGold,sizeof(m_lUserGold) );
//动画变量
m_SendCardCurPos = m_SendCardPos;
m_nStepCount = 0;
m_nXStep = 0;
m_nYStep = 0;
m_SendCardItemArray.RemoveAll();
//设置控件
m_btStart.ShowWindow(SW_HIDE);
m_btFollow.ShowWindow(SW_HIDE);
m_btGiveUp.ShowWindow(SW_HIDE);
m_btAddGold.ShowWindow(SW_HIDE);
m_btShowHand.ShowWindow(SW_HIDE);
m_ScoreView.ShowWindow(SW_HIDE);
m_GoldControl.ShowWindow(SW_HIDE);
//设置筹码
for (int i=0;i<CountArray(m_GoldView);i++) m_GoldView[i].SetGold(0L);
//设置扑克
for (int i=0;i<CountArray(m_CardControl);i++)
{
m_CardControl[i].SetCardData(NULL,0);
m_CardControl[i].ShowFirstCard(false);
m_CardControl[i].AllowPositively(false);
}
return;
}
//调整控件
void CGameClientView::RectifyGameView(int nWidth, int nHeight)
{
//设置坐标
m_ptFace[0].x=nWidth/2;
m_ptFace[0].y=nHeight/2-347;
m_ptName[0].x=nWidth/2+37;
m_ptName[0].y=nHeight/2-347;
m_ptTimer[0].x=nWidth/2-45;
m_ptTimer[0].y=nHeight/2-326;
m_ptReady[0].x=nWidth/2-47;
m_ptReady[0].y=nHeight/2-326;
m_ptFace[1].x=nWidth/2+341;
m_ptFace[1].y=nHeight/2-90;
m_ptName[1].x=nWidth/2+336;
m_ptName[1].y=nHeight/2-90;
m_ptTimer[1].x=nWidth/2+352;
m_ptTimer[1].y=nHeight/2-115;
m_ptReady[1].x=nWidth/2+330;
m_ptReady[1].y=nHeight/2-115;
m_ptFace[2].x=nWidth/2-32;
m_ptFace[2].y=nHeight/2+316;
m_ptName[2].x=nWidth/2+5;
m_ptName[2].y=nHeight/2+316;
m_ptTimer[2].x=nWidth/2-77;
m_ptTimer[2].y=nHeight/2+327;
m_ptReady[2].x=nWidth/2+10;
m_ptReady[2].y=nHeight/2+96;
m_ptFace[3].x=nWidth/2-373;
m_ptFace[3].y=nHeight/2-90;
m_ptName[3].x=nWidth/2-336;
m_ptName[3].y=nHeight/2-90;
m_ptTimer[3].x=nWidth/2-354;
m_ptTimer[3].y=nHeight/2-115;
m_ptReady[3].x=nWidth/2-333;
m_ptReady[3].y=nHeight/2-115;
//筹码控件
int nXCenterPos=nWidth/2;
int nYCenterPos=nHeight/2;
m_GoldStation[0].SetPoint(nXCenterPos-35,nYCenterPos-105);
m_GoldStation[1].SetPoint(nXCenterPos+33,nYCenterPos-105);
m_GoldStation[2].SetPoint(nXCenterPos+102,nYCenterPos-33);
m_GoldStation[3].SetPoint(nXCenterPos+102,nYCenterPos+39);
m_GoldStation[4].SetPoint(nXCenterPos+31,nYCenterPos+97);
m_GoldStation[5].SetPoint(nXCenterPos-35,nYCenterPos+97);
m_GoldStation[6].SetPoint(nXCenterPos-102,nYCenterPos+39);
m_GoldStation[7].SetPoint(nXCenterPos-102,nYCenterPos-33);
//按钮控件
HDWP hDwp=BeginDeferWindowPos(32);
const UINT uFlags=SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCOPYBITS|SWP_NOSIZE;
//开始按钮
CRect rcStart;
m_btStart.GetWindowRect(&rcStart);
DeferWindowPos(hDwp,m_btStart,NULL,(nWidth-rcStart.Width())/2+10,nHeight/2+156,0,0,uFlags);
//控制按钮
CRect rcControl;
m_btAddGold.GetWindowRect(&rcControl);
DeferWindowPos(hDwp,m_btAddGold,NULL,nWidth/2+125,nHeight/2+303-rcControl.Height(),0,0,uFlags);
DeferWindowPos(hDwp,m_btFollow,NULL,nWidth/2+125,nHeight/2+303-rcControl.Height(),0,0,uFlags);
DeferWindowPos(hDwp,m_btShowHand,NULL,nWidth/2+rcControl.Width()+130,nHeight/2+303-rcControl.Height(),0,0,uFlags);
DeferWindowPos(hDwp,m_btGiveUp,NULL,nWidth/2+rcControl.Width()*2+135,nHeight/2+303-rcControl.Height(),0,0,uFlags);
EndDeferWindowPos(hDwp);
//加注窗口
m_GoldControl.SetBenchmarkPos( nWidth/2+300,nHeight/2+293-rcControl.Height() );
//成绩窗口
CRect rcScoreView;
m_ScoreView.GetWindowRect(&rcScoreView);
m_ScoreView.MoveWindow((nWidth-rcScoreView.Width())/2,(nHeight-rcScoreView.Height())/2-10,rcScoreView.Width(),rcScoreView.Height());
//扑克控件
m_CardControl[0].SetBasicStation(CPoint(nWidth/2,nHeight/2-300),enXCenter,enYTop);
m_CardControl[1].SetBasicStation(CPoint(nWidth/2+373,nHeight/2),enXRight,enYCenter);
m_CardControl[2].SetBasicStation(CPoint(nWidth/2,nHeight/2+298),enXCenter,enYBottom);
m_CardControl[3].SetBasicStation(CPoint(nWidth/2-373,nHeight/2),enXLeft,enYCenter);
//发牌起始位置
m_SendCardPos.SetPoint(nWidth/2-40,nHeight/2-52);
return;
}
//绘画界面
void CGameClientView::DrawGameView(CDC * pDC, int nWidth, int nHeight)
{
//绘画背景
CImageHandle HandleTitle(&m_ImageTitle);
DrawViewImage(pDC,m_ImageViewFill,enMode_Spread);
DrawViewImage(pDC,m_ImageViewCenter,enMode_Centent);
m_ImageTitle.BitBlt(pDC->m_hDC,m_nXBorder,m_nYBorder);
//绘画用户
WORD wUserTimer=0;
TCHAR szBuffer[64];
pDC->SetTextColor(RGB(255,255,0));
for (WORD i=0;i<4;i++)
{
//变量定义
const tagUserData * pUserData=GetUserInfo(i);
////////////////////////////////////////////////////////
//tagUserData *pUserData = new tagUserData;
//strcpy( pUserData->szName, "dkfjdkfj" );
//pUserData->cbUserStatus = US_READY ;
//wUserTimer = 50;
//////////////////////////////////////////////////////////
if (pUserData!=NULL)
{
//用户名字
pDC->SetTextAlign((i==1)?(TA_RIGHT|TA_TOP):(TA_LEFT|TA_TOP));
pDC->TextOut(m_ptName[i].x,m_ptName[i].y,pUserData->szName,lstrlen(pUserData->szName));
//用户金币
LONG lUserScore = (pUserData->cbUserStatus==US_PLAY)?m_lUserGold[i]-m_GoldView[i*2].GetGold()-m_GoldView[i*2+1].GetGold():pUserData->lScore;
_snprintf(szBuffer,sizeof(szBuffer),TEXT("%ld"),lUserScore);
pDC->TextOut(m_ptName[i].x,m_ptName[i].y+16,szBuffer,lstrlen(szBuffer));
//其他信息
wUserTimer=GetUserTimer(i);
if (wUserTimer!=0) DrawUserTimer(pDC,m_ptTimer[i].x,m_ptTimer[i].y,wUserTimer);
if (pUserData->cbUserStatus==US_READY) DrawUserReady(pDC,m_ptReady[i].x,m_ptReady[i].y);
DrawUserFace(pDC,pUserData->wFaceID,m_ptFace[i].x,m_ptFace[i].y,pUserData->cbUserStatus==US_OFFLINE);
}
}
for( WORD i = 0; i < GAME_PLAYER; i++ )
m_CardControl[i].DrawCardControl(pDC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -