📄 0206220330view.cpp
字号:
}
for(int t=a;t>0;t--)
{
for(b=0;b<10;b++)
{
if(cor[t-1][b]==2)
{
cor[t][b]=2;
boxcolor[t][b]=boxcolor[t-1][b];
flag2=1;
cor[t-1][b]=0;
boxcolor[t-1][b]=RGB(255,255,255);
}
}
}
a=a+1;
}
}//消除已满的方块
//////////////////////
//根据不同情况加分
count3=count3+count;
if(count==1)
count2=count2+100;
if(count==2)
count2=count2+400;
if(count==3)
count2=count2+900;
if(count==4)
count2=count2+1200;
if(count3>=shengji){
if(time==50&&count3>shengji){
OnPause();
MessageBox("恭喜你已通关!!",NULL,MB_OK);
}
if(time>50)
time=time-50;
count3=count3-shengji;
}
count=0;
for(a=0;a<9;a++)////////////判断是否GameOver
{
if(cor[0][a]==2)
{
isstart=0;
if(timer==1)
KillTimer(1);
if(timer==2)
KillTimer(2);
CString str;
str.Format("游戏结束!\n%s\n得分:%d",name,count2);
MessageBox(str);
time=500;
count2=0;
count=0;
count3=0;
for(int i=0;i<20;i++)
{
for(int j=0;j<10;j++)
{
cor[i][j]=0;
flag2=1;
}
}
// SetTimer(1,time,NULL);
MyDraw();
}
}
}
//DEL void CMy0206220330View::makebox()
//DEL {
//DEL for(int i=0;i<4;i++)
//DEL {
//DEL aa[i].x=0;
//DEL aa[i].y=0;
//DEL }
//DEL R=0;
//DEL H=5;
//DEL int REDclr=rand()%10;
//DEL int GREENclr=rand()%10;
//DEL int BLUEclr=rand()%10;
//DEL tempclr=RGB(REDclr*20,GREENclr*20,BLUEclr*20);
//DEL oldindex=index;
//DEL index=rand()%7;
//DEL switch(oldindex)
//DEL {
//DEL case 1:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R;
//DEL aa[2].y=H-1;
//DEL aa[3].x=R;
//DEL aa[3].y=H-2;
//DEL // tempclr=RGB(REDclr*20,154,175);
//DEL
//DEL /*//cor[R][H]=1;//----//
//DEL cor[R][H+1]=1;
//DEL cor[R][H-1]=1;
//DEL cor[R][H-2]=1;*/
//DEL break;
//DEL case 2:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R+1;
//DEL aa[2].y=H+1;
//DEL aa[3].x=R+1;
//DEL aa[3].y=H+2;
//DEL // tempclr=RGB(43,213,140);
//DEL
//DEL /* cor[R][H]=1;
//DEL cor[R][H+1]=1; //|_
//DEL cor[R+1][H+1]=1;// |
//DEL cor[R+1][H+2]=1;*/
//DEL break;
//DEL case 3:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R-1;
//DEL aa[2].y=H+1;
//DEL aa[3].x=R-1;
//DEL aa[3].y=H+2;
//DEL // tempclr=RGB(233,149,22);
//DEL /*cor[R][H]=1; // _|
//DEL cor[R+1][H]=1; // |
//DEL cor[R+1][H-1]=1;
//DEL cor[R+2][H-1]=1;*/
//DEL break;
//DEL case 4:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R;
//DEL aa[2].y=H+2;
//DEL aa[3].x=R+1;
//DEL aa[3].y=H+2;
//DEL // tempclr=RGB(210,23,191);
//DEL /*cor[R][H]=1; //|
//DEL cor[R+1][H]=1;// |
//DEL cor[R+2][H]=1;// |__
//DEL cor[R+2][H+1]=1;*/
//DEL break;
//DEL case 5:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R;
//DEL aa[2].y=H+2;
//DEL aa[3].x=R-1;
//DEL aa[3].y=H+2;
//DEL // tempclr=RGB(9,24,225);
//DEL /*cor[R][H]=1; //|
//DEL cor[R+1][H]=1;// |
//DEL cor[R+2][H]=1;//__|
//DEL cor[R+2][H-1]=1;*/
//DEL break;
//DEL case 6:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R+1;
//DEL aa[1].y=H;
//DEL aa[2].x=R+1;
//DEL aa[2].y=H+1;
//DEL aa[3].x=R+1;
//DEL aa[3].y=H-1;
//DEL // tempclr=RGB(5,228,211);
//DEL /*cor[R][H]=1;// |
//DEL cor[R+1][H]=1;// _|_
//DEL cor[R+1][H+1]=1;//
//DEL cor[R+1][H-1]=1;*/
//DEL break;
//DEL case 0:
//DEL aa[0].x=R;
//DEL aa[0].y=H;
//DEL aa[1].x=R;
//DEL aa[1].y=H+1;
//DEL aa[2].x=R+1;
//DEL aa[2].y=H;
//DEL aa[3].x=R+1;
//DEL aa[3].y=H+1;
//DEL // tempclr=RGB(77,68,70);
//DEL /*cor[R][H]=1; //|----|
//DEL cor[R][H+1]=1;// |____|
//DEL cor[R+1][H]=1;//
//DEL cor[R+1][H+1]=1;*/
//DEL break;
//DEL
//DEL
//DEL }
//DEL MyDraw();
//DEL K=1;
//DEL
//DEL }
int CMy0206220330View::round(int ab)
{
if(oldindex==0)/// 如果是四方块就不变形
return 0;
int tempx=0,tempy=0,a,d=0,h=0;
int temp2=0,temp1=0;
for(a=0;a<4;a++)
{
bb[a].x=box[a].x;
bb[a].y=box[a].y;
}
if(oldindex==1)
{
temp1=box[2].x;
temp2=box[2].y;
h=2;
}
else
{
temp1=box[1].x;
temp2=box[1].y;
h=1;
}
for(a=0;a<4;a++)
{
if(a!=h)
{
tempx=(box[a].x-temp1);
tempy=(box[a].y-temp2);
box[a].x=tempy+temp1;
box[a].y=-tempx+temp2;
if((cor[box[a].x][box[a].y]==2)||(box[a].y>9)||(box[a].y<0)||(box[a].x>19)||(box[a].x<0))
{
for(int d=0;d<4;d++)
{
box[d].x=bb[d].x;
box[d].y=bb[d].y;
}
return 0;
}
}
}
return 1;
}
int CMy0206220330View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
/* CString title;
title="俄罗斯方块";
AfxGetApp()->m_pMainWnd->GetWindowText(title);
AfxGetApp()->m_pMainWnd->SetWindowText("fffffffffffffff");*/
flag2=0;
k=0;
K=0;
pause=0;
pause=0;
for(int i=0;i<20;i++)
{
for(int j=0;j<11;j++)
{
cor[i][j]=0;
}
}
// count=0;
R=0;
// L=0;
H=0;
index=0;
flag=0;
// OnSet();
// makebox();
// AfxMessageBox(" 开 始",MB_OK,0);
// SetTimer(1,500,NULL);
return 0;
}
int CMy0206220330View::Isbottom()
{
for(int 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;
}
k=0;
return 0;
}
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;
}
k=0;
return 0;
}
}
return 1;
}
void CMy0206220330View::OnStart()
{
// TODO: Add your command handler code here
// OnSet();
isstart=1;
if(pause!=1)//判断是否按下Pause,如是,pause=1
showbox();
SetTimer(1,time,NULL);
}
void CMy0206220330View::OnStop()
{
// TODO: Add your command handler code here
isstart=0;
pause=0;
flag2=1;
flag=0;
count=0;
count2=0;
count3=0;
index=2;
time=500;
timer=0;
shengji=5;
name="姓名:无名氏";
facecolor=RGB(230,251,36);
KillTimer(1);
// CMy0206220330View();
// flag2=1;
// flag=1;
for(int i=0;i<20;i++)
{
for(int j=0;j<10;j++)
{
cor[i][j]=0;
}
}
OnPaint();
MyDraw();
// OnPaint();
}
void CMy0206220330View::OnPause()
{
// TODO: Add your command handler code here
isstart=0;
pause=1;
// KillTimer(1);
}
void CMy0206220330View::OnSet()
{
// TODO: Add your command handler code here
if(isstart)
OnPause();
CSET dlg;
if(dlg.DoModal()==IDOK)
{
facecolor=dlg.m_color;
time=(10-dlg.speed)*50;///////////////
name="姓名:"+dlg.m_name;
shengji=dlg.m_shengji;
}
OnPaint();
}
void CMy0206220330View::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar=='s'||nChar=='S')//83115 ||nChar==13 回车键
OnStart();
if(nChar=='p'||nChar=='P')//11280
OnPause();
if(nChar=='e'||nChar=='E')//69101
OnStop();
if(!isstart)
return;
switch(nChar){
case VK_DOWN:
case VK_NUMPAD2:
KillTimer(2);
timer=1;
SetTimer(1,time,NULL);
break;
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CMy0206220330View::makebox(int old)
{
for(int i=0;i<4;i++)
{
box[i].x=0;
box[i].y=0;
}
R=0;
H=5;
int REDclr=rand()%10;
int GREENclr=rand()%10;
int BLUEclr=rand()%10;
tempclr=RGB(REDclr*20,GREENclr*20,BLUEclr*20);
oldindex=index;
index=rand()%7;
nextbox(index);
switch(oldindex)
{
case 1:
box[0].x=R;
box[0].y=H;
box[1].x=R;
box[1].y=H+1; ///////////
box[2].x=R; ///////////
box[2].y=H-1;
box[3].x=R;
box[3].y=H-2;
break;
case 2:
box[0].x=R;
box[0].y=H;
box[1].x=R;
box[1].y=H+1; ///////
box[2].x=R+1; ///////
box[2].y=H+1;
box[3].x=R+1;
box[3].y=H+2;
break;
case 3:
box[0].x=R;
box[0].y=H;
box[1].x=R;
box[1].y=H+1; //////
box[2].x=R-1; ///////
box[2].y=H+1;
box[3].x=R-1;
box[3].y=H+2;
break;
case 4:
box[0].x=R;
box[0].y=H;
box[1].x=R; ///////////
box[1].y=H+1; ///////////
box[2].x=R; ///
box[2].y=H+2; ///
box[3].x=R+1;
box[3].y=H+2;
break;
case 5:
box[0].x=R;
box[0].y=H;
box[1].x=R;
box[1].y=H+1; ///
box[2].x=R; ///
box[2].y=H+2; ///////////
box[3].x=R-1; ///////////
box[3].y=H+2;
break;
case 6:
box[0].x=R;
box[0].y=H;
box[1].x=R+1;
box[1].y=H; ///
box[2].x=R+1; ///
box[2].y=H+1; ///////////
box[3].x=R+1; ///////////
box[3].y=H-1;
break;
case 0: ////////
box[0].x=R; ////////
box[0].y=H; ////////
box[1].x=R; ////////
box[1].y=H+1;
box[2].x=R+1;
box[2].y=H;
box[3].x=R+1;
box[3].y=H+1;
break;
}
K=1;
// CClientDC dc(this);
// int a=0;
// dc.FillSolidRect(10,40,90,120,RGB(255,255,255));
// for(int a=0;a<4;a++);
// {
// dc.FillSolidRect(20+dd[a].y*20,40+dd[a].x*20,20,20,RGB(68, 71, 140));
// dc.Draw3dRect(20+dd[a].y*20,40+dd[a].x*20,20,20,RGB(68, 71, 140), RGB(70, 166,152)); //下落时的重绘
// }
// MyDraw();
}
void CMy0206220330View::showbox()
{
// oldindex=index;
// index=rand()%7;
// nextbox(index);
// makebox(oldindex);
makebox(1);
}
void CMy0206220330View::nextbox(int next)
{
CClientDC dc(this);
int wide=20;
int hight=20;
dc.FillSolidRect(340,20,80,80,RGB(255,255,255));
if(next==1)
dc.FillSolidRect(340,40,80,20,tempclr);
if(next==6){
dc.FillSolidRect(360,60,60,20,tempclr);
dc.FillSolidRect(380,40,20,20,tempclr);
}
if(next==3){
dc.FillSolidRect(380,60,20,40,tempclr);
dc.FillSolidRect(360,40,20,40,tempclr);
}
if(next==2){
dc.FillSolidRect(380,40,20,40,tempclr);
dc.FillSolidRect(360,60,20,40,tempclr);
}
if(next==5){
dc.FillSolidRect(360,40,20,60,tempclr);
dc.FillSolidRect(380,80,20,20,tempclr);
}
if(next==4){
dc.FillSolidRect(380,40,20,60,tempclr);
dc.FillSolidRect(360,80,20,20,tempclr);
}
if(next==0)
dc.FillSolidRect(360,40,40,40,tempclr);
for(int x=0;x<4;x++){
for(int y=0;y<4;y++)
dc.Draw3dRect(340+x*20,20+y*20,20,20,RGB(68, 71, 140),RGB(70, 166,152));
}
}
void CMy0206220330View::OnInstruction()
{
// TODO: Add your command handler code here
CINFO dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -