u22放炮100胡(机器人)【源码】
http://img.woaidaima.com//upload/image/20170520/1495279179484099730.pnghttp://img.woaidaima.com//upload/image/20170520/1495279181418093715.png#include "StdAfx.h"#include "ChooseWnd.h"
#include "CardControl.h"
#include ".\choosewnd.h"
//////////////////////////////////////////////////////////////////////////
#define IDC_OK 205 //确定按钮
BEGIN_MESSAGE_MAP(CChooseWnd, CWnd)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_SETCURSOR()
ON_WM_LBUTTONUP()
// ON_WM_LBUTTONDBLCLK()
// ON_WM_SIZING()
ON_BN_CLICKED(IDC_OK, OnOk)
ON_WM_SIZE()
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////
//构造函数
CChooseWnd::CChooseWnd()
{
//数据变量
m_bWeaveCount=0;
ZeroMemory(&m_ChiCardInfo,sizeof(m_ChiCardInfo));
ZeroMemory(m_bSelectEd,sizeof(m_bSelectEd));//kf jia
//运行变量
m_cbCurrentIndex=0xFF;
//m_wSelectWeaveCount=0;//kf jia
//m_wCanSelectWeaveCount=0;//kf jia
return;
}
//析构函数
CChooseWnd::~CChooseWnd()
{
}
//设置基准
void CChooseWnd::SetBenchmarkPos(int nXPos, int nYPos)
{
//设置变量
m_ControlPoint.x=nXPos;
m_ControlPoint.y=nYPos;
//调整位置
if (m_hWnd!=NULL)
{
int nWidth=m_SizeLeft.cx+m_SizeRight.cx+m_bWeaveCount*m_SizeCell.cx;
SetWindowPos(NULL,m_ControlPoint.x-nWidth,m_ControlPoint.y-m_SizeCell.cy,nWidth,m_SizeCell.cy,SWP_NOZORDER);
}
return;
}
//设置数据
//bool CChooseWnd::SetChooseWeave(tagChiCardInfo ChiCardInfo, BYTE cbWeaveCount)//YB
bool CChooseWnd::SetChooseWeave(tagChiCardInfo ChiCardInfo, BYTE cbWeaveCount,BYTE m_cbCenterCardData,WORD m_OutCardCount,BYTE cbCardIndex)//KF JIA
{
//效验数据
ASSERT(cbWeaveCount<CountArray(m_ChiCardInfo));
if (cbWeaveCount>=CountArray(m_ChiCardInfo)) return false;
m_btOK.EnableWindow(false);
ZeroMemory(m_cbCardIndex,sizeof(m_cbCardIndex));
CopyMemory(m_cbCardIndex,cbCardIndex,sizeof(m_cbCardIndex));
//设置数据
m_bWeaveCount=cbWeaveCount;
m_cbOutCardCount=m_OutCardCount;
m_cbOutCardData=m_cbCenterCardData;//kf jia
CopyMemory(&m_ChiCardInfo,ChiCardInfo,sizeof(m_ChiCardInfo)*cbWeaveCount);//这儿取吃牌的组合
ZeroMemory(m_bSelectEd,sizeof(m_bSelectEd));
//m_wSelectWeaveCount=0;
m_iChiKind=0;
//调整位置
int nWidth=m_SizeLeft.cx+m_SizeRight.cx+m_bWeaveCount*m_SizeCell.cx;
SetWindowPos(NULL,m_ControlPoint.x-nWidth,m_ControlPoint.y-m_SizeCell.cy,nWidth,m_SizeCell.cy,SWP_NOZORDER|SWP_SHOWWINDOW);
return true;
}
//kf jia end
//重画函数
void CChooseWnd::OnPaint()
{
CPaintDC dc(this);
//获取位置
CRect rcClient;
GetClientRect(&rcClient);
//加载资源
//CImageHandle HandleBackL(&m_ImageBackL);
//CImageHandle HandleBackM(&m_ImageBackM);
//CImageHandle HandleBackR(&m_ImageBackR);
//CImageHandle HandleBackH(&m_ImageBackH);
//CImageHandle HandleBackS(&m_ImageBackS);
//创建缓冲
CDC BufferDC;
CBitmap BufferImage;
BufferDC.CreateCompatibleDC(&dc);
BufferImage.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
//设置缓冲
BufferDC.SelectObject(&BufferImage);
//绘画界面
m_ImageBackL.BitBlt(BufferDC,0,0);
m_ImageBackR.BitBlt(BufferDC,rcClient.Width()-m_ImageBackR.GetWidth(),0);
for (int i=0;i<m_bWeaveCount;i++)
{
//绘画背景
int nXPos=m_SizeLeft.cx+m_SizeCell.cx*i;
//if (i==m_cbCurrentIndex) m_ImageBackH.BitBlt(BufferDC,nXPos,0);//yb
/*else */if (m_bSelectEd) m_ImageBackS.BitBlt(BufferDC,nXPos,0);//kf jia
else m_ImageBackM.BitBlt(BufferDC,nXPos,0);
//绘画扑克
g_CardResource.m_ImageUserBottom.DrawCardItem(&BufferDC,m_ChiCardInfo.cbCardData,nXPos+6,10,false);
g_CardResource.m_ImageUserBottom.DrawCardItem(&BufferDC,m_ChiCardInfo.cbCardData,nXPos+6,30,false);
g_CardResource.m_ImageUserBottom.DrawCardItem(&BufferDC,m_ChiCardInfo.cbCardData,nXPos+6,50,false);
}
//绘画界面
dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),&BufferDC,0,0,SRCCOPY);
//清理资源
BufferImage.DeleteObject();
BufferDC.DeleteDC();
return;
}
//建立消息
int CChooseWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (__super::OnCreate(lpCreateStruct)==-1) return -1;
//加载资源
HINSTANCE hInstance=AfxGetInstanceHandle();
/*m_ImageBackL.SetLoadInfo(IDB_CHOOSE_L,hInstance);
m_ImageBackM.SetLoadInfo(IDB_CHOOSE_M,hInstance);
m_ImageBackR.SetLoadInfo(IDB_CHOOSE_R,hInstance);
m_ImageBackH.SetLoadInfo(IDB_CHOOSE_H,hInstance);
m_ImageBackS.SetLoadInfo(IDB_CHOOSE_S,hInstance);*/
m_ImageBackL.LoadFromResource(hInstance,IDB_CHOOSE_L);
m_ImageBackM.LoadFromResource(hInstance,IDB_CHOOSE_M);
m_ImageBackR.LoadFromResource(hInstance,IDB_CHOOSE_R);
m_ImageBackH.LoadFromResource(hInstance,IDB_CHOOSE_H);
m_ImageBackS.LoadFromResource(hInstance,IDB_CHOOSE_S);
//加载资源
//CImageHandle HandleBackL(&m_ImageBackL);
//CImageHandle HandleBackM(&m_ImageBackM);
//CImageHandle HandleBackR(&m_ImageBackR);
//获取大小
m_SizeCell.cx=m_ImageBackM.GetWidth();
m_SizeCell.cy=m_ImageBackM.GetHeight();
m_SizeLeft.cx=m_ImageBackL.GetWidth();
m_SizeLeft.cy=m_ImageBackL.GetHeight();
m_SizeRight.cx=m_ImageBackR.GetWidth();
m_SizeRight.cy=m_ImageBackR.GetHeight();
CRect rcCreate(0,0,0,0);
m_btOK.Create(NULL,WS_CHILD|WS_VISIBLE|WS_DISABLED,rcCreate,this,IDC_OK);//KF JIA
m_btOK.SetButtonImage(IDB_BT_OK,AfxGetInstanceHandle(),false,false);
m_btOK.EnableWindow(false);
return 0;
}
//鼠标消息
void CChooseWnd::OnLButtonUp(UINT nFlags, CPoint Point)
{
__super::OnLButtonUp(nFlags, Point);
//状态判断
if (m_cbCurrentIndex>=m_bWeaveCount) return;
m_bSelectEd=!m_bSelectEd;
/*CString s;
s.Format("当前选择为类别:%d",m_ChiCardInfo.cbChiKind);
AfxMessageBox(s);*/
tagChiCardInfo TmpChiCardInfo;
m_cbSelectedOutCardCount=0;//已选中的当前要吃的牌的只数
m_iChiKind=0;
BYTE m_cbSelectWeave=0;//已选中的组数
//bool bAllShun=true;//所选择的是否全部为顺
//BYTE bShunCount=0;//顺子数
ZeroMemory(TmpChiCardInfo,sizeof(TmpChiCardInfo));
for (WORD i=0;i<m_bWeaveCount;i++)
{
if (m_bSelectEd)//该组已选中了
{
for (WORD j=0;j<3;j++)
{
TmpChiCardInfo.cbCardData =m_ChiCardInfo.cbCardData;//保存到临时组合中
if (m_ChiCardInfo.cbCardData==m_cbOutCardData) m_cbSelectedOutCardCount++;//如果这只牌为当前要吃的牌则加1
}
m_cbSelectWeave++;
m_iChiKind+=m_ChiCardInfo.cbChiKind;
//if ((m_ChiCardInfo.cbChiKind==CK_EQS)||(m_ChiCardInfo.cbChiKind==CK_XXD)||(m_ChiCardInfo.cbChiKind==CK_XDD)||(m_ChiCardInfo.cbChiKind==CK_NULL)) bAllShun =false;//判断是否全部为顺
//if ((m_ChiCardInfo.cbChiKind==CK_EQS)||(m_ChiCardInfo.cbChiKind==CK_XXD)||(m_ChiCardInfo.cbChiKind==CK_XDD)) bShunCount++; //统计顺子数
}
}
//CStdioFile mfile;
//CString s;
//mfile.Open("c:\\abc.txt",CFile::modeReadWrite);
//mfile.SeekToEnd(); //
//for (WORD i=0;i<20;i++)
// s.Format("OnLButtonUP中%d:%d\n\r",i,m_cbCardIndex);
// mfile.Close();
if ((m_cbSelectedOutCardCount==m_cbOutCardCount)&&(ISChi(m_cbCardIndex,TmpChiCardInfo,m_cbSelectWeave)==true))
//{
// if ((bAllShun==true)&&(bShunCount>1)) //条件(bShunCount>1)过滤家里有三三四 进五不能吃的问题
// {
// if (ISChi(m_cbCardIndex,TmpChiCardInfo,m_cbSelectWeave)==true) //已选的组合数中吃牌的张数与手上牌加上进字后的张数相同并且满足吃的条件
// m_btOK.EnableWindow(true);
// else
// m_btOK.EnableWindow(false);
// }
// else
// m_btOK.EnableWindow(true);
//}
m_btOK.EnableWindow(true);
else
m_btOK.EnableWindow(false);
//if (m_bSelectEd)
//{
// m_wSelectWeaveCount++;
// m_iChiKind+=m_ChiCardInfo.cbChiKind;
//}
//else
//{
// m_wSelectWeaveCount--;
// m_iChiKind-=m_ChiCardInfo.cbChiKind;
//}
//
//if (m_cbWeaveCount==1) m_wCanSelectWeaveCount=m_wOldCanSelectWeaveCount;
//if (m_cbWeaveCount==2)
//{
// bool bBianLe=false;
// for (int i=0;i<m_bWeaveCount;i++)
// {
// BYTE CenterDataCount=0;
// /*if (m_bSelectEd)
// {*/
// for (WORD k=0;k<3;k++)
// if (m_ChiCardInfo.cbCardData==m_cbOutCardData)
// {
// CenterDataCount++;
// if (CenterDataCount>=2) break;
// }
// //}
// if(CenterDataCount>=2)
// {
// m_wCanSelectWeaveCount=m_wOldCanSelectWeaveCount-1;
// bBianLe=true;
// break;
// }
// }
// if (bBianLe==false) m_wCanSelectWeaveCount=m_wOldCanSelectWeaveCount;
//}
//
//if (m_cbWeaveCount>2)
//{
// bool bBianLe=false;
// for (int i=0;i<m_bWeaveCount;i++)
// {
// BYTE CenterDataCount=0;
// if (m_bSelectEd)
// {
// for (WORD k=0;k<3;k++)
// if (m_ChiCardInfo.cbCardData==m_cbOutCardData)
// {
// CenterDataCount++;
// if (CenterDataCount>=2) break;
// }
// }
// if(CenterDataCount>=2)
// {
// m_wCanSelectWeaveCount=m_wOldCanSelectWeaveCount-1;
// bBianLe=true;
// break;
// }
// }
// if (bBianLe==false) m_wCanSelectWeaveCount=m_wOldCanSelectWeaveCount;
//}
/*if(m_wSelectWeaveCount==m_wCanSelectWeaveCount)
m_btOK.EnableWindow(true);
else
m_btOK.EnableWindow(false);*/
//CString s;
//s.Format("能吃的组数:%d,已选组数:%d,最初的组数:%d",m_wCanSelectWeaveCount,m_wSelectWeaveCount,m_wOldCanSelectWeaveCount);
//AfxMessageBox(s);
Invalidate(FALSE);
//发送消息
//CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,m_cbCurrentIndex,m_ChiCardInfo.cbChiKind); // kf guan
return;
}
//光标消息
BOOL CChooseWnd::OnSetCursor(CWnd * pWnd, UINT nHitTest, UINT message)
{
//获取选择
CPoint MousePoint;
GetCursorPos(&MousePoint);
ScreenToClient(&MousePoint);
//当前索引
BYTE cbIndex=0xFF;
if (MousePoint.x>=m_SizeLeft.cx)
{
cbIndex=(BYTE)((MousePoint.x-m_SizeLeft.cx)/m_SizeCell.cx);
if (cbIndex>=m_bWeaveCount) cbIndex=0xFF;
}
//设置索引
if (cbIndex!=m_cbCurrentIndex)
{
//设置变量
m_cbCurrentIndex=cbIndex;
//更新窗口
Invalidate(FALSE);
}
//设置光标
if (m_cbCurrentIndex!=0xFF)
{
SetCursor(LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_CARD_CUR)));
return TRUE;
}
return __super::OnSetCursor(pWnd,nHitTest,message);
}
//////////////////////////////////////////////////////////////////////////
//kf jia start
void CChooseWnd::AutoChi(void)
{
///自动选择吃牌kf jia 仅选二七十与一二三
bool Flag=false;
for(WORD i=0;i<6;i++)//最多只有6种吃牌
{
if ((m_ChiCardInfo.cbChiKind==CK_EQS) /*|| (m_ChiCardInfo.cbChiKind==CK_YES)*/)//是二七十或一二三才调用
{
CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,i,m_ChiCardInfo.cbChiKind);
Flag =true;
break;
//return;//返回第一组二七十或一二三
}
}
if (Flag==false)//不是二七十或一二三 放弃
CGameFrameEngine::GetInstance()->PostMessage(WM_USER+300,ACK_NULL,0);
return;
}
//void CChooseWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
//{
// // TODO: 在此添加消息处理程序代码和/或调用默认值
// //状态判断
// if (m_cbCurrentIndex>=m_bWeaveCount) return;
// CString s;
// if (m_wSelectWeaveCount!=m_wCanSelectWeaveCount)
// {
// s.Format("您选必须择%d组!,您已选择了%d组,请重新选择。",m_wCanSelectWeaveCount,m_wSelectWeaveCount);
// AfxMessageBox(s);
// return;
// }
// //s.Format("吃的类别总和为:%d",m_iChiKind);
// //AfxMessageBox(s);
//
// //发送消息
// //CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,m_cbCurrentIndex,m_ChiCardInfo.cbChiKind); // kf guan
// CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,m_cbCurrentIndex,m_iChiKind); // kf guan
// return;
//
// CWnd::OnLButtonDblClk(nFlags, point);
//}
void CChooseWnd::OnOk()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//状态判断
if (m_cbCurrentIndex>=m_bWeaveCount) return;
CString s;
if (m_cbSelectedOutCardCount!=m_cbOutCardCount)
{
s.Format(TEXT("您选择的组合不符合逻辑,请重新选择。"));
AfxMessageBox(s);
return;
}
/*s.Format("吃的类别总和为:%d",m_iChiKind);
AfxMessageBox(s);*/
//发送消息
//CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,m_cbCurrentIndex,m_ChiCardInfo.cbChiKind); // kf guan
CGameFrameEngine::GetInstance()->PostMessage(IDM_CHOOSE_CARD,m_cbCurrentIndex,m_iChiKind); // kf guan
return;
// CWnd::OnLButtonDblClk(nFlags, point);
}
//设置能够选择组数 kf jia
//LRESULT CChooseWnd::SetCanSelectWeaveCount(tagWeaveItem m_WeaveItemArray;,BYTE cbWeaveCount)
//{
// //变量定义
// m_wCanSelectWeaveCount=(BYTE)(wParam);
// m_wOldCanSelectWeaveCount=m_wCanSelectWeaveCount;//保存初始能选的组数
// m_cbWeaveCount=cbWeaveCount;
// /*CString s;
// s.Format("收到了最多可选组数的消息了啦:%d",m_wCanSelectWeaveCount);
// AfxMessageBox(s);*/
// return 0;
//};
CChooseWnd m_ChooseWnd; //扑克资源
//kf jia end
void CChooseWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
CRect rcButton/*,rcClient*/;
/*GetClientRect(&rcClient);*/
m_btOK.GetWindowRect(&rcButton);
/*CString s;
s.Format("窗口高度:%d,按钮高度:%d",rcClient.Height(),rcButton.Height());
AfxMessageBox(s);*/
m_btOK.SetWindowPos(NULL,cx-rcButton.Width()-10,cy-rcButton.Height()-3,0,0,SWP_NOSIZE|SWP_NOZORDER);
}
//判断中否能吃 KF JIA 能吃返回真,否则返回假
bool CChooseWnd::ISChi(BYTE cbCardIndex,tagChiCardInfo ChiCardInfo,BYTE ChiWeaveCount)
{
BYTE cbCardIndexTmp;
ZeroMemory(cbCardIndexTmp,sizeof(cbCardIndexTmp));
CopyMemory(cbCardIndexTmp,cbCardIndex,sizeof(cbCardIndexTmp));
//CStdioFile mfile;
//CString s;
//mfile.Open("c:\\abc.txt",CFile::modeReadWrite);
//mfile.SeekToEnd(); //
//for (WORD i=0;i<20;i++)
//{
// s.Format("ISCHi中%d:%d\n\r",i,cbCardIndexTmp);
// mfile.WriteString(s);
//}
CGameLogic m_GameLogic;
for (WORD j=0;j<ChiWeaveCount;j++)//检查每个组合中的张牌
for (WORD k=0;k<3;k++)
{
/*s.Format("牌:%d,牌位:%d:数量:%d\n\r",ChiCardInfo.cbCardData,m_GameLogic.SwitchToCardIndex(ChiCardInfo.cbCardData),cbCardIndexTmp.cbCardData)]);
mfile.WriteString(s);*/
cbCardIndexTmp.cbCardData)]--;
}
//mfile.WriteString("\n\r");
for (WORD j=0;j<ChiWeaveCount;j++)//检查每个组合中的张牌
for (WORD k=0;k<3;k++)
{
/*s.Format("牌:%d,牌位:%d:数量:%d,\n\r",ChiCardInfo.cbCardData,m_GameLogic.SwitchToCardIndex(ChiCardInfo.cbCardData),cbCardIndexTmp.cbCardData)]);
mfile.WriteString(s);*/
if (cbCardIndexTmp.cbCardData)]>4)
{ /*mfile.Close();*/ return false;}
}
//mfile.Close();
return true;
}
页:
[1]