📄 chessview.cpp
字号:
// chessView.cpp : implementation of the CChessView class
//
#include "stdafx.h"
#include "chess.h"
#include "chessDoc.h"
#include "chessView.h"
#include "Global1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChessView
IMPLEMENT_DYNCREATE(CChessView, CFormView)
BEGIN_MESSAGE_MAP(CChessView, CFormView)
//{{AFX_MSG_MAP(CChessView)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChessView construction/destruction
CChessView::CChessView()
: CFormView(CChessView::IDD)
{
//{{AFX_DATA_INIT(CChessView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CChessView::~CChessView()
{
}
void CChessView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChessView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CChessView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CChessView printing
BOOL CChessView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChessView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChessView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CChessView::OnPrint(CDC* pDC, CPrintInfo*)
{
// TODO: add code to print the controls
}
/////////////////////////////////////////////////////////////////////////////
// CChessView diagnostics
#ifdef _DEBUG
void CChessView::AssertValid() const
{
CFormView::AssertValid();
}
void CChessView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CChessDoc* CChessView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChessDoc)));
return (CChessDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChessView message handlers
void CChessView::OnPaint()
{
draw();
}
void CChessView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(pDoc->EnableClick){
CClientDC dc(this); // device context for painting
CBitmap bm1,bm2;//bm1=black,bm2=white
int wid,hei,i,j;
CDC memDC1,memDC2;
bm1.LoadBitmap(Black);
bm2.LoadBitmap(White);
CPoint p;
memDC1.CreateCompatibleDC(&dc);
memDC1.SelectObject(&bm1);
memDC2.CreateCompatibleDC(&dc);
memDC2.SelectObject(&bm2);
wid=25;
hei=25;
for(i=1;i<16;i++){
if((point.x-19-25*i)<=0){
for(j=1;j<16;j++){
if((point.y-19-25*j)<=0){
if(pDoc->chess.PushChess(i-1,j-1)==1){
if(pDoc->chess.BlackOrWhite==0)dc.BitBlt(19+25*(i-1),19+25*(j-1),wid,hei,&memDC1,0,0,SRCCOPY);
if(pDoc->chess.BlackOrWhite==1)dc.BitBlt(19+25*(i-1),19+25*(j-1),wid,hei,&memDC2,0,0,SRCCOPY);
if(pDoc->chess.WhoWin()==0){AfxMessageBox("黑赢");pDoc->EnableClick=false;break;}
if(pDoc->chess.WhoWin()==1){AfxMessageBox("白赢");pDoc->EnableClick=false;break;}
if(Computer){
pDoc->EnableClick=false;
p=pDoc->Thinking();
pDoc->chess.PushChess(p.x,p.y);
if(pDoc->chess.BlackOrWhite==0)dc.BitBlt(19+25*p.x,19+25*p.y,wid,hei,&memDC1,0,0,SRCCOPY);
if(pDoc->chess.BlackOrWhite==1)dc.BitBlt(19+25*p.x,19+25*p.y,wid,hei,&memDC2,0,0,SRCCOPY);
pDoc->EnableClick=true;
if(pDoc->chess.WhoWin()==0){AfxMessageBox("黑赢");pDoc->EnableClick=false;break;}
if(pDoc->chess.WhoWin()==1){AfxMessageBox("白赢");pDoc->EnableClick=false;break;}
}
break;
}
}
}
break;
}
}
CFormView::OnLButtonDown(nFlags, point);
}
}
void CChessView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//pDoc->chess.fileout();
CFormView::OnRButtonDown(nFlags, point);
}
void CChessView::draw()
{
CPaintDC dc(this); // device context for painting
pDoc=GetDocument();
CBitmap bm1,bm2,bm;
int wid,hei,i,j;
bm.LoadBitmap(BackGround);
CDC memDC1,memDC2,memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bm);
wid=600;
hei=600;
dc.BitBlt(0,0,wid,hei,&memDC,0,0,SRCCOPY);
bm1.LoadBitmap(Black);
bm2.LoadBitmap(White);
memDC2.CreateCompatibleDC(&dc);
memDC2.SelectObject(&bm2);
memDC1.CreateCompatibleDC(&dc);
memDC1.SelectObject(&bm1);
for(i=0;i<15;i++){
for(j=0;j<15;j++){
if(pDoc->chess.State[i][j]==1)dc.BitBlt(19+25*i,19+25*j,25,25,&memDC1,0,0,SRCCOPY);
if(pDoc->chess.State[i][j]==2)dc.BitBlt(19+25*i,19+25*j,25,25,&memDC2,0,0,SRCCOPY);
}
}
if(UserBW==0){
if(pDoc->chess.PushChess(7,7)==1){
dc.BitBlt(19+25*7,19+25*7,25,25,&memDC1,0,0,SRCCOPY);
}
}
// TODO: Add your message handler code here
// Do not call CFormView::OnPaint() for painting messages
}
void CChessView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
draw();
}
void CChessView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -