⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4_1view.cpp

📁 VC++游戏编程
💻 CPP
字号:
// 4_1View.cpp : implementation of the CMy4_1View class
//

#include "stdafx.h"
#include "4_1.h"

#include "4_1Doc.h"
#include "4_1View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View

IMPLEMENT_DYNCREATE(CMy4_1View, CView)

BEGIN_MESSAGE_MAP(CMy4_1View, CView)
	//{{AFX_MSG_MAP(CMy4_1View)
	ON_COMMAND(ID_MENU_START, OnMenuStart)
	ON_WM_TIMER()
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_MENU_PAUSE, OnMenuPause)
	ON_UPDATE_COMMAND_UI(ID_MENU_PAUSE, OnUpdateMenuPause)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View construction/destruction

CMy4_1View::CMy4_1View()
{
	// TODO: add construction code here
	fenmian.LoadBitmap(IDB_BITMAP1);
	start=false;
	m_bPause=false;
}

CMy4_1View::~CMy4_1View()
{
}

BOOL CMy4_1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View drawing

void CMy4_1View::OnDraw(CDC* pDC)
{
	CMy4_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CDC Dc;
	if(Dc.CreateCompatibleDC(pDC)==FALSE)
		AfxMessageBox("Can't create DC");
	//没有开始,显示封面
	if( !start)
	{
		Dc.SelectObject(fenmian);
		pDC->BitBlt(0,0,500,550,&Dc,0,0,SRCCOPY);
	}
	//显示背景
	else
		russia.DrawJiemian(pDC);

}

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View printing

BOOL CMy4_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMy4_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMy4_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View diagnostics

#ifdef _DEBUG
void CMy4_1View::AssertValid() const
{
	CView::AssertValid();
}

void CMy4_1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMy4_1Doc* CMy4_1View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy4_1Doc)));
	return (CMy4_1Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMy4_1View message handlers

void CMy4_1View::OnMenuStart() 
{
	// TODO: Add your command handler code here
    start=true;
    russia.Start();
	SetTimer(1,50*(11-russia.m_Speed ),NULL);    
}


void CMy4_1View::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//下移
	russia.Move(3);
	//重画
	russia.DrawJiemian(GetDC());
	CView::OnTimer(nIDEvent);
}

void CMy4_1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
    //没有开始
	if(!start)
		return;
    //暂停
   	if(m_bPause==TRUE)
		return;

	switch(nChar)
	{
	case VK_LEFT:
		russia.Move(1);
		break;
	case VK_RIGHT:
		russia.Move(2);
		break;		
	case VK_UP:
		russia.Move(4);
		break;
	case VK_DOWN:
		russia.Move(3);
		break;
	}
	//重画
	CDC* pDC=GetDC();
	russia.DrawJiemian(pDC);
	ReleaseDC(pDC);

	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}





void CMy4_1View::OnMenuPause() 
{
	// TODO: Add your command handler code here
	m_bPause=!m_bPause;
	if(m_bPause)
		KillTimer(1);
	else
		SetTimer(1,50*(11-russia.m_Speed ),NULL);   
}

void CMy4_1View::OnUpdateMenuPause(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bPause);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -