first commit

master
296289990@qq.com 6 years ago
parent 0ee18ed52c
commit a25c012149

@ -140,6 +140,7 @@ void welcome()
case 1: case 1:
system("cls"); system("cls");
DrawGameframe(); DrawGameframe();
Gameplay();
break; break;
case 2: case 2:
break; break;
@ -192,7 +193,7 @@ void DrawGameframe()
gotoxy(FrameX+i,FrameY); gotoxy(FrameX+i,FrameY);
printf("¨T"); printf("¨T");
} }
for(i=2;i<Frame_width-2;i+=2){ for(i=2;i<2*Frame_width-2;i+=2){
gotoxy(FrameX+i,FrameY+Frame_height); gotoxy(FrameX+i,FrameY+Frame_height);
printf("¨T"); printf("¨T");
a[FrameX+i][FrameY+Frame_height]=2; a[FrameX+i][FrameY+Frame_height]=2;
@ -210,125 +211,195 @@ void DrawGameframe()
} }
/********制作俄罗斯方块*********/ /**
void MakeTetris(struct Tetris *tetris){ *
a[tetris->x][tetris->y]=b[0];//中心方块的图形状态 */
switch(tetris->flag){ void MakeTetris(struct Tetris *tetris)
case 1: //田字方块 {
a[tetris->x][tetris->y]=b[0]; //中心方块位置的图形状态
switch(tetris->flag) //共7大类19种类型
{
case 1: /*田字方块 ■■
*/
{
color(10); color(10);
a[tetris->x][tetris->y-1]=b[1]; a[tetris->x][tetris->y-1]=b[1];
a[tetris->x+2][tetris->y-1]=b[2]; a[tetris->x+2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3]; a[tetris->x+2][tetris->y]=b[3];
break; break;
case 2: //横直线方块 }
color(13); case 2: /*直线方块 ■■■■*/
a[tetris->x-2][tetris->y]=b[1]; {
a[tetris->x+2][tetris->y]=b[2]; color(13);
a[tetris->x+4][tetris->y]=b[3]; a[tetris->x-2][tetris->y]=b[1];
break; a[tetris->x+2][tetris->y]=b[2];
case 3: //竖直线方块 a[tetris->x+4][tetris->y]=b[3];
color(13); break;
a[tetris->x][tetris->y-1]=b[1]; }
a[tetris->x][tetris->y-2]=b[2]; case 3: /*直线方块 ■
a[tetris->x][tetris->y+1]=b[3];
break;
case 4: //T字方块 */
color(11); {
a[tetris->x-2][tetris->y]=b[1]; color(13);
a[tetris->x+2][tetris->y]=b[2]; a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y-1]=b[3]; a[tetris->x][tetris->y+1]=b[2];
break; a[tetris->x][tetris->y+2]=b[3];
case 5: //顺时针90°T字方块 break;
color(11); }
a[tetris->x][tetris->y-1]=b[1]; case 4: /*T字方块 ■■■
a[tetris->x-2][tetris->y]=b[2]; */
a[tetris->x][tetris->y+1]=b[3]; {
break; color(11);
case 6: //顺时针180°T字方块 a[tetris->x-2][tetris->y]=b[1];
color(11); a[tetris->x+2][tetris->y]=b[2];
a[tetris->x][tetris->y-1]=b[1]; a[tetris->x][tetris->y+1]=b[3];
a[tetris->x-2][tetris->y]=b[2]; break;
a[tetris->x+2][tetris->y]=b[3]; }
break; case 5: /* 顺时针90°T字方块 ■
case 7: //顺时针270°T字方块
color(11); */
a[tetris->x][tetris->y-1]=b[1]; {
a[tetris->x][tetris->y+1]=b[2]; color(11);
a[tetris->x+2][tetris->y]=b[3]; a[tetris->x][tetris->y-1]=b[1];
break; a[tetris->x][tetris->y+1]=b[2];
case 8: //Z字方块 a[tetris->x-2][tetris->y]=b[3];
color(14); break;
a[tetris->x+2][tetris->y+1]=b[1]; }
a[tetris->x][tetris->y+1]=b[2]; case 6: /* 顺时针180°T字方块 ■
a[tetris->x-2][tetris->y]=b[3]; */
break; {
case 9: //顺时针Z字方块 color(11);
color(14); a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y-1]=b[1]; a[tetris->x-2][tetris->y]=b[2];
a[tetris->x-2][tetris->y]=b[2]; a[tetris->x+2][tetris->y]=b[3];
a[tetris->x-2][tetris->y+1]=b[3]; break;
break; }
case 10: //反Z字方块 case 7: /* 顺时针270°T字方块 ■
color(14);
a[tetris->x][tetris->y-1]=b[1]; */
a[tetris->x-2][tetris->y-1]=b[2]; {
a[tetris->x+2][tetris->y]=b[3]; color(11);
break; a[tetris->x][tetris->y-1]=b[1];
case 11: //顺时针反Z字方块 a[tetris->x][tetris->y+1]=b[2];
color(14); a[tetris->x+2][tetris->y]=b[3];
a[tetris->x][tetris->y+1]=b[1]; break;
a[tetris->x-2][tetris->y-1]=b[2]; }
a[tetris->x-2][tetris->y]=b[3]; case 8: /* Z字方块 ■■
break; */
case 12: //7字方块 {
color(12); color(14);
a[tetris->x][tetris->y-1]=b[1]; a[tetris->x][tetris->y+1]=b[1];
a[tetris->x][tetris->y+1]=b[2]; a[tetris->x-2][tetris->y]=b[2];
a[tetris->x-2][tetris->y-1]=b[3]; a[tetris->x+2][tetris->y+1]=b[3];
break; break;
case 13: //顺时针90°7字方块 }
color(12); case 9: /* 顺时针Z字方块 ■
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y-1]=b[2]; */
a[tetris->x+2][tetris->y]=b[3]; {
break; color(14);
case 14: //顺时针180°7字方块 a[tetris->x][tetris->y-1]=b[1];
color(12); a[tetris->x-2][tetris->y]=b[2];
a[tetris->x][tetris->y-1]=b[1]; a[tetris->x-2][tetris->y+1]=b[3];
a[tetris->x][tetris->y+1]=b[2]; break;
a[tetris->x+2][tetris->y+1]=b[3]; }
break; case 10: /* 反转Z字方块 ■■
case 15: //顺时针270°7字方块 */
color(12); {
a[tetris->x][tetris->y-1]=b[1]; color(14);
a[tetris->x][tetris->y+1]=b[2]; a[tetris->x][tetris->y-1]=b[1];
a[tetris->x+2][tetris->y]=b[3]; a[tetris->x-2][tetris->y-1]=b[2];
break; a[tetris->x+2][tetris->y]=b[3];
case 16: //反7字方块 break;
color(12); }
a[tetris->x][tetris->y-1]=b[1]; case 11: /* 顺时针Z字方块 ■
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y-1]=b[3]; */
break; {
case 17: //顺时针90°反7字方块 color(14);
color(12); a[tetris->x][tetris->y+1]=b[1];
a[tetris->x-2][tetris->y]=b[1]; a[tetris->x-2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y+1]=b[2]; a[tetris->x-2][tetris->y]=b[3];
a[tetris->x+2][tetris->y]=b[3]; break;
break; }
case 18: //顺时针180°反7字方块 case 12: /* 7字方块 ■■
color(12);
a[tetris->x][tetris->y-1]=b[1]; */
a[tetris->x][tetris->y+1]=b[2]; {
a[tetris->x-2][tetris->y+1]=b[3]; color(12);
break; a[tetris->x][tetris->y-1]=b[1];
case 19: //顺时针270°反7字方块 a[tetris->x][tetris->y+1]=b[2];
color(12); a[tetris->x-2][tetris->y-1]=b[3];
a[tetris->x-2][tetris->y]=b[1]; break;
a[tetris->x-2][tetris->y-1]=b[2]; }
a[tetris->x+2][tetris->y]=b[3]; case 13: /* 顺时针90°7字方块 ■
break; */
} {
color(12);
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
break;
}
case 14: /* 顺时针180°7字方块 ■
*/
{
color(12);
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y+1]=b[3];
break;
}
case 15: /* 顺时针270°7字方块 ■■■
*/
{
color(12);
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x-2][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
break;
}
case 16: /* 反转7字方块 ■■
*/
{
color(12);
a[tetris->x][tetris->y+1]=b[1];
a[tetris->x][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y-1]=b[3];
break;
}
case 17: /* 顺时针转90°7字方块 ■■■
*/
{
color(12);
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
break;
}
case 18: /* 顺时针转180°7字方块 ■
*/
{
color(12);
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x-2][tetris->y+1]=b[3];
break;
}
case 19: /* 顺指针转270°7字方块 ■
*/
{
color(12);
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x-2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
break;
}
}
} }
@ -364,114 +435,142 @@ void PrintTetris(struct Tetris *tetris){
} }
/******判断方块能否移动******/ /**
*
*/
int ifMove(struct Tetris *tetris) int ifMove(struct Tetris *tetris)
{ {
if(a[tetris->x][tetris->y]!=0){ if(a[tetris->x][tetris->y]!=0)//当中心方块位置上有图案时返回值为0即不可移动
return 0; {
} return 0;
else{ }
if( else
(tetris->flag==1&&(a[tetris->x][tetris->y-1]==0&& {
a[tetris->x][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| if(
(tetris->flag==2&&(a[tetris->x-2][tetris->y]==0&& ( tetris->flag==1 && ( a[tetris->x][tetris->y-1]==0 &&/*当为田字方块且除中心方块位
a[tetris->x+2][tetris->y]==0&&a[tetris->x+4][tetris->y]==0))|| ""1
(tetris->flag==3&&(a[tetris->x][tetris->y-1]==0&& */
a[tetris->x][tetris->y-2]==0&&a[tetris->x][tetris->y+1]==0))|| a[tetris->x+2][tetris->y-1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
(tetris->flag==4&&(a[tetris->x-2][tetris->y]==0&& //或为直线方块且除中心方块位置外,其他"■"字方块位置上无图案时返回值为1即可移动
a[tetris->x+2][tetris->y]==0&&a[tetris->x][tetris->y+1]==0))|| ( tetris->flag==2 && ( a[tetris->x-2][tetris->y]==0 &&
(tetris->flag==5&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x+2][tetris->y]==0 && a[tetris->x+4][tetris->y]==0 ) ) ||
a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y]==0))|| ( tetris->flag==3 && ( a[tetris->x][tetris->y-1]==0 && //直线方块(竖)
(tetris->flag==6&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x][tetris->y-2]==0 && a[tetris->x][tetris->y+1]==0 ) ) ||
a[tetris->x-2][tetris->y]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==4 && ( a[tetris->x-2][tetris->y]==0 && //T字方块
(tetris->flag==7&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x+2][tetris->y]==0 && a[tetris->x][tetris->y+1]==0 ) ) ||
a[tetris->x][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==5 && ( a[tetris->x][tetris->y-1]==0 && //T字方块顺时针90°
(tetris->flag==8&&(a[tetris->x][tetris->y+1]==0&& a[tetris->x][tetris->y+1]==0 && a[tetris->x-2][tetris->y]==0 ) ) ||
a[tetris->x-2][tetris->y]==0&&a[tetris->x+2][tetris->y+1]==0))|| ( tetris->flag==6 && ( a[tetris->x][tetris->y-1]==0 && //T字方块顺时针180°
(tetris->flag==9&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x-2][tetris->y]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
a[tetris->x-2][tetris->y]==0&&a[tetris->x-2][tetris->y+1]==0))|| ( tetris->flag==7 && ( a[tetris->x][tetris->y-1]==0 && //T字方块顺时针270°
(tetris->flag==10&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x][tetris->y+1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
a[tetris->x-2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==8 && ( a[tetris->x][tetris->y+1]==0 && //Z字方块
(tetris->flag==11&&(a[tetris->x][tetris->y+1]==0&& a[tetris->x-2][tetris->y]==0 && a[tetris->x+2][tetris->y+1]==0 ) ) ||
a[tetris->x-2][tetris->y-1]==0&&a[tetris->x-2][tetris->y]==0))|| ( tetris->flag==9 && ( a[tetris->x][tetris->y-1]==0 && //Z字方块顺时针180°
(tetris->flag==12&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x-2][tetris->y]==0 && a[tetris->x-2][tetris->y+1]==0 ) ) ||
a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y-1]==0))|| ( tetris->flag==10 && ( a[tetris->x][tetris->y-1]==0 && //Z字方块反转
(tetris->flag==13&&(a[tetris->x-2][tetris->y]==0&& a[tetris->x-2][tetris->y-1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
a[tetris->x+2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==11 && ( a[tetris->x][tetris->y+1]==0 &&//Z字方块反转+顺时针180°
(tetris->flag==14&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x-2][tetris->y-1]==0 && a[tetris->x-2][tetris->y]==0 ) ) ||
a[tetris->x][tetris->y+1]==0&&a[tetris->x+2][tetris->y+1]==0))|| ( tetris->flag==12 && ( a[tetris->x][tetris->y-1]==0 && //7字方块
(tetris->flag==15&&(a[tetris->x-2][tetris->y]==0&& a[tetris->x][tetris->y+1]==0 && a[tetris->x-2][tetris->y-1]==0 ) ) ||
a[tetris->x-2][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==15 && ( a[tetris->x-2][tetris->y]==0 && //7字方块顺时针90°
(tetris->flag==16&&(a[tetris->x][tetris->y+1]==0&& a[tetris->x-2][tetris->y+1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
a[tetris->x][tetris->y-1]==0&&a[tetris->x+2][tetris->y-1]==0))|| ( tetris->flag==14 && ( a[tetris->x][tetris->y-1]==0 && //7字方块顺时针180°
(tetris->flag==17&&(a[tetris->x-2][tetris->y]==0&& a[tetris->x][tetris->y+1]==0 && a[tetris->x+2][tetris->y+1]==0 ) ) ||
a[tetris->x+2][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| ( tetris->flag==13 && ( a[tetris->x-2][tetris->y]==0 && //7字方块顺时针270°
(tetris->flag==18&&(a[tetris->x][tetris->y-1]==0&& a[tetris->x+2][tetris->y-1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y+1]==0))|| ( tetris->flag==16 && ( a[tetris->x][tetris->y+1]==0 && //7字方块反转
(tetris->flag==19&&(a[tetris->x-2][tetris->y]==0&& a[tetris->x][tetris->y-1]==0 && a[tetris->x+2][tetris->y-1]==0 ) ) ||
a[tetris->x-2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))) ( tetris->flag==19 && ( a[tetris->x-2][tetris->y]==0 &&//7字方块反转+顺时针90°
{ a[tetris->x-2][tetris->y-1]==0 && a[tetris->x+2][tetris->y]==0 ) ) ||
return 1; ( tetris->flag==18 && ( a[tetris->x][tetris->y-1]==0 &&//7字方块反转+顺时针180°
} a[tetris->x][tetris->y+1]==0 && a[tetris->x-2][tetris->y+1]==0 ) ) ||
( tetris->flag==17 && ( a[tetris->x-2][tetris->y]==0 &&//7字方块反转+顺时针270°
a[tetris->x+2][tetris->y+1]==0 && a[tetris->x+2][tetris->y]==0 ) ) )
{
return 1;
}
} }
return 0; return 0;
} }
/*******清除俄罗斯方块的痕迹********/
void CleanTetris(struct Tetris *tetris){ void CleanTetris(struct Tetris *tetris)
for(i=0;i<4;i++){ {
b[i]=0; for(i=0;i<4;i++) //数组b[4]中有4个元素循环这4个元素让每个元素的值都为0
} {
MakeTetris(tetris); b[i]=0; //数组b[4]的每个元素的值都为0
for(i=tetris->x-2;i<=tetris->x+4;i+=2){ }
for(tetris->y-2;i<=tetris->y+1;j++){ MakeTetris(tetris); //制作俄罗斯方块
if(a[i][j]==0&&j>FrameY){ for( i = tetris->x - 2;i <= tetris->x + 4; i+=2 ) //■X■■ X为中心方块
gotoxy(i,j); {
printf(" "); for(j = tetris->y-2;j <= tetris->y + 1;j++) /* ■
}
} X
} */
} {
if( a[i][j] == 0 && j > FrameY ) //如果这个位置上没有图案,并且处于游戏界面当中
{
gotoxy(i,j);
printf(" "); //清除方块
}
}
}
}
/*******判断是否满行********/ /**
void Del_Fullline(struct Tetris *tetris){ *
int k,del_rows=0; */
for(j=FrameY+Frame_height-1;j>=FrameY+1;j--){ void Del_Fullline(struct Tetris *tetris) //当某行有Frame_width-2个方块时则满行消除
k=0; {
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2){ int k,del_rows=0; //分别用于记录某行方块的个数和删除方块的行数的变量
if(a[i][j]==1){ for(j=FrameY+Frame_height-1;j>=FrameY+1;j--)
k++; {
if(k==Frame_width-2){ k=0;
for(k=FrameX+2;k<FrameX+2*Frame_width-2;k+=2){ for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2)
a[k][j]=0; {
gotoxy(k,j); if(a[i][j]==1) //纵坐标依次从下往上,横坐标依次由左至右判断是否满行
printf(""); {
} k++; //记录此行方块的个数
for(k=j-1;k>FrameY;k--){ if(k==Frame_width-2) //如果满行
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2){ {
if(a[i][k]==1){ for(k=FrameX+2;k<FrameX+2*Frame_width-2;k+=2) //删除满行的方块
a[i][k]=0; {
gotoxy(i,k); a[k][j]=0;
printf(" "); gotoxy(k,j);
a[i][k+1]=1; printf(" ");
gotoxy(i,k+1); }
printf(""); //如果删除行以上的位置有方块,则先清除,再将方块下移一个位置
} for(k=j-1;k>FrameY;k--)
} {
} for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2)
j++; {
del_rows++; if(a[i][k]==1)
} {
} a[i][k]=0;
} gotoxy(i,k);
} printf(" ");
tetris->score+=100*del_rows; a[i][k+1]=1;
if(del_rows>0&&(tetris->score%1000==0||tetris->score/1000>tetris->level-1)){ gotoxy(i,k+1);
tetris->speed-+20; printf("");
tetris->level++; }
} }
}
j++; //方块下移后,重新判断删除行是否满行
del_rows++; //记录删除方块的行数
}
}
}
}
tetris->score+=100*del_rows; //每删除一行得100分
if( del_rows>0 && ( tetris->score%1000==0 || tetris->score/1000>tetris->level-1 ) )
{ //如果得1000分即累计删除10行速度加快20ms并升一级
tetris->speed-=20;
tetris->level++;
}
} }
@ -486,142 +585,181 @@ void Flag(struct Tetris *tetris){
} }
/*******开始游戏*******/ /**
void Gameplay(){ *
*/
void Gameplay()
{
int n; int n;
struct Tetris t,*tetris=&t; struct Tetris t,*tetris=&t; //定义结构体的指针并指向结构体变量
char ch; char ch; //定义接收键盘输入的变量
tetris->number=0; tetris->number=0; //初始化俄罗斯方块数为0个
tetris->speed=300; tetris->speed=300; //初始移动速度为300ms
tetris->score=0; tetris->score=0; //初始游戏的分数为0分
tetris->level=1; tetris->level=1; //初始游戏为第1关
while(1){ while(1) //循环产生方块,直至游戏结束
Flag(tetris); {
Temp=tetris->flag; Flag(tetris); //得到产生俄罗斯方块类型的序号
tetris->x=FrameX+2*Frame_width+6; Temp=tetris->flag; //记住当前俄罗斯方块序号
tetris->y=FrameY+10; tetris->x=FrameX+2*Frame_width+6; //获得预览界面方块的x坐标
tetris->flag=tetris->next; tetris->y=FrameY+10; //获得预览界面方块的y坐标
PrintTetris(tetris); tetris->flag = tetris->next; //获得下一个俄罗斯方块的序号
tetris->x=FrameX+Frame_width; PrintTetris(tetris); //调用打印俄罗斯方块方法
tetris->y=FrameY-1; tetris->x=FrameX+Frame_width; //获得游戏窗口中心方块x坐标
tetris->flag=Temp; tetris->y=FrameY-1; //获得游戏窗口中心方块y坐标
/******获取键盘按键*******/ tetris->flag=Temp; //按键操作
while(1){ while(1) //控制方块方向,直至方块不再下移
label:PrintTetris(tetris); {
Sleep(tetris->speed);//控制时间 label:PrintTetris(tetris); //打印俄罗斯方块
CleanTetris(tetris); Sleep(tetris->speed); //延缓时间
Temp1=tetris->x; CleanTetris(tetris); //清除痕迹
Temp2+tetris->flag; Temp1=tetris->x; //记住中心方块横坐标的值
if(kbhit()){ Temp2=tetris->flag; //记住当前俄罗斯方块序号
ch=getch(); if(kbhit()) //判断是否有键盘输入有则用ch↓接收
if(ch==75){ {
tetris->x-=2; //←键左移 ch=getch();
} if(ch==75) //按 ←键则向左动中心横坐标减2
if(ch==77) tetris->x+=2;//→键右移 {
if(ch==80){ //↓键加速下落 tetris->x-=2;
if(ifMove(tetris)!=0) tetris->y+=2; }
else tetris->y=FrameY+Frame_height-2; if(ch==77) //按 →键则向右动中心横坐标加2
} {
if(ch==72){ tetris->x+=2;
if(tetris->flag>=2&&tetris->flag<=3){ }
tetris->flag++; if(ch==80) //按 ↓键则加速下落
tetris->flag%=2; {
tetris->flag+=2; if(ifMove(tetris)!=0)
}//直线方块 {
if(tetris->flag>=4&&tetris->flag<=7){ tetris->y+=2;
tetris->flag++;
tetris->flag%=4;
tetris->flag+=4;
}//T字方块
if(tetris->flag>=8&&tetris->flag<=11){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=8;
}//Z字方块
if(tetris->flag>=12&&tetris->flag<=15){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=12;
}// 7字方块
if(tetris->flag>=16&&tetris->flag<=19){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=16;
}//反7字方块
}
if(ch==32) //空格暂停
{
PrintTetris(tetris);
while(1){
if(kbhit()){
ch=getch();
if(ch==32) goto label;
}
} }
} if(ifMove(tetris)==0)
if(ch==27){ //ESC退出游戏 {
tetris->y=FrameY+Frame_height-2;
}
}
if(ch==72) //按 ↑键则变体,即当前方块顺时针转90度
{
if( tetris->flag>=2 && tetris->flag<=3 ) //如果是直线方块
{
tetris->flag++;
tetris->flag%=2;
tetris->flag+=2;
}
if( tetris->flag>=4 && tetris->flag<=7 ) //如果是T字方块
{
tetris->flag++;
tetris->flag%=4;
tetris->flag+=4;
}
if( tetris->flag>=8 && tetris->flag<=11 ) //如果是Z字方块
{
tetris->flag++;
tetris->flag%=4;
tetris->flag+=8;
}
if( tetris->flag>=12 && tetris->flag<=15 ) //如果是7字方块
{
tetris->flag++;
tetris->flag%=4;
tetris->flag+=12;
}
if( tetris->flag>=16 && tetris->flag<=19 ) //如果是反7字方块
{
tetris->flag++;
tetris->flag%=4;
tetris->flag+=16;
}
}
if(ch == 32) //按空格键,暂停
{
PrintTetris(tetris);
while(1)
{
if(kbhit()) //再按空格键,继续游戏
{
ch=getch();
if(ch == 32)
{
goto label;
}
}
}
}
if(ch == 27)
{
system("cls"); system("cls");
memset(a,0,6400*sizeof(int));//初始化数组 memset(a,0,6400*sizeof(int));
title(); //初始化a数组
welcome(); welcome();
} }
if(ifMove(tetris)==0){ if(ifMove(tetris)==0) //如果不可动,上面操作无效
tetris->x=Temp1; {
tetris->flag=Temp2; tetris->x=Temp1;
} tetris->flag=Temp2;
else{ }
goto label; else //如果可动,执行操作
} {
} goto label;
tetris->y++; }
if(ifMove(tetris)==0){ }
tetris->y--; tetris->y++; //如果没有操作指令,方块向下移动
PrintTetris(tetris); if(ifMove(tetris)==0) //如果向下移动且不可动,方块放在此处
Del_Fullline(tetris); {
break; tetris->y--;
} PrintTetris(tetris);
} Del_Fullline(tetris);
//游戏结束 break;
for(i=tetris->y-2;i<tetris->y+2;i++){ }
if(i==FrameY){ }//游戏结束条件:方块触到框顶位置
system("cls"); for(i=tetris->y-2;i<tetris->y+2;i++)
gotoxy(29,7); {
printf(" \n"); if(i==FrameY)
color(12); {
printf("\t\t\t████ █ █ ██ \n"); system("cls"); //清屏
gotoxy(29,7); //设置显示位置
printf("\t\t\t█ ██ █ █ █ \n"); printf(" \n");
color(12); //红色
printf("\t\t\t███ █ █ █ █ █ \n"); printf("\t\t\t■■■■ ■ ■ ■■ \n");
printf("\t\t\t■ ■■ ■ ■ ■ \n");
printf("\t\t\t█ █ ██ █ █ \n"); printf("\t\t\t■■■ ■ ■ ■ ■ ■ \n");
printf("\t\t\t■ ■ ■ ■ ■ ■ \n");
printf("\t\t\t████ █ █ ██ \n"); printf("\t\t\t■■■■ ■ ■ ■■ \n");
gotoxy(17,18); gotoxy(17,18);
color(14); color(14);
printf("我要重新玩一局---------1"); printf("我要重新玩一局-------1");
gotoxy(44,18); gotoxy(44,18);
printf("不玩了,退出-----------2\n"); printf("不玩了,退出吧-------2\n");
int n; int n;
gotoxy(32,20); gotoxy(32,20);
printf("选择【1/2】"); printf("选择【1/2】");
color(11); color(11);
scanf("%d",&n); scanf("%d", &n); //输入1或2
switch(n){ switch (n) //分支语句
case 1: {
system("cls"); case 1:
Replay(tetris); system("cls");
break; Replay(tetris); //重新开始游戏
case 2: break;
exit(0); case 2:
break; exit(0);
} break;
} }
} }
tetris->flag=tetris->next; }
tetris->x=FrameX+2*Frame_width+6; tetris->flag = tetris->next; //清除下一个俄罗斯方块的图形(右边窗口)
tetris->y=FrameY+10; tetris->x=FrameX+2*Frame_width+6;
CleanTetris(tetris); tetris->y=FrameY+10;
} CleanTetris(tetris);
}
}
/*******重新开始游戏函数*******/
void Replay(struct Tetris *tetris){
system("cls");
memset(a,0,6400*sizeof(int));
DrawGameframe();
Gameplay();
} }

Binary file not shown.
Loading…
Cancel
Save