📄 aaaaview.cpp
字号:
for(int jj = -1; jj <= 3;jj++)
{
if (s2.co[0]+2 == i && s2.co[1] == jj)
cout<<"■";
else if (s2.co[2]+2 == i && s2.co[3] == jj)
cout<<"■";
else if (s2.co[4]+2 == i && s2.co[5] == jj)
cout<<"■";
else if (s2.co[6]+2 == i && s2.co[7] == jj)
cout<<"■";
else
cout<<" ";
}
}
cout<<endl<<" 分数:"<<score<<endl;
}
*/
void CAaaaView::update(point p, shape s)//更新
{
int i,j, count = 0;
for(i = 0; i <= 19;i++)
{
for(j = 1; j <= 13;j++)
{
if(p.i > 0)
{
if (s.co[0]+ p.i == i && s.co[1] + p.j == j)
back[i][j] = 1;
else if (s.co[2]+ p.i == i && s.co[3]+p.j == j)
back[i][j] = 1;
else if (s.co[4]+p.i == i && s.co[5]+ p.j == j)
back[i][j] = 1;
else if (s.co[6]+ p.i == i && s.co[7]+ p.j== j)
back[i][j] = 1;
}
}
}
for(i = 0;i <= 19; i++) //消行
{
int flag = 1;
for(j = 1; j <=13; j++)
{
if(back[i][j] != 1)
{
flag = 0;
break;
}
}
if(flag == 1)
{
int k = i;
for(k=i;k>= 1;k--)
{
for(j=1;j<=13;j++)
back[k][j] = back[k-1][j];
}
count++;
}
}
if(count == 1)
score += 100;
else if(count == 2)
score += 300;
else if(count == 3)
score += 500;
else if(count == 4)
score += 800;
level = score/100 +1;
speed = 1000/level;
/* for(j = 1; j <=13; j++)
{
if(back[1][j] == 1)
{
MessageBox("sssssssss");
if( _continue())
{
for(int ii = 0; ii <= 19; ii++)
for(int jj = 1; jj <= 13;jj++)
back[ii][jj] = 0;
}
else
exit(0);
}
}*/
}
int CAaaaView::check_buttom(point p, shape s)
{
if (p.i >= 0)
if(back[s.co[0]+ p.i +1][s.co[1]+p.j]==1 ||back[s.co[2]+ p.i +1][s.co[3]+p.j] == 1
||back[s.co[4]+ p.i +1][s.co[5]+p.j]==1 ||back[s.co[6]+ p.i +1][s.co[7]+p.j]==1 )
{
return 0;//如果到底返回0
}
return 1;//没有到底返回1
}
void CAaaaView::move()
{
/* while(1)
{
for(int i = 1; i <= 30; i++)
{
if(_kbhit())//_kbhit()判断是否有键盘消息
{
switch(_getch())//接收数据
{
case 0x50: // ↓向下移动
if(check_buttom(p, ps[t1]))
{
p.i++;
system("cls");
// show(p,ps[t1],ps[t2]);
}
break;
case 0x4B: // ←向左移动
if(back[ps[t1].co[0]+ p.i][ps[t1].co[1]+p.j - 1] == 0 && back[ps[t1].co[2]+ p.i][ps[t1].co[3]+p.j - 1] == 0
&& back[ps[t1].co[4]+ p.i][ps[t1].co[5]+p.j - 1] == 0 && back[ps[t1].co[6]+ p.i][ps[t1].co[7]+p.j - 1] == 0)
{
p.j--;
system("cls");
//show(p,ps[t1],ps[t2]);
}
break;
case 0x4d: // →向右移动
if(back[ps[t1].co[0]+ p.i][ps[t1].co[1]+p.j + 1]==0 && back[ps[t1].co[2]+ p.i][ps[t1].co[3]+p.j + 1] == 0
&& back[ps[t1].co[4]+ p.i][ps[t1].co[5]+p.j + 1]==0 && back[ps[t1].co[6]+ p.i][ps[t1].co[7]+p.j + 1]==0)
{
p.j++;
system("cls");
// show(p,ps[t1],ps[t2]);
}
break;
case 0x48:// ↑变换形状
if(t1 == 3&&check_change( p, ps[0])) t1 = 0;
else if(t1 == 5&&check_change( p, ps[4])) t1 = 4;
else if(t1 == 6) t1 = 6;
else if(t1 == 8&&check_change(p, ps[7])) t1 = 7;
else if(t1 == 10&&check_change( p, ps[9])) t1 = 9;
else if(t1 == 14&&check_change(p, ps[11])) t1 = 11;
else if(t1 == 18&&check_change( p, ps[15])) t1 = 15;
else if(check_change( p, ps[t1+1])) t1++;
break;
case 32: //空格 直接降到底端
while(check_buttom(p, ps[t1]))
{
p.i++;
}
default:
break;
}
}
}*/
if(check_buttom(p, ps[t1]))
{
// system("cls");
p.i++;
show(p, ps[t1],ps[t2]);
}
else
{
if(p.i<=0)
{
KillTimer(1);
MessageBox("游戏结束");
}
//KillTimer(hWnd,1);
update(p, ps[t1]);
t1 = t2;
t2 = rand()%19;
p.i = -2;
p.j = 4;
}
}
void CAaaaView::nint()//画方框
{
int i, j;
for(i = 0; i<= 20; i++)
for(j = 0; j <=14;j++)
{
if(j == 0 || j == 14 || i == 20)
back[i][j] = 1;
else
back[i][j] = 0;
}
}
int CAaaaView::_continue()
{
cout<<"是否继续游戏?\n";
cout<<"y 是 n 否 \n";
switch(_getch())
{
case 'y'||'Y':
return 1; break;
case 'n':
return 0; break;
}
return 0;
}
void CAaaaView::show(point p,shape s, shape s2)
{
CDC* dc=GetDC();
char title[10]="Next :", str[10] = "Level: ";
int wide =18;
int hight = 18;
for(int x = 0; x <= 20; x++)
{
for(int j = 0; j <= 14; j++)
{
if (x == 20 || j == 0 || j == 14 )
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(10, 10, 10));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(10, 10, 10), RGB(10, 10, 10));
}
else if (s.co[0] + p.i == x && s.co[1]+ p.j ==j)
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if (s.co[2] + p.i == x && s.co[3]+ p.j== j)
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if (s.co[4] + p.i == x && s.co[5]+ p.j == j)
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if (s.co[6]+ p.i == x && s.co[7]+ p.j == j)
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if (back[x][j] == 1 )
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else
{
dc->FillSolidRect(j*18,x*18,wide,hight,RGB(0, 255, 0));
dc->Draw3dRect(j*18,x*18,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
}
}
//if (x==1)
// TextOut(hdc, r.left, r.top, "Defenestration can be hazardous", 4); //( int x, int y, const CString& str );
for(x = 0; x<= 3; x++)
{
for(int jj=0;jj<=3;jj++)
{
if(s2.co[0] == x && s2.co[1] ==jj)
{
dc->FillSolidRect(jj*18+300,x*18+60,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(jj*18+300,x*18+60,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if(s2.co[2] == x && s2.co[3] ==jj)
{
dc->FillSolidRect(jj*18+300,x*18+60,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(jj*18+300,x*18+60,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if(s2.co[4] == x && s2.co[5] ==jj)
{
dc->FillSolidRect(jj*18+300,x*18+60,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(jj*18+300,x*18+60,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else if(s2.co[6] == x && s2.co[7] ==jj)
{
dc->FillSolidRect(jj*18+300,x*18+60,wide,hight,RGB(255, 0, 255));
dc->Draw3dRect(jj*18+300,x*18+60,wide,hight,RGB(0, 0, 255), RGB(0, 255, 0));
}
else
{
dc->FillSolidRect(jj*18+300,x*18+60,wide,hight,RGB(255, 255, 255));
dc->Draw3dRect(jj*18+300,x*18+60,wide,hight,RGB(255,255, 255), RGB(255, 255, 255));
}
}
}
dc->TextOut(300,30,title);
sprintf(str, "Level : %d", level);
dc->TextOut(300, 200, str);
sprintf(str, "Score : %d", score);
dc->TextOut(300, 300, str);
dc->SetBkColor(RGB(20,255, 0));
}
void CAaaaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case 'P':
if(timeFlag)
{
KillTimer(1);
timeFlag = 0;
}
else
{
SetTimer(1, speed, NULL);
timeFlag = 1;
}
break;
case VK_LEFT:
if(back[ps[t1].co[0]+ p.i][ps[t1].co[1]+p.j - 1] == 0 && back[ps[t1].co[2]+ p.i][ps[t1].co[3]+p.j - 1] == 0
&& back[ps[t1].co[4]+ p.i][ps[t1].co[5]+p.j - 1] == 0 && back[ps[t1].co[6]+ p.i][ps[t1].co[7]+p.j - 1] == 0)
{
p.j--;
show(p,ps[t1],ps[t2]);
}
break;
case VK_RIGHT:
if(back[ps[t1].co[0]+ p.i][ps[t1].co[1]+p.j + 1]==0 && back[ps[t1].co[2]+ p.i][ps[t1].co[3]+p.j + 1] == 0
&& back[ps[t1].co[4]+ p.i][ps[t1].co[5]+p.j + 1]==0 && back[ps[t1].co[6]+ p.i][ps[t1].co[7]+p.j + 1]==0)
{
p.j++;
// system("cls");
show(p,ps[t1],ps[t2]);
}
break;
case VK_UP:
if(t1 == 3&&check_change( p, ps[0])) t1 = 0;
else if(t1 == 5&&check_change( p, ps[4])) t1 = 4;
else if(t1 == 6) t1 = 6;
else if(t1 == 8&&check_change(p, ps[7])) t1 = 7;
else if(t1 == 10&&check_change( p, ps[9])) t1 = 9;
else if(t1 == 14&&check_change(p, ps[11])) t1 = 11;
else if(t1 == 18&&check_change( p, ps[15])) t1 = 15;
else if(check_change( p, ps[t1+1])) t1++;
break;
case VK_DOWN:
if(check_buttom(p, ps[t1]))
{
p.i++;
//system("cls");
show(p,ps[t1],ps[t2]);
}
break;
case 32:
while(check_buttom(p, ps[t1]))
{
p.i++;
}
show(p,ps[t1],ps[t2]);
break;
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -