russiaView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:6k
- // russiaView.cpp : implementation of the CRussiaView class
- //
- #include "stdAfx.h"
- #include "russia.h"
- #include "destinate.h"
- #include "russiaDoc.h"
- #include "russiaView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- const int TimerID=1;
- int dead=0;
- Block everblock;
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView
- IMPLEMENT_DYNCREATE(CRussiaView, CView)
- BEGIN_MESSAGE_MAP(CRussiaView, CView)
- //{{AFX_MSG_MAP(CRussiaView)
- ON_WM_KEYDOWN()
- ON_WM_TIMER()
- ON_COMMAND(ID_NEWGAME, OnNewgame)
- ON_COMMAND(ID_SAVEGAME, OnSavegame)
- ON_COMMAND(ID_HEROLIST, OnHerolist)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView construction/destruction
- CRussiaView::CRussiaView()
- {
- width=20;
- // TODO: add construction code here
- }
- CRussiaView::~CRussiaView()
- {
- }
- BOOL CRussiaView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView drawing
- void CRussiaView::OnDraw(CDC* pDC)
- {
- CRussiaDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- DrawBlocks(pDC);
- DrawEdge(pDC);
- //SetTimer(TimerID,4000,NULL);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView printing
- BOOL CRussiaView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CRussiaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CRussiaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView diagnostics
- #ifdef _DEBUG
- void CRussiaView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CRussiaView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CRussiaDoc* CRussiaView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRussiaDoc)));
- return (CRussiaDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CRussiaView message handlers
- void CRussiaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- switch(nChar)
- {
- case VK_DOWN:
- {
- everblock.ChangeFalse();
- everblock.Down();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- break;
- }
- case VK_LEFT:
- {
- everblock.ChangeFalse();
- everblock.Left();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- break;
- }
- case VK_RIGHT:
- {
- everblock.ChangeFalse();
- everblock.Right();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- break;
- }
- case VK_UP:
- {
- everblock.ChangeFalse();
- everblock.Shift();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- break;
- }
- default:
- break;
- }
- //if(!SetArray(everblock))
- /*
- if(!everblock.DownOK())
- {
- if(ExamArray()==false)
- {
- KillTimer(TimerID);
- MessageBox(" you are dead");
- }
- else
- {
- everblock.ChangeTrue();
- BreakBlock();
- DrawBlocks(&dc);
- everblock.Generate();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- }
- }
- */
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CRussiaView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- if(nIDEvent==TimerID)
- {
-
- if(!everblock.DownOK())
- {
- everblock.ChangeTrue();
- BreakBlock();
- DrawBlocks(&dc);
- if(ExamArray()==false||dead)
- {
- KillTimer(TimerID);
- dead=0;
- MessageBox(" you are dead");
- }
- else
- {
- everblock.Generate();
- if(!everblock.Possiable())
- dead=1;
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- }
- }
- else
- {
- everblock.ChangeFalse();
- everblock.Down();
- everblock.ChangeTrue();
- DrawBlocks(&dc);
- }
- }
- CView::OnTimer(nIDEvent);
- }
- void CRussiaView::WinHelp(DWORD dwData, UINT nCmd)
- {
- // TODO: Add your specialized code here and/or call the base class
- CView::WinHelp(dwData, nCmd);
- }
- void CRussiaView::DrawWhiteBlocks(CDC * pDC,CRect& rect)
- {
- CBrush backbrush,*oldbrush;
- backbrush.CreateSolidBrush(RGB(255,255,255));
- oldbrush=pDC->SelectObject(&backbrush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CRussiaView::DrawColorBlocks(CDC * pDC,CRect &rect)
- {
- CBrush brush,*oldbrush;
- brush.CreateSolidBrush(RGB(255,123,0));
- oldbrush=pDC->SelectObject(&brush);
- pDC->Rectangle(rect);
- pDC->SelectObject(oldbrush);
- }
- void CRussiaView::DrawEdge(CDC * pDC)
- {
- int i;
- CRect rect;
- for(i=0;i<ROW;i++)
- {
- rect.top=width*i;
- rect.bottom=width*(i+1);
- rect.left=0;
- rect.right=width;
- DrawColorBlocks(pDC,rect);
- }
- for(i=0;i<ROW;i++)
- {
- rect.top=width*i;
- rect.bottom=width*(i+1);
- rect.left=width*(COL-1);
- rect.right=width*COL;
- DrawColorBlocks(pDC,rect);
- }
- for(i=0;i<COL;i++)
- {
- rect.top=width*(ROW-1);
- rect.bottom=width*ROW;
- rect.left=i*width;
- rect.right=width*(i+1);
- DrawColorBlocks(pDC,rect);
- }
- }
- void CRussiaView::DrawBlocks(CDC * pDC)
- {
- CBrush brush;
- CRect rect;
- int i=0,j=0;
- for(i=0;i<ROW-1;i++)
- {
- rect.top=width*i;
- rect.bottom=width*(i+1);
- for(j=1;j<COL-1;j++)
- {
- rect.left=width*j;
- rect.right=width*(j+1);
- if(Array[i][j].takeup)
- {
- DrawColorBlocks(pDC,rect);
- }
- else
- {
- DrawWhiteBlocks(pDC,rect);
- }
- }
- }
- }
- void CRussiaView::OnNewgame()
- {
- // TODO: Add your command handler code here
- MessageBox(" are you ready");
- everblock.Generate();
- InitArray();
- SetTimer(TimerID,1000,NULL);
- }
- void CRussiaView::OnSavegame()
- {
- // TODO: Add your command handler code here
- MessageBox(" do you want to save game?");
- }
- void CRussiaView::OnHerolist()
- {
- MessageBox(" the hero is listed");
- // TODO: Add your command handler code here
- }