📄 win马踏棋盘view.cpp
字号:
// WIN马踏棋盘View.cpp : implementation of the CWINView class
//
#include "stdafx.h"
#include "WIN马踏棋盘.h"
#include "WIN马踏棋盘Doc.h"
#include "WIN马踏棋盘View.h"
#include "MainFrm.h"
//计时函数
#include "time.h"
#include "OninitDataDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWINView
IMPLEMENT_DYNCREATE(CWINView, CView)
BEGIN_MESSAGE_MAP(CWINView, CView)
//{{AFX_MSG_MAP(CWINView)
ON_COMMAND(ID_MENURUN, OnMenurun)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWINView construction/destruction
CWINView::CWINView()
{
// TODO: add construction code here
}
CWINView::~CWINView()
{
}
BOOL CWINView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWINView drawing
void CWINView::OnDraw(CDC* pDC)
{
CWINDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
extern int m_ChessBoardSize_x;//棋盘的形状
extern int m_ChessBoardSize_y;
//获得马的位置
extern int horse_X;
extern int horse_Y;
//画出棋盘
for(int k=1;k<=m_ChessBoardSize_y;k++)
{
pDC->MoveTo(60,k*45);
pDC->LineTo(60*m_ChessBoardSize_x,k*45);
}
for(int i=1;i<=m_ChessBoardSize_x;i++)
{
pDC->MoveTo(i*60, 45);
pDC->LineTo(i*60,45*m_ChessBoardSize_y);
}
CDC memdc;
CBitmap mybitmap;
mybitmap.LoadBitmap(IDB_horse);
BITMAP bm;
memdc.CreateCompatibleDC(NULL);
mybitmap.GetObject(sizeof(BITMAP),&bm);
memdc.SelectObject(&mybitmap);
if(f<=m_ChessBoardSize_x*m_ChessBoardSize_y)
{
pDC->BitBlt(horse_X*60-13,horse_Y*45-13,bm.bmWidth,bm.bmHeight,&memdc,0,0,SRCCOPY);
pDC->TextOut(60,380,time);
CString str;
str.Format("(%d,%d)",horse_X,horse_Y);
pDC->TextOut(60+50*(f/m_ChessBoardSize_x),400+20*(f%m_ChessBoardSize_y),str);
}
}
/////////////////////////////////////////////////////////////////////////////
// CWINView diagnostics
#ifdef _DEBUG
void CWINView::AssertValid() const
{
CView::AssertValid();
}
void CWINView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWINDoc* CWINView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWINDoc)));
return (CWINDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWINView message handlers
void CWINView::OnMenurun()
{
// TODO: Add your command handler code here
//运行主要程序
CHorsePosition m_horse;
double begin=(double)clock();
extern int horse_X;
extern int horse_Y;
m_horse.m_CurrptrPosition.SetPosition(horse_X,horse_Y);
m_horse.SetAbutPosition();
ma.Oninit();
ma.MainFuntion(m_horse);
f=0;
double end=(double)clock();
time.Format("时间花费%.0f毫秒",end-begin);
SetTimer(0,1000,NULL);
}
void CWINView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
extern int horse_X;
extern int horse_Y;
extern int m_ChessBoardSize_x;//棋盘的位置
extern int m_ChessBoardSize_y;
if(f<=m_ChessBoardSize_y*m_ChessBoardSize_x)
{
f++;
horse_X=ma.m_RecordPosition[f].m_CurrptrPosition.m_x;
horse_Y=ma.m_RecordPosition[f].m_CurrptrPosition.m_y;
CDC *pDC=GetDC();
OnDraw(pDC);
}
CView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -