📄 beeview.cpp
字号:
// beeView.cpp : implementation of the CBeeView class
//
#include "stdafx.h"
#include "bee.h"
#include <mmsystem.h>
#include "beeDoc.h"
#include "beeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CBeeApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBeeView
IMPLEMENT_DYNCREATE(CBeeView, CView)
BEGIN_MESSAGE_MAP(CBeeView, CView)
//{{AFX_MSG_MAP(CBeeView)
ON_WM_KEYDOWN()
ON_WM_ERASEBKGND()
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBeeView construction/destruction
CBeeView::CBeeView()
{
// TODO: add construction code here
testx=0,testy=0;
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP2); ///加载位图
m_brushBackground.CreatePatternBrush(&bmp); ///创建位图画刷
}
CBeeView::~CBeeView()
{
}
BOOL CBeeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx=300;
cs.cy=330;
m_screen.maxx=cs.cx;
m_screen.maxy=cs.cy;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBeeView drawing
void CBeeView::OnDraw(CDC* pDC)
{
char temp[200];
POSITION i;
CBeeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(20, 0,"生命值");
pDC->TextOut(65,0,itoa(pDoc->m_gun.status,temp,10));
pDC->TextOut(100,0,itoa(pDoc->m_recordlist.m_highscore,temp,10));
pDC->TextOut(140,0,itoa(pDoc->m_recordlist.m_lowscore,temp,10));
pDC->TextOut(190,0,"第");
pDC->TextOut(204,0,itoa(pDoc->m_gatenum,temp,10));
pDC->TextOut(212,0,"关");
pDC->TextOut(240,0,"积分");
pDC->TextOut(270,0,itoa(pDoc->m_score,temp,10));
pDoc->m_gun.paint(pDC,&m_screen);
pDoc->m_beequeue.paint(pDC,&m_screen);
i=pDoc->m_bomblist.GetHeadPosition();
while(i!=NULL){
bomb tb=pDoc->m_bomblist.GetNext(i);
tb.paint(pDC,&m_screen);
}
i=pDoc->m_dropbomblist.GetHeadPosition();
while(i!=NULL){
dropbomb ttb=pDoc->m_dropbomblist.GetNext(i);
ttb.paint(pDC,&m_screen);
}
}
/////////////////////////////////////////////////////////////////////////////
// CBeeView diagnostics
#ifdef _DEBUG
void CBeeView::AssertValid() const
{
CView::AssertValid();
}
void CBeeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBeeDoc* CBeeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBeeDoc)));
return (CBeeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBeeView message handlers
void CBeeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_LEFT){
CBeeDoc* pDoc = GetDocument();
pDoc->m_gun.move(-1,&m_screen);
pDoc->UpdateAllViews(NULL);
}
if(nChar==VK_RIGHT){
CBeeDoc* pDoc = GetDocument();
pDoc->m_gun.move(1,&m_screen);
pDoc->UpdateAllViews(NULL);
}
if(nChar==VK_SPACE){
int x,y;
CBeeDoc* pDoc = GetDocument();
pDoc->m_gun.getpos(&x,&y);
bomb *newbomb=new bomb(x,y);
PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
pDoc->m_bomblist.AddTail(*newbomb);
pDoc->UpdateAllViews(NULL);
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
BOOL CBeeView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//CBrush brYellowHatch(HS_DIAGCROSS,RGB(192,192,0));
//CRect rcClient;
//GetClientRect(&rcClient);
//pDC->FillRect(rcClient,&brYellowHatch);
CRect rect;
GetClientRect(rect);///取得客户区域
pDC->FillRect(rect,&m_brushBackground); ///用背景画刷填充区域
//AfxMessageBox("i am here");
return TRUE;
//return CView::OnEraseBkgnd(pDC);
}
void CBeeView::OnCancelMode()
{
CView::OnCancelMode();
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -