📄 frameview.cpp
字号:
// frameView.cpp : implementation of the CFrameView class//#include "stdafx.h"#include "fiver.h"#include "frameDoc.h"#include "frameView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CFrameViewIMPLEMENT_DYNCREATE(CFrameView, CView)BEGIN_MESSAGE_MAP(CFrameView, CView) //{{AFX_MSG_MAP(CFrameView) ON_WM_PAINT() ON_COMMAND(ID_NEWGAME, OnNewgame) ON_COMMAND(ID_BACK, OnBack) ON_COMMAND(ID_NEXT, OnNext) ON_COMMAND(ID_BACKRECORD, OnBackrecord) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CFrameView construction/destructionCFrameView::CFrameView(){ // TODO: add construction code here CBitmap b,c,d,e; pAI = NULL; b.LoadBitmap(IDB_QIPAN); qipan.CreateCompatibleDC(NULL); qipan.SelectObject(&b); b.DeleteObject(); c.LoadBitmap(IDB_BLACK); qzh.CreateCompatibleDC(NULL); qzh.SelectObject(&c); c.DeleteObject(); d.LoadBitmap(IDB_WHITE); qzb.CreateCompatibleDC(NULL); qzb.SelectObject(&d); d.DeleteObject(); e.LoadBitmap(IDB_MASK); mask.CreateCompatibleDC(NULL); mask.SelectObject(&e); d.DeleteObject();}CFrameView::~CFrameView(){}BOOL CFrameView::PreCreateWindow(CREATESTRUCT& cs){ // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs);}/////////////////////////////////////////////////////////////////////////////// CFrameView drawingvoid CFrameView::OnDraw(CDC* pDC){ CFrameDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here}/////////////////////////////////////////////////////////////////////////////// CFrameView diagnostics#ifdef _DEBUGvoid CFrameView::AssertValid() const{ CView::AssertValid();}void CFrameView::Dump(CDumpContext& dc) const{ CView::Dump(dc);}CFrameDoc* CFrameView::GetDocument() // non-debug version is inline{ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFrameDoc))); return (CFrameDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CFrameView message handlersvoid CFrameView::DrawChess(int nx,int ny,bool style){ CDC *dc = GetDC(); if (nx>14||ny>14) return; if (style==false ) { dc->BitBlt(nx*29+7,ny*29+7,28,28,&mask,0,0,MERGEPAINT); dc->BitBlt(nx*29+7,ny*29+7,28,28,&qzb,0,0,SRCAND); } else { dc->BitBlt(nx*29+7,ny*29+7,28,28,&mask,0,0,MERGEPAINT); dc->BitBlt(nx*29+7,ny*29+7,28,28,&qzh,0,0,SRCAND); }}void CFrameView::Draw(){ CDC *dc = GetDC(); dc->BitBlt(0, 0,466,466,&qipan,0,0,SRCCOPY); if (NULL!=pAI) for(int i1=0 ; i1<15;i1++) { for(int i2=0 ; i2<15;i2++) { if (pAI->map[i1][i2]==1){ DrawChess(i1,i2,false); } else if (pAI->map[i1][i2]==2){ DrawChess(i1,i2,true); } } }}void CFrameView::OnPaint() { CPaintDC dc(this); // device context for painting Draw(); // Do not call CView::OnPaint() for painting messages}void CFrameView::OnNewgame() { CDC* dc = GetDC(); dc->BitBlt(0, 0,446,446,&qipan,0,0,SRCCOPY); pAI->NewGame(); style = TRUE; GetDocument()->OnNewDocument(); }void CFrameView::OnBack() { ChessPositionStruct last; CDC *pDC = GetDC(); if (!pAI->back(last)) return; pDC->BitBlt(last.nx*29+7,last.ny*29+7,28,28,&qipan,last.nx*29+7,last.ny*29+7,SRCCOPY); }void CFrameView::OnNext() { CString BlackWin("black win"); CString WhiteWin("white win"); ChessPositionStruct ChessPosition; CDocument *pDoc = GetDocument(); if (!pAI->GetRecord(ChessPosition)) return; nx = ChessPosition.nx; ny = ChessPosition.ny; style = ChessPosition.style; DrawChess(nx,ny,style); if (pAI->IsWinner(style,nx,ny)) { if (style) MessageBox(BlackWin); else MessageBox(WhiteWin); } }void CFrameView::OnBackrecord() { ChessPositionStruct last; CDC *pDC = GetDC(); if (!pAI->back(last)) return; style=!style; pDC->BitBlt(last.nx*29+7,last.ny*29+7,28,28,&qipan,last.nx*29+7,last.ny*29+7,SRCCOPY); }void CFrameView::OnLButtonDown(UINT nFlags, CPoint point) { CString BlackWin("black win"); CString WhiteWin("white win"); nx = (point.x-7)/29; ny = (point.y-7)/29; if (nx > 14 || ny>14) return; if (!pAI->PutChess(nx,ny)) return; style = pAI->style; DrawChess(nx,ny,style); if (pAI->IsWinner(style,nx,ny)) { if (style) MessageBox(BlackWin); else MessageBox(WhiteWin); } CView::OnLButtonDown(nFlags, point);}void CFrameView::OnInitialUpdate() { CView::OnInitialUpdate(); pAI = GetDocument()->GetAI(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -