📄 russiaview.cpp
字号:
// RussiaView.cpp : implementation of the CRussiaView class
//
#include "stdafx.h"
#include "Russia.h"
#include "Square.h"
#include "RussiaDoc.h"
#include "RussiaView.h"
#include "Cell.h"
#include "SETdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
Square win(16,16);
/////////////////////////////////////////////////////////////////////////////
// CRussiaView
IMPLEMENT_DYNCREATE(CRussiaView, CView)
BEGIN_MESSAGE_MAP(CRussiaView, CView)
//{{AFX_MSG_MAP(CRussiaView)
ON_COMMAND(ID_START, OnStart)
ON_WM_TIMER()
ON_COMMAND(ID_PAUSE, OnPause)
ON_UPDATE_COMMAND_UI(ID_START, OnUpdateStart)
ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)
ON_COMMAND(ID_EXIT, OnExit)
ON_WM_DESTROY()
ON_WM_CHAR()
ON_COMMAND(ID_ONE, OnOne)
ON_UPDATE_COMMAND_UI(ID_ONE, OnUpdateOne)
ON_COMMAND(ID_TWO, OnTwo)
ON_UPDATE_COMMAND_UI(ID_TWO, OnUpdateTwo)
ON_COMMAND(ID_THREE, OnThree)
ON_UPDATE_COMMAND_UI(ID_THREE, OnUpdateThree)
ON_COMMAND(ID_FOUR, OnFour)
ON_UPDATE_COMMAND_UI(ID_FOUR, OnUpdateFour)
ON_COMMAND(ID_SETGRID, OnSetgrid)
ON_UPDATE_COMMAND_UI(ID_SETGRID, OnUpdateSetgrid)
ON_COMMAND(ID_DEFIEN, OnDefien)
//}}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()
{
// TODO: add construction code here
bCircle=TRUE;
nType=rand()%11;
nSpeed=9;
nKey=0;
cols=7;
rows=0;
con=0;
nScore=0;
nLevel=1;
nLife=15;
bGrid=TRUE;
bPause=FALSE;
}
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);
// TODO: add draw code for native data here
CRect rect;
GetClientRect(rect);
win.DrawPicture(pDC,1,1,600,400,FALSE,FALSE,RGB(0,0,0));
win.DrawPicture(pDC,10,10,420,384,bGrid,FALSE,RGB(0, 250, 140));
}
/////////////////////////////////////////////////////////////////////////////
// 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::OnStart()
{
// T;ODO: Add your command handler code here
CDC* pDC=GetDC();
bStart=FALSE;
bPause=TRUE;
win.DrawPicture(pDC,10,10,420,384,bGrid,FALSE,RGB(0, 250, 140));
ReleaseDC(pDC);
nLife=15;
this->DplayScore(win.nScore);
SetTimer(1,50,NULL);
// pD->TextOut(100,100,"ff");
// ReleaseDC(dc);
//win.pDC=GetDC();
///**/
}
void CRussiaView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//nType;
int OldRow,OldCol;
if(!bPause)//设置暂停按钮
return;
win.pDC=GetDC();
Cell celldata;
con++;
if(bCircle)//画右边出现的方块;
{
rows=0;
cols=7;
CeData.SetType(nType);
CeData.nControl=0;
win.EraseCell(win.pDC,3,18);
nType=rand()%12+1;
celldata.SetType(nType);
win.DrawData(win.pDC,celldata,3,18,RGB(255,0,0));
win.DrawData(win.pDC,CeData,rows,cols,RGB(0,0,255));
bCircle=FALSE;
}
OldRow=rows;
OldCol=cols;
for(int l=0;l<16;l++)
{
if (win.Grid[0][l]==1)
{
KillTimer(1);
MessageBox("你输了!");
this->init();
win.nScore=0;
bCircle=TRUE;
return ;
}
}
if(!win.CanDown(rows,cols,&CeData))
{
win.AddData(rows,cols,&CeData);
if(win.RemoveGrid())
for(int j=0;j<16;j++)
for(int k=0;k<16;k++)
if(win.Grid[j][k]==1)
win.DrawGrid(win.pDC,j,k,RGB(0,0,255),TRUE);
else
win.DrawGrid(win.pDC,j,k,RGB(0,250,140),FALSE);
nLife=win.LifeValue();
DplayScore( win.nScore);
this->SetLevel(win.nScore);
bCircle=TRUE;
return;
}
else
{
switch(nKey)
{
case VK_SPACE:
if(win.CanDown(rows,cols,&CeData))
{ rows++;
nKey=0;
}
if(win.CanDown(rows,cols,&CeData))
{
rows++;
nKey=0;
}
break;
//case key1:
case 'a':
case 'A':
if(win.CanLeft(rows,cols,&CeData))
{
cols--;
nKey=0;
}
break;
case 'F':
case 'f':
if(win.CanRight(rows,cols,&CeData))
{
cols++;
}
nKey=0;
break;
case 'd':
case 'D':
if(win.CanTrun(rows,cols,&CeData))
{
win.DrawData(win.pDC,CeData,OldRow,OldCol,RGB(0,250,140));
CeData.Turn(&CeData);
nKey=100;
}
nKey=0;
break;
}
}
if(con%nSpeed==0&&win.CanDown(rows,cols,&CeData))
rows++;
if(con>=5000)
con=0;
if(rows!=OldRow||nKey<=0||cols!=OldCol||nKey==100)
{
win.DrawData(win.pDC,CeData,OldRow,OldCol,RGB(0, 250, 140));
win.DrawData(win.pDC,CeData,rows,cols,RGB(0,0,255));
}
ReleaseDC(win.pDC);
CView::OnTimer(nIDEvent);
}
void CRussiaView::OnPause()
{
// TODO: Add your command handler code here
bPause=FALSE;
bStart=TRUE;
}
void CRussiaView::OnUpdateStart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(bStart);
}
void CRussiaView::OnUpdatePause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(bPause);
}
void CRussiaView::OnExit()
{
// TODO: Add your command handler code here
_exit(1);
// CView::OnDestroy();
}
void CRussiaView::OnDestroy()
{
CView::OnDestroy();
KillTimer(1);
//TODO: Add your message handler code here
}
void CRussiaView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
nKey=nChar;
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CRussiaView::init()
{
bStart=TRUE;
bPause=TRUE;
for(int m=0;m<win.nRows;m++)
for(int n=0;n<win.nCols;n++)
{
win.Grid[m][n]=0;
}
rows=0;
cols=7;
// win.nScore=0;
}
void CRussiaView::DplayScore(int Score)
{
CDC* pDC=GetDC();
CString str;
// CPen *pOldpen,pen;int
// pDC->FillSolidRect(11+18*win.nCellWidth,11+18*win.nCellWidth,5*win.nCellWidth+300,6*win.nCellWidth+100,RGB(255,255,0));
pDC->FillSolidRect(460,240,120,30,RGB((((nLife)*255/15)),0,0));
// if(nLife<0)
// MessageBox("F");
int nValue=(((nLife)*100)/15);
str.Format(" 生命力:%d%%",nValue);
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(460,250,str);
pDC->FillSolidRect(460,300,120,30,RGB(0,255,0));
str.Format("成绩:%d",Score);
// pDC->SetBkColor(255);
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(460,310,str);
pDC->FillSolidRect(460,360,120,30,RGB(0,0,255));
// pen.CreatePen(PS_SOLID,3,RGB(255,255,255));
str.Format("水平:%d",nLevel);
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(460,370,str);
// pDC->SelectObject(pOldpen);
ReleaseDC(pDC);
}
void CRussiaView::OnOne()
{
// TODO: Add your command handler code here
nSpeed=9;
nLevel=1;
}
void CRussiaView::OnUpdateOne(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(nSpeed==9);
}
void CRussiaView::OnTwo()
{
// TODO: Add your command handler code here
nSpeed=7;
nLevel=2;
}
void CRussiaView::OnUpdateTwo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(nSpeed==7);
}
void CRussiaView::OnThree()
{
// TODO: Add your command handler code here
nSpeed=5;
nLevel=3;
}
void CRussiaView::OnUpdateThree(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(nSpeed==5);
}
void CRussiaView::OnFour()
{
// TODO: Add your command handler code here
nSpeed=3;
nLevel=4;
}
void CRussiaView::OnUpdateFour(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(nSpeed==3);
}
void CRussiaView::OnSetgrid()
{
// TODO: Add your command handler code here
bGrid=!bGrid;
win.pDC=GetDC();
win.DrawPicture(win.pDC,10,10,420,384,bGrid,FALSE,RGB(0, 250, 140));
ReleaseDC(win.pDC);
}
void CRussiaView::OnUpdateSetgrid(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler 你进\n第2关!code here
pCmdUI->SetRadio(bGrid);
}
void CRussiaView::SetLevel(int Score)
{
CDC* pDC=GetDC();
static BOOL b1,b2,b3,b4;
CBrush brush,*pOldBrush;
brush.CreateSolidBrush(RGB(255,255,255));
pOldBrush=pDC->SelectObject(&brush);
if(Score>=2000&&Score<2000)
{ if(!b1)
{
pDC->Ellipse(50,50,150,100);
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(50,70,"恭喜进入2关");
nSpeed=7;
KillTimer(1);
this->init();
b1=TRUE;
}
}
else if(Score>=2000&&Score<3000)
{
if(!b2)
{
pDC->Ellipse(200,200,280,280);
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(220,220,"恭喜你进\n第3关!");
nSpeed=5;
KillTimer(1);
this->init();
b2=TRUE;
}
}
else if(Score>=3000)
{
if(!b3)
{
pDC->Ellipse(200,200,280,280);
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(220,220,"恭喜你进\n第4关!");
nSpeed=5;
KillTimer(1);
this->init();
b3=TRUE;
}
}
pDC->SelectObject(pOldBrush);
ReleaseDC(pDC);
}
void CRussiaView::OnDefien()
{
// TODO: Add your command handler code here
//char t;
// SETdlg dlg;
// if(dlg.DoModal()==IDOK)
// {
// key1=dlg.m_1;
// key2=dlg.m_2;
// key3=dlg.m_3;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -