📄 ourblokeview.cpp
字号:
// OurBlokeView.cpp : COurBlokeView 类的实现
//
#include "stdafx.h"
#include "OurBloke.h"
#include "OurBlokeDoc.h"
#include "OurBlokeView.h"
#include "MainFrm.h"
#include "SubMenu.h"
#define IDB_BITMAP_JIONG 136
#define WM_CHANGEBLOKEVIEW (WM_USER + 2)
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// COurBlokeView
IMPLEMENT_DYNCREATE(COurBlokeView, CView)
BEGIN_MESSAGE_MAP(COurBlokeView, CView)
// ON_WM_TIMER()
ON_WM_ERASEBKGND()
ON_WM_KEYDOWN()
ON_WM_TIMER()
ON_WM_SYSKEYDOWN()
END_MESSAGE_MAP()
// COurBlokeView 构造/析构
COurBlokeView::COurBlokeView()
: _CursorX(SCREENX_L)
, counter(0)
, bDo(false)
{
// TODO: 在此处添加构造代码
}
COurBlokeView::~COurBlokeView()
{
}
BOOL COurBlokeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// COurBlokeView 绘制
void COurBlokeView::OnDraw(CDC* pDC)
{
COurBlokeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: 在此处为本机数据添加绘制代码
//apply the resource
CRect rcclient;
GetClientRect(rcclient);
CBitmap bitmap;
CDC MemDC;
HGDIOBJ hOldObject;
MemDC.CreateCompatibleDC(pDC);
bitmap.CreateCompatibleBitmap(pDC,rcclient.right,rcclient.bottom);
hOldObject = MemDC.SelectObject(&bitmap);
//fill the rectangle into white brush
// MemDC.FillRect(&rcclient,&CBrush(RGB(255,255,255)));
//FillRect(MemDC,&rcclient,(HBRUSH) GetStockObject(WHITE_BRUSH));
CBitmap bgbmp;
bgbmp.LoadBitmap(IDC_BITMAP_BKGD);
CDC mdc;
HGDIOBJ hOldObject2;
mdc.CreateCompatibleDC(pDC);
hOldObject2 = mdc.SelectObject(&bgbmp);
//_Blockbmp.CreateCompatibleBitmap(pDC,15,15);
//Draw the screen
MemDC.BitBlt( 0,0,rcclient.right,rcclient.bottom,&mdc,0,0,SRCCOPY);
//relieve the resource of the objects which I have gotten.
SelectObject(mdc,hOldObject2);
DeleteObject(hOldObject2);
DeleteObject(bgbmp);
DeleteDC (mdc) ;
//for the frame of the map
/* MemDC.MoveTo(8,100);
MemDC.LineTo(8,200);
MemDC.LineTo(168,200);
MemDC.LineTo(168,100);
MemDC.LineTo(8,100);*/
//for the text of the score
CRect a(0,0,100,20);
SetBkMode(MemDC,TRANSPARENT);
MemDC.SetTextColor(RGB(0,0,255));
//FillRect(MemDC,&a,(HBRUSH)GetStockObject(BLACK_BRUSH));
CString str ;
str.Format(_T("Score: %d"),_Screen.score);
//string str = _T("Score: ");
//str = _T("Score: ")+ str;
MemDC.DrawText(str,&a,DT_LEFT);
CBrush brush(RGB(128,128,255));
int b = SCREENX_L +(SCREENX_R - SCREENX_L)/_Screen.MaxNum * _Screen.score;
FillRect(MemDC,CRect(SCREENX_L,195,b,205),brush);
brush.DeleteObject();
DeleteObject(a);
bgbmp.LoadBitmap(IDB_BITMAP_JIONG);
mdc.CreateCompatibleDC(pDC);
hOldObject2 = mdc.SelectObject(&bgbmp);
//_Blockbmp.CreateCompatibleBitmap(pDC,15,15);
//Draw the screen
MemDC.BitBlt( b-5,190,b+16,210,&mdc,0,0,SRCCOPY);
//relieve the resource of the objects which I have gotten.
SelectObject(mdc,hOldObject2);
DeleteObject(hOldObject2);
DeleteObject(bgbmp);
DeleteDC (mdc) ;
//the cursor
MemDC.MoveTo(_CursorX,SCREENY_T);
MemDC.LineTo(_CursorX,SCREENY_B);
_Screen.OnDraw(&MemDC,this);
//Draw the screen
pDC->BitBlt(0,0, rcclient.right , rcclient.bottom ,&MemDC, 0, 0, SRCCOPY);
//relieve the resource of the objects which I have gotten.
SelectObject(MemDC,hOldObject);
DeleteObject(bitmap);
DeleteObject(hOldObject);
MemDC.DeleteDC() ;
DeleteObject(rcclient);
ReleaseDC(pDC);
// TODO: 在此处为本机数据添加绘制代码
}
// COurBlokeView 诊断
#ifdef _DEBUG
void COurBlokeView::AssertValid() const
{
CView::AssertValid();
}
COurBlokeDoc* COurBlokeView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COurBlokeDoc)));
return (COurBlokeDoc*)m_pDocument;
}
#endif //_DEBUG
// COurBlokeView 消息处理程序
BOOL COurBlokeView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
if (!CView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
{
return false;
}
SetTimer(1,50,NULL);
return true;
}
//void COurBlokeView::OnTimer(UINT_PTR nIDEvent)
//{
// // TODO: 在此添加消息处理程序代码和/或调用默认值
//
//
//
//
// CView::OnTimer(nIDEvent);
//}
BOOL COurBlokeView::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return true;//CView::OnEraseBkgnd(pDC);
}
void COurBlokeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(VK_LEFT==nChar)//还要加上判断是否重叠
{
//MessageBox(_T("key: <-"));%
_Screen.Leftwards();
//??this->Invalidate(true);
}
if(VK_RIGHT==nChar)//还要加上判断是否重叠
{
//MessageBox(_T("key: ->"));
_Screen.Rightwards();
//??this->Invalidate(true);
}
if(VK_UP==nChar)//还要加上判断是否重叠
{
//MessageBox(_T("key: 1"));
_Screen.TurnAround();
//??this->Invalidate(true);
}
if(VK_DOWN==nChar)//还要加上判断是否重叠
{
//MessageBox(_T("key: !"));
//EnterCriticalSection(&lpCriticalSection);
_Screen.Downwards();
//LeaveCriticalSection(&lpCriticalSection);
//??this->Invalidate(true);
}
if (13==nChar)
{
//MessageBox(_T("key: !"));
bDo =true;
CSubMenu * psub = new CSubMenu;
psub->DoModal();
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void COurBlokeView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
COurBlokeView * pView = this;
if (bDo == true)
{
return;
}
counter ++;
if ((counter%10)== 0)
{
pView->_Screen.IncBottomY();
//EnterCriticalSection(&lpCriticalSection);
if (pView->_Screen.JudgeBottomY())
{
pView->_Screen.MappingQueue();
pView->_Screen.RestartQueue();
//this->Invalidate(true);
}
else
{
if (pView->_Screen.HasTouch())
{
if (_Screen.HasFailed())
{
CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
pMain->SendMessage(WM_CHANGEBLOKEVIEW,0,0);
}
else
{
pView->_Screen.SetTouch();
pView->_Screen.RestartQueue();
}
//EnterCriticalSection(&lpCriticalSection);
//LeaveCriticalSection(&lpCriticalSection);
}
/*else
{
_Screen.IncBottomY();
}*/
//_Screen.HasTouch(BottomX,BottomY);
}
//LeaveCriticalSection(&lpCriticalSection);
}
if (counter == 4000)
{
counter = 0;
}
if (pView->_CursorX == (SCREENX_R+2) )
{
pView->_CursorX = SCREENX_L;
}
int tmpL =(pView->_CursorX-SCREENX_L)%CELLSIZEX;
if (tmpL == 0)
{
_Screen.Reduceblock(_CursorX);
}
pView->_CursorX += 2;
this->Invalidate(true);
CView::OnTimer(nIDEvent);
}
void COurBlokeView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnSysKeyDown(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -