📄 0206220330view.cpp
字号:
// 0206220330View.cpp : implementation of the CMy0206220330View class
//
#include "stdafx.h"
#include "0206220330.h"
#include "0206220330Doc.h"
#include "0206220330View.h"
#include "SET.H"
#include "INFO.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int count,count2,count3;
int shengji=5;
int oldindex,index;
int pause;
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View
IMPLEMENT_DYNCREATE(CMy0206220330View, CView)
BEGIN_MESSAGE_MAP(CMy0206220330View, CView)
//{{AFX_MSG_MAP(CMy0206220330View)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_KEYDOWN()
ON_WM_CREATE()
ON_COMMAND(IDM_START, OnStart)
ON_COMMAND(ID_STOP, OnStop)
ON_COMMAND(IDM_PAUSE, OnPause)
ON_COMMAND(ID_SET, OnSet)
ON_WM_KEYUP()
ON_COMMAND(ID_INSTRUCTION, OnInstruction)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View construction/destruction
CMy0206220330View::CMy0206220330View()
{
// TODO: add construction code here
isstart=0;
count=0;
count2=0;
count3=0;
index=2;
time=500;
facecolor=RGB(230,251,36);
flag2=0;
flag=0;
k=0;
K=0;
R=0;
H=0;
timer=0;
name="姓名:无名氏";
for(int i=0;i<20;i++)
{
for(int j=0;j<10;j++)
{
cor[i][j]=0;
}
}
// for( i=0;i<4;i++){
// boxcolor[box[i].x][box[i].y]=RGB(255,255,255);
// }
// facecolor=RGB(230,251,36);
}
CMy0206220330View::~CMy0206220330View()
{
}
BOOL CMy0206220330View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// SetTimer(1,500,NULL);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View drawing
void CMy0206220330View::OnDraw(CDC* pDC)
{
CMy0206220330Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/* COLORREF clrTopLeft = RGB(68, 71, 140);
COLORREF clrBottomRight = RGB(70, 166,152);
COLORREF clrTopLeft2 = ::GetSysColor(COLOR_BTNHILIGHT);
COLORREF clrBottomRight2 =::GetSysColor(COLOR_BTNSHADOW);
CRect rect;
CClientDC dc(this);
register const UINT wide =20;
register const UINT hight =20;
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);
dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrTopLeft2);
dc.FillSolidRect(120,20,20,20,RGB(0,255,0));
}
}
MessageBox("hh",NULL,MB_OK);*/
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View printing
BOOL CMy0206220330View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy0206220330View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy0206220330View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View diagnostics
#ifdef _DEBUG
void CMy0206220330View::AssertValid() const
{
CView::AssertValid();
}
void CMy0206220330View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy0206220330Doc* CMy0206220330View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy0206220330Doc)));
return (CMy0206220330Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy0206220330View message handlers
void CMy0206220330View::OnPaint()
{
CPaintDC pdc(this); // device context for painting
// TODO: Add your message handler code here
/* COLORREF clrTopLeft = RGB(68, 71, 140);
COLORREF clrBottomRight = RGB(70, 166,152);
COLORREF clrTopLeft2 = ::GetSysColor(COLOR_BTNHILIGHT);
// COLORREF clrBottomRight2 =::GetSysColor(COLOR_BTNSHADOW);
// CRect rect;
CClientDC dc(this);
register const UINT wide =20;
register const UINT hight =20;
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrTopLeft2);// clrBottomRight
dc.FillSolidRect(0,0,120,800,RGB(0,0,100));
dc.FillSolidRect(320,0,1024,800,RGB(0,0,100));
dc.FillSolidRect(0,400,1024,800,RGB(0,0,100));
}
}
// for(int i=0;i<20;i++)
// {
// dc.FillSolidRect(100+20,i*20,20,20,RGB(0,255,0));
// for(float b=0;b<10000;b=b+0.001);
// dc.FillSolidRect(100+20,i*20,20,20,RGB(255,255,255));
// }
// SetTimer(1,1000,NULL);*/
/////////////////////////////////////////////
CString title;
title="俄罗斯方块 小亮编写 0206220330";
// AfxGetApp()->m_pMainWnd->GetWindowText(title);
AfxGetApp()->m_pMainWnd->SetWindowText(title);
//////////////////////////////////////////////////
COLORREF clrTopLeft = RGB(68, 71, 140);
COLORREF clrBottomRight = RGB(70, 166,152);
COLORREF clrTopLeft2 =RGB(255,255,255);// ::GetSysColor(COLOR_BTNHILIGHT);
// COLORREF clrBottomRight2 =::GetSysColor(COLOR_BTNSHADOW);
// CRect rect;
CClientDC dc(this);
register const UINT wide =20;
register const UINT hight =20;
dc.FillSolidRect(0,0,120,800,facecolor);
dc.FillSolidRect(320,0,1024,800,facecolor);
dc.FillSolidRect(0,400,1024,800,facecolor);
// paint the board itself
if(flag)
{
for(int a=0;a<4;a++)
{
cor[box[a].x][box[a].y]=1;
}
/* for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
if(cor[x][j]==1)
{
// dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);
// dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrBottomRight);
}
}
}*/
}
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
// dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);
dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrTopLeft2);
}
}
for( x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
if((cor[x][j]==1)||(cor[x][j]==2))
{
dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);
dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrBottomRight);
}
}
}
// Do not call CView::OnPaint() for painting messages
}
void CMy0206220330View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// MessageBox("hello",NULL,MB_OK);
if(isstart==0)
return;
if(K)
{
if(Isbottom())
{
flag=1;
clean();
// R=R+2;
for(int a=0;a<4;a++)
{
box[a].x++;
}
MyDraw();
}
else if(K)
{
Isover();
showbox();
flag=1;
}
}
CView::OnTimer(nIDEvent);
}
void CMy0206220330View::MyDraw()
{
CDC *dc=GetDC();
COLORREF clrTopLeft = RGB(68, 71, 140);
COLORREF clrBottomRight = RGB(70, 166,152);
COLORREF clrTopLeft2 = RGB(255,255,255);//::GetSysColor(COLOR_BTNHILIGHT);
// COLORREF clrBottomRight2 = ::GetSysColor(COLOR_BTNSHADOW);
register const UINT wide =20;
register const UINT hight = 20;
///////////////////////////////////////
CString s;
dc->TextOut(1,20,name);
s.Format("第 %d 关 ", (11-time/50));
dc->TextOut(1,40,s);
s.Format("得 分:%d",count2);
dc->TextOut(1,60,s);
s.Format("升级积分:%d",count3);
dc->TextOut(1,80,s);
//////////////////////////////////////
////////////////////////////////////
// paint the board itself
for(int a=0;a<4;a++)
{
//用白色消去前一个方块;
dc->FillSolidRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2);
dc->Draw3dRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft, clrTopLeft2); //下落时的重绘
}
if(flag)
{
for(int a=0;a<4;a++)
{
cor[box[a].x][box[a].y]=1;
}
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
if(cor[x][j]==1)
{
dc->FillSolidRect(100+20+j*20,x*20,wide,hight,tempclr);
dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrBottomRight );//tempclrclrTopLeft2
//下落过程的绘画
}
}
}
}
if(flag2)
{
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
dc->FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);
dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrTopLeft2);
//////////网格重绘
}
}
for( x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
if((cor[x][j]==1)||(cor[x][j]==2))
{
dc->FillSolidRect(100+20+j*20,x*20,wide,hight,boxcolor[x][j]);
dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft,clrBottomRight );//boxcolor[x][j]
}
}
}
flag2=0;
}
//////////////////////////////////////////////////////
// for( a=0;a<4;a++)
// {
// dc->FillSolidRect(dd[a].y,dd[a].x,wide,hight,tempclr);
// dc->Draw3dRect(20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft, clrTopLeft2); //下落时的重绘
// }
// MessageBox("hh",NULL,MB_OK);
}
void CMy0206220330View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
// MessageBox("dddd",NULL,MB_OK);
if(!isstart)
return;
// if(!Y)
{
K=0;
switch(nChar)
{
case VK_LEFT:
case VK_NUMPAD4:
if(!(Isout(1)==2))
{
flag=1;
clean();
// H--;
for(int a=0;a<4;a++)
{
box[a].y--;
}
}
break;
case VK_RIGHT:
case VK_NUMPAD6:
if(!(Isout(2)==1))
{
flag=1;
clean();
// H++;
for(int a=0;a<4;a++)
{
box[a].y++;
}
}
break;
case VK_DOWN:
case VK_NUMPAD2:
KillTimer(1);
timer=2;
SetTimer(2,20,NULL);
// break;
clean();
// dop();
Isover();
MyDraw();
// makebox();
break;
case VK_UP:
case VK_NUMPAD8:
case VK_NUMPAD5:
clean();
k++;
round(k);
break;
}
K=1;
}
// OnPaint();
MyDraw();
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
int CMy0206220330View::Isout(int out)
{
if(out==2) //右界
{
for(int a=0;a<4;a++)
{
if((box[a].y>=9)||(cor[box[a].x][box[a].y+1]==2))
{
return 1;
}
}
}
if(out==1) //左界
{
for(int a=0;a<4;a++)
{
if((box[a].y<=0)||(cor[box[a].x][box[a].y-1]==2))
{
return 2;
}
}
}
return 3;
}
void CMy0206220330View::clean()
{
for(int a=0;a<4;a++)
{
cor[box[a].x][box[a].y]=0;
dd[a].x=box[a].x;
dd[a].y=box[a].y;
}
}
int CMy0206220330View::dop()
{
/* for(int u=0;u<20;u++)
{
for(int a=0;a<4;a++)
{
if(cor[box[a].x+1][box[a].y]==2)
{
for(int c=0;c<4;c++)
{
cor[box[c].x][box[c].y]=2;
boxcolor[box[c].x][box[c].y]=tempclr;
flag2=1;
}
return 0;
}
}
for(a=0;a<4;a++)
{
if(box[a].x==19)
{
for(int c=0;c<4;c++)
{
cor[box[c].x][box[c].y]=2;
boxcolor[box[c].x][box[c].y]=tempclr;
flag2=1;
}
return 0;
}
}
for(int o=0;o<4;o++)
{
box[o].x=box[o].x+1;
}
}
return 1;
*/
return 1;
}
void CMy0206220330View::Isover()
{
int flagover=0,n=0;
for(int a=19;a>=0;a--)
{
flagover=0;
for(int b=0;b<10;b++)
{
if(cor[a][b]==2)
{
flagover++;
}
}
if(flagover==10)
{
count++;
// count2+=100;
// if(count==3){
// if(time>100)
// time=time-100;
// count=0;
// }
for(b=0;b<10;b++)
{
cor[a][b]=0;
boxcolor[a][b]=RGB(255,255,255);//所有BOX变白
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -