上传用户:zhengjing
上传日期:2022-08-08
资源大小:5708k
文件大小:6k
- // 俄罗斯方块View.cpp : implementation of the CMyView class
- //
- #include "stdafx.h"
- #include "俄罗斯方块.h"
- #include "俄罗斯方块Doc.h"
- #include "俄罗斯方块View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define IDT_TIMER 100
- /////////////////////////////////////////////////////////////////////////////
- // CMyView
- IMPLEMENT_DYNCREATE(CMyView, CView)
- BEGIN_MESSAGE_MAP(CMyView, CView)
- //{{AFX_MSG_MAP(CMyView)
- ON_COMMAND(ID_MENUITEM_STAR, OnMenuitemStar)
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_EASY, OnUpdateMenuitemEasy)
- ON_COMMAND(ID_MENUITEM_EASY, OnMenuitemEasy)
- ON_COMMAND(ID_MENUITEM_NORMAL, OnMenuitemNormal)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_NORMAL, OnUpdateMenuitemNormal)
- ON_COMMAND(ID_MENUITEM_HARD, OnMenuitemHard)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_HARD, OnUpdateMenuitemHard)
- ON_COMMAND(ID_MENUITEM_OVER, OnMenuitemOver)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_STAR, OnUpdateMenuitemStar)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CMyView construction/destruction
- CMyView::CMyView()
- {
- // TODO: add construction code here
- check[0]=1;
- check[1]=0;
- check[2]=0;
- valid=1;
- gray=1;
- }
- CMyView::~CMyView()
- {
- }
- BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView drawing
- void CMyView::OnDraw(CDC* pDC)
- {
- CMyDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- if(!ClaEluosi.startflags)
- {
- ClaEluosi.DrawCover(pDC);
- gray=1;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView printing
- BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView diagnostics
- #ifdef _DEBUG
- void CMyView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMyView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMyDoc* CMyView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
- return (CMyDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMyView message handlers
- void CMyView::OnMenuitemStar()
- {
- // TODO: Add your command handler code here
- gray=0;
- pauseflags=0;
- ClaEluosi.Start();
- CMyApp*pApp=(CMyApp*)AfxGetApp();
- SetTimer(IDT_TIMER,500-pApp->speed*200,NULL);
- }
- void CMyView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(ClaEluosi.startflags&&!pauseflags)
- {
- CDC*dc=GetDC();
- ClaEluosi.move(2);
- ClaEluosi.DrawScore(dc);
- ClaEluosi.DrawCover(dc);
- ReleaseDC(dc);
- return;
- }
- gray=1;
- CView::OnTimer(nIDEvent);
- }
- void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- if(!ClaEluosi.startflags)
- return;
- switch(nChar)
- {
- case VK_UP:
- {
- if(!pauseflags)
- ClaEluosi.move(1);
- break;
- }
- case VK_DOWN:
- {
- if(!pauseflags)
- ClaEluosi.move(2);
- break;
- }
- case VK_LEFT:
- {
- if(!pauseflags)
- ClaEluosi.move(3);
- break;
- }
- case VK_RIGHT:
- {
- if(!pauseflags)
- ClaEluosi.move(4);
- break;
- }
- case VK_SPACE:
- {
- pauseflags=!pauseflags;
- break;
- }
- }
- CDC*dc=GetDC();
- ClaEluosi.DrawScore(dc);
- ClaEluosi.DrawCover(dc);
- ReleaseDC(dc);
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CMyView::OnUpdateMenuitemEasy(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(check[0]);
- pCmdUI->Enable(gray);
- }
- void CMyView::OnMenuitemEasy()
- {
- // TODO: Add your command handler code here
- check[0]=!check[0];
- if(check[0])
- {
- check[2]=0;
- check[1]=0;
- }
- CMyApp*pApp=(CMyApp*)AfxGetApp();
- for(int i=0;i<3;i++)
- {
- if(check[i])
- {
- pApp->speed=i;
- valid=1;
- ClaEluosi.DrawCover(GetDC());
- return;
- }
- }
- valid=0;
- }
- void CMyView::OnMenuitemNormal()
- {
- // TODO: Add your command handler code here
- check[1]=!check[1];
- if(check[1])
- {
- check[2]=0;
- check[0]=0;
- }
- CMyApp*pApp=(CMyApp*)AfxGetApp();
- for(int i=0;i<3;i++)
- {
- if(check[i])
- {
- pApp->speed=i;
- valid=1;
- ClaEluosi.DrawCover(GetDC());
- return;
- }
- }
- valid=0;
- }
- void CMyView::OnUpdateMenuitemNormal(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(check[1]);
- pCmdUI->Enable(gray);
- }
- void CMyView::OnMenuitemHard()
- {
- // TODO: Add your command handler code here
- check[2]=!check[2];
- if(check[2])
- {
- check[0]=0;
- check[1]=0;
- }
- CMyApp*pApp=(CMyApp*)AfxGetApp();
- for(int i=0;i<3;i++)
- {
- if(check[i])
- {
- pApp->speed=i;
- valid=1;
- ClaEluosi.DrawCover(GetDC());
- return;
- }
- }
- valid=0;
- }
- void CMyView::OnUpdateMenuitemHard(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(check[2]);
- pCmdUI->Enable(gray);
- }
- void CMyView::OnMenuitemOver()
- {
- // TODO: Add your command handler code here
- gray=1;
- KillTimer(IDT_TIMER);
- ClaEluosi.end();
- ClaEluosi.DrawCover(GetDC());
- }
- void CMyView::OnUpdateMenuitemStar(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(valid);
- }