📄 testmfcview.cpp
字号:
// TestMfcView.cpp : implementation of the CTestMfcView class
//
#include "stdafx.h"
#include "TestMfc.h"
#include "TestMfcView.h"
#include "Continue.h"
#include "Choose.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView
IMPLEMENT_DYNCREATE(CTestMfcView, CView)
BEGIN_MESSAGE_MAP(CTestMfcView, CView)
//{{AFX_MSG_MAP(CTestMfcView)
ON_WM_KEYUP()
ON_COMMAND(IDB_REPLAY, OnReplay)
ON_COMMAND(IDB_NEW, OnNew)
ON_COMMAND(IDB_CHOOSE, OnChoose)
ON_COMMAND(IDB_NEXT, OnNext)
ON_COMMAND(IDB_FRONT, OnFront)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView construction/destruction
CTestMfcView::CTestMfcView()
{
// TODO: add construction code here
}
CTestMfcView::~CTestMfcView()
{
cdc.DeleteDC();
bmp.DeleteObject();
}
BOOL CTestMfcView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView drawing
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView printing
BOOL CTestMfcView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestMfcView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestMfcView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView diagnostics
#ifdef _DEBUG
void CTestMfcView::AssertValid() const
{
CView::AssertValid();
}
void CTestMfcView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestMfcDoc* CTestMfcView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestMfcDoc)));
return (CTestMfcDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestMfcView message handlers
void CTestMfcView::DrawAll(CDC *pDC)
{
for(int i=0;i<CX;i++)
{
for(int j=0;j<CY;j++)
{
if(manager.map[j][i]==0)
{
//内背景
pDC->BitBlt(i*Width,j*Width,Width,Width,&cdc,0,100,SRCCOPY);
}
else if(manager.map[j][i]==1)
{
//墙
pDC->BitBlt(i*Width,j*Width,Width,Width,&cdc,50,50,SRCCOPY);
}
else if(manager.map[j][i]==2)
{
//箱子
pDC->BitBlt(i*Width,j*Width,Width,Width,&cdc,0,0,SRCCOPY);
}
else if(manager.map[j][i]==9)
{
//外背景
pDC->BitBlt(i*Width,j*Width,Width,Width,&cdc,100,50,SRCCOPY);
}
}
}
for(i=0;i<manager.num;i++)
{
if(manager.target[i].status==0)
{
//目标
pDC->BitBlt(manager.target[i].x*Width,manager.target[i].y*Width,Width,Width,&cdc,0,50,SRCCOPY);
}
else
{
//已完成的箱子
pDC->BitBlt(manager.target[i].x*Width,manager.target[i].y*Width,Width,Width,&cdc,50,0,SRCCOPY);
}
}
{
//人物
pDC->BitBlt(manager.man.x*Width,manager.man.y*Width,Width,Width,&cdc,50,100,MERGEPAINT);
pDC->BitBlt(manager.man.x*Width,manager.man.y*Width,Width,Width,&cdc,100,0,SRCAND);
}
{
//标题
CFont font;
CFont *oldFont;
font.CreateFont(25,20,0,0,FW_LIGHT,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"宋体");
CString subject;
oldFont=pDC->SelectObject(&font);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(243,223,215));
subject.Format("正在攻克第%d关",manager.index);
pDC->TextOut(200,10,subject);
pDC->SelectObject(oldFont);
}
}
/*
void CTestMfcView::DrawBox(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,0,0,SRCCOPY);
}
void CTestMfcView::DrawMan(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,50,100,MERGEPAINT);
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,100,0,SRCAND);
}
void CTestMfcView::DrawTarget(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,0,50,SRCCOPY);
}
void CTestMfcView::DrawWall(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,50,50,SRCCOPY);
}
void CTestMfcView::DrawBg(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,100,50,SRCCOPY);
}
void CTestMfcView::DrawInnerbg(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,0,100,SRCCOPY);
}
void CTestMfcView::DrawFin(int x,int y,CDC *pDC)
{
pDC->BitBlt(x*Width,y*Width,Width,Width,&cdc,50,0,SRCCOPY);
}
void CTestMfcView::DrawSubject(CDC *pDC)
{
CFont font;
CFont *oldFont;
font.CreateFont(25,20,0,0,FW_LIGHT,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"宋体");
CString subject;
oldFont=pDC->SelectObject(&font);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(243,223,215));
subject.Format("正在攻克第%d关",manager.index);
pDC->TextOut(200,10,subject);
pDC->SelectObject(oldFont);
}
*/
void CTestMfcView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
static int begined=0;
if(begined==0)
{
bmp.LoadBitmap(IDB_BMP);
cdc.CreateCompatibleDC(pDC);
cdc.SelectObject(bmp);
begined++;
}
if(manager.gamestate==1)
{
this->DrawAll(pDC);
}
}
void CTestMfcView::NextGame()
{
this->GameStart(manager.index+1);;
}
void CTestMfcView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(manager.DoMsg(nChar))
{
bool finish=false;
finish=manager.CheckState();
CDC *pDC=this->GetDC();
this->DrawAll(pDC);
this->ReleaseDC(pDC);
if(finish)
{
CContinue dialog;
if(dialog.DoModal()==IDOK)
{
if(dialog.next==0)
{
this->GameStart();
}
else
{
this->NextGame();
}
}
else
{
::exit(0);
}
}
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CTestMfcView::GameStart()
{
GameStart(manager.index);
}
void CTestMfcView::GameStart(int index)
{
if(index==43)
{
index=1;
}
if(index==0)
{
index=42;
}
manager.index=index;
manager.GameStart();
CDC *pDC=this->GetDC();
this->DrawAll(pDC);
this->ReleaseDC(pDC);
}
void CTestMfcView::OnReplay()
{
// TODO: Add your command handler code here
if(manager.gamestate==1)
{
this->GameStart();
}
}
void CTestMfcView::OnNew()
{
// TODO: Add your command handler code here
manager.index=1;
this->GameStart();
}
void CTestMfcView::OnChoose()
{
// TODO: Add your command handler code here
CChoose dialog;
if(dialog.DoModal()==IDOK)
{
if(dialog.m_index>=42)
{
manager.index=42;
}
else if(dialog.m_index>0)
{
manager.index=dialog.m_index;
}
else
{
manager.index=1;
}
this->GameStart();
}
}
void CTestMfcView::OnNext()
{
// TODO: Add your command handler code here
if(manager.gamestate==1)
{
this->NextGame();
}
}
void CTestMfcView::OnFront()
{
// TODO: Add your command handler code here
if(manager.gamestate==1)
{
this->GameStart(manager.index-1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -