|
|
@ -25,6 +25,7 @@ struct Tetris
|
|
|
|
} ;
|
|
|
|
} ;
|
|
|
|
HANDLE hOut; //控制台句柄
|
|
|
|
HANDLE hOut; //控制台句柄
|
|
|
|
/****函数声明****/
|
|
|
|
/****函数声明****/
|
|
|
|
|
|
|
|
void HideCursor();
|
|
|
|
int color(int c); //控制文字颜色函数
|
|
|
|
int color(int c); //控制文字颜色函数
|
|
|
|
void gotoxy(int x,int y); //获取屏幕光标位置
|
|
|
|
void gotoxy(int x,int y); //获取屏幕光标位置
|
|
|
|
void Game(); //游戏界面
|
|
|
|
void Game(); //游戏界面
|
|
|
@ -34,18 +35,24 @@ void rule(); //
|
|
|
|
void Make(struct Tetris *); //制作方块
|
|
|
|
void Make(struct Tetris *); //制作方块
|
|
|
|
void Print(struct Tetris *); //打印方块
|
|
|
|
void Print(struct Tetris *); //打印方块
|
|
|
|
void Clean(struct Tetris *); //清除痕迹
|
|
|
|
void Clean(struct Tetris *); //清除痕迹
|
|
|
|
/**
|
|
|
|
int ifMove(struct Tetris *); //判断是否能移动,1动;0不动
|
|
|
|
*控制文字颜色函数
|
|
|
|
void Flag(struct Tetris *); //随机产生方块
|
|
|
|
*/
|
|
|
|
void Full(struct Tetris *); // 判断方块是否满行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*隐藏控制台的光标*/
|
|
|
|
|
|
|
|
void HideCursor()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
|
|
|
|
|
|
|
|
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**控制文字颜色函数 */
|
|
|
|
int color(int c)
|
|
|
|
int color(int c)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*获取屏幕光标位置 */
|
|
|
|
*获取屏幕光标位置
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void gotoxy(int x,int y)
|
|
|
|
void gotoxy(int x,int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
COORD pos;
|
|
|
|
COORD pos;
|
|
|
@ -56,10 +63,8 @@ void gotoxy(int x,int y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*首页 */
|
|
|
|
*首页
|
|
|
|
int main()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*图案*/
|
|
|
|
/*图案*/
|
|
|
|
color(11);
|
|
|
|
color(11);
|
|
|
@ -174,11 +179,10 @@ void main()
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*按键说明 */
|
|
|
|
*按键说明
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void explation()
|
|
|
|
void explation()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i,j = 1;
|
|
|
|
int i,j = 1;
|
|
|
@ -196,22 +200,22 @@ void explation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
color(12);
|
|
|
|
color(12);
|
|
|
|
gotoxy(16,9);
|
|
|
|
gotoxy(16,8);
|
|
|
|
printf("1/通过 ← →方向键来移动方块");
|
|
|
|
printf("1/通过 ← →方向键来移动方块");
|
|
|
|
gotoxy(16,11);
|
|
|
|
gotoxy(16,10);
|
|
|
|
printf("2/通过 ↑使方块旋转");
|
|
|
|
printf("2/通过 ↑使方块旋转");
|
|
|
|
gotoxy(16,13);
|
|
|
|
gotoxy(16,12);
|
|
|
|
printf("3/通过 ↓加速方块下落");
|
|
|
|
printf("3/通过 ↓加速方块下落");
|
|
|
|
gotoxy(16,15);
|
|
|
|
gotoxy(16,14);
|
|
|
|
printf("4/通过空格键暂停游戏");
|
|
|
|
printf("4/通过空格键暂停游戏");
|
|
|
|
|
|
|
|
gotoxy(16,16);
|
|
|
|
|
|
|
|
printf("5/通过 Esc 键返回首页");
|
|
|
|
getch(); //按任意键返回主界面
|
|
|
|
getch(); //按任意键返回主界面
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*游戏规则 */
|
|
|
|
*游戏规则
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void rule()
|
|
|
|
void rule()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i,j = 1;
|
|
|
|
int i,j = 1;
|
|
|
@ -248,11 +252,12 @@ void rule()
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*游戏界面 */
|
|
|
|
void Game()
|
|
|
|
void Game()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gotoxy(FrameX+Frame_width-7,FrameY-2);
|
|
|
|
gotoxy(FrameX+Frame_width-7,FrameY-2);
|
|
|
|
color(11);
|
|
|
|
color(11);
|
|
|
|
printf("趣味俄罗斯方块");
|
|
|
|
printf("我的俄罗斯方块");
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+7);
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+7);
|
|
|
|
color(2);
|
|
|
|
color(2);
|
|
|
|
printf("***********");
|
|
|
|
printf("***********");
|
|
|
@ -268,34 +273,27 @@ void Game()
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+19);
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+19);
|
|
|
|
printf("空格:暂停游戏");
|
|
|
|
printf("空格:暂停游戏");
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+15);
|
|
|
|
gotoxy(FrameX+2*Frame_width+3,FrameY+15);
|
|
|
|
printf("Esc:退出游戏");
|
|
|
|
printf("Esc:返回首页");
|
|
|
|
gotoxy(FrameX,FrameY); //打印框角
|
|
|
|
|
|
|
|
color(6);
|
|
|
|
color(6);
|
|
|
|
printf("■");
|
|
|
|
for(i=0;i<=2*Frame_width-2;i+=2)
|
|
|
|
gotoxy(FrameX+2*Frame_width-2,FrameY);
|
|
|
|
|
|
|
|
printf("■");
|
|
|
|
|
|
|
|
gotoxy(FrameX,FrameY+Frame_height);
|
|
|
|
|
|
|
|
printf("■");
|
|
|
|
|
|
|
|
gotoxy(FrameX+2*Frame_width-2,FrameY+Frame_height);
|
|
|
|
|
|
|
|
printf("■");
|
|
|
|
|
|
|
|
for(i=2;i<2*Frame_width-2;i+=2)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gotoxy(FrameX+i,FrameY);
|
|
|
|
gotoxy(FrameX+i,FrameY);
|
|
|
|
printf("■"); //打印上横框
|
|
|
|
printf("■"); //打印上横框
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=2;i<2*Frame_width-2;i+=2)
|
|
|
|
for(i=0;i<=2*Frame_width-2;i+=2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gotoxy(FrameX+i,FrameY+Frame_height);
|
|
|
|
gotoxy(FrameX+i,FrameY+Frame_height);
|
|
|
|
printf("■"); //打印下横框
|
|
|
|
printf("■"); //打印下横框
|
|
|
|
a[FrameX+i][FrameY+Frame_height]=2; //标记下横框为游戏边框,防止方块出界
|
|
|
|
a[FrameX+i][FrameY+Frame_height]=2; //标记下横框为游戏边框,防止方块出界
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=1;i<Frame_height;i++)
|
|
|
|
for(i=0;i<=Frame_height;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gotoxy(FrameX,FrameY+i);
|
|
|
|
gotoxy(FrameX,FrameY+i);
|
|
|
|
printf("■"); //打印左边框
|
|
|
|
printf("■"); //打印左边框
|
|
|
|
a[FrameX][FrameY+i]=2; //标记左竖框为游戏边框,防止方块出界
|
|
|
|
a[FrameX][FrameY+i]=2; //标记左竖框为游戏边框,防止方块出界
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=1;i<Frame_height;i++)
|
|
|
|
for(i=0;i<=Frame_height;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gotoxy(FrameX+2*Frame_width-2,FrameY+i);
|
|
|
|
gotoxy(FrameX+2*Frame_width-2,FrameY+i);
|
|
|
|
printf("■"); //打印右边框
|
|
|
|
printf("■"); //打印右边框
|
|
|
@ -304,9 +302,7 @@ void Game()
|
|
|
|
printf("\n");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*制作方块*/
|
|
|
|
* 制作方块
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Make(struct Tetris *tetris)
|
|
|
|
void Make(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
a[tetris->x][tetris->y]=b[0]; //中心方块位置的图形状态
|
|
|
|
a[tetris->x][tetris->y]=b[0]; //中心方块位置的图形状态
|
|
|
@ -334,8 +330,8 @@ void Make(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color(13);
|
|
|
|
color(13);
|
|
|
|
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][tetris->y-2]=b[2];
|
|
|
|
a[tetris->x][tetris->y+2]=b[3];
|
|
|
|
a[tetris->x][tetris->y+1]=b[3];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -414,18 +410,18 @@ void Make(struct Tetris *tetris)
|
|
|
|
case 12: // 7
|
|
|
|
case 12: // 7
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color(1);
|
|
|
|
color(1);
|
|
|
|
a[tetris->x-2][tetris->y]=b[1];
|
|
|
|
a[tetris->x][tetris->y-1 ]=b[1];
|
|
|
|
a[tetris->x][tetris->y+1]=b[2];
|
|
|
|
a[tetris->x][tetris->y+1]=b[2];
|
|
|
|
a[tetris->x][tetris->y+2]=b[3];
|
|
|
|
a[tetris->x-2][tetris->y-1]=b[3];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 13: // 顺90 7
|
|
|
|
case 13: // 顺90 7
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color(2);
|
|
|
|
color(2);
|
|
|
|
a[tetris->x-2][tetris->y]=b[1];
|
|
|
|
a[tetris->x+2][tetris->y-1]=b[1];
|
|
|
|
a[tetris->x-4][tetris->y]=b[2];
|
|
|
|
a[tetris->x-2][tetris->y]=b[2];
|
|
|
|
a[tetris->x][tetris->y-1]=b[3];
|
|
|
|
a[tetris->x+2][tetris->y]=b[3];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -450,9 +446,9 @@ void Make(struct Tetris *tetris)
|
|
|
|
case 16: // 反 7
|
|
|
|
case 16: // 反 7
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color(9);
|
|
|
|
color(9);
|
|
|
|
a[tetris->x+2][tetris->y]=b[1];
|
|
|
|
a[tetris->x+2][tetris->y-1]=b[1];
|
|
|
|
a[tetris->x][tetris->y+1]=b[2];
|
|
|
|
a[tetris->x][tetris->y+1]=b[2];
|
|
|
|
a[tetris->x][tetris->y+2]=b[3];
|
|
|
|
a[tetris->x][tetris->y-1]=b[3];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -460,8 +456,8 @@ void Make(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color(10);
|
|
|
|
color(10);
|
|
|
|
a[tetris->x-2][tetris->y]=b[1];
|
|
|
|
a[tetris->x-2][tetris->y]=b[1];
|
|
|
|
a[tetris->x-4][tetris->y]=b[2];
|
|
|
|
a[tetris->x+2][tetris->y]=b[2];
|
|
|
|
a[tetris->x][tetris->y+1]=b[3];
|
|
|
|
a[tetris->x+2][tetris->y+1]=b[3];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -485,9 +481,7 @@ void Make(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*打印方块*/
|
|
|
|
*打印方块
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Print(struct Tetris *tetris)
|
|
|
|
void Print(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(i=0;i<4;i++) //让数组b[4]中的每个数都为1
|
|
|
|
for(i=0;i<4;i++) //让数组b[4]中的每个数都为1
|
|
|
@ -524,9 +518,7 @@ void Make(struct Tetris *tetris)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/* 开始游戏*/
|
|
|
|
* 开始游戏
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void play()
|
|
|
|
void play()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int n;
|
|
|
@ -536,6 +528,7 @@ void play()
|
|
|
|
tetris->speed=300;
|
|
|
|
tetris->speed=300;
|
|
|
|
tetris->score=0;
|
|
|
|
tetris->score=0;
|
|
|
|
tetris->level=1;
|
|
|
|
tetris->level=1;
|
|
|
|
|
|
|
|
HideCursor();
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Flag(tetris);
|
|
|
|
Flag(tetris);
|
|
|
@ -550,23 +543,23 @@ void play()
|
|
|
|
//按键操作
|
|
|
|
//按键操作
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
label:PrintTetris(tetris);
|
|
|
|
loop:Print(tetris);
|
|
|
|
Sleep(tetris->speed);
|
|
|
|
Sleep(tetris->speed);
|
|
|
|
CleanTetris(tetris);
|
|
|
|
Clean(tetris);
|
|
|
|
Temp1=tetris->x;
|
|
|
|
Temp1=tetris->x;
|
|
|
|
Temp2=tetris->flag; //记住当前俄罗斯方块序号
|
|
|
|
Temp2=tetris->flag; //记住当前俄罗斯方块序号
|
|
|
|
if(kbhit()) //判断是否有键盘输入,有则用ch↓接收
|
|
|
|
if(kbhit()) //判断是否有键盘输入,有则用ch↓接收
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ch=getch();
|
|
|
|
ch=getch();
|
|
|
|
if(ch==75) //按 ←键则向左动,中心横坐标减2
|
|
|
|
if(ch==75) //←键则向左动,中心横坐标减2
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->x-=2;
|
|
|
|
tetris->x-=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch==77) //按 →键则向右动,中心横坐标加2
|
|
|
|
if(ch==77) //→键则向右动,中心横坐标加2
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->x+=2;
|
|
|
|
tetris->x+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch==80) //按 ↓键则加速下落
|
|
|
|
if(ch==80) //↓键则加速下落
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(ifMove(tetris)!=0)
|
|
|
|
if(ifMove(tetris)!=0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -577,7 +570,7 @@ void play()
|
|
|
|
tetris->y=FrameY+Frame_height-2;
|
|
|
|
tetris->y=FrameY+Frame_height-2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch==72) //按 ↑键则变体,即当前方块顺时针转90度
|
|
|
|
if(ch==72) //↑键则变体,即当前方块顺时针转90度
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( tetris->flag>=2 && tetris->flag<=3 ) //如果是直线方块
|
|
|
|
if( tetris->flag>=2 && tetris->flag<=3 ) //如果是直线方块
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -620,33 +613,33 @@ void play()
|
|
|
|
ch=getch();
|
|
|
|
ch=getch();
|
|
|
|
if(ch == 32)
|
|
|
|
if(ch == 32)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
goto label;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch == 27)
|
|
|
|
if(ch == 27) //esc
|
|
|
|
{
|
|
|
|
{
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
memset(a,0,6400*sizeof(int)); //初始化a数组
|
|
|
|
memset(a,0,6400*sizeof(int)); //初始化a数组
|
|
|
|
welcome();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ifMove(tetris)==0) //如果不可动,上面操作无效
|
|
|
|
if(ifMove(tetris)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->x=Temp1;
|
|
|
|
tetris->x=Temp1;
|
|
|
|
tetris->flag=Temp2;
|
|
|
|
tetris->flag=Temp2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //如果可动,执行操作
|
|
|
|
else //如果可动,执行操作
|
|
|
|
{
|
|
|
|
{
|
|
|
|
goto label;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tetris->y++; //如果没有操作指令,方块向下移动
|
|
|
|
tetris->y++;
|
|
|
|
if(ifMove(tetris)==0) //如果向下移动且不可动,方块放在此处
|
|
|
|
if(ifMove(tetris)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->y--;
|
|
|
|
tetris->y--;
|
|
|
|
PrintTetris(tetris);
|
|
|
|
Print(tetris);
|
|
|
|
Del_Fullline(tetris);
|
|
|
|
Full(tetris);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -658,25 +651,25 @@ for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
gotoxy(29,7);
|
|
|
|
gotoxy(29,7);
|
|
|
|
printf("\n");
|
|
|
|
printf("\n");
|
|
|
|
color(6);
|
|
|
|
color(6);
|
|
|
|
printf(" @=================================|||||======================================@ \n");
|
|
|
|
printf(" @=================================|||||======================================@ \n");
|
|
|
|
printf("|| ■■ ■ ■ ■ ■■■■■ || \n");
|
|
|
|
printf(" || ■■ ■ ■ ■ ■■■■■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■■ ■■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■■ ■■ ■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■ ■■■ ■ ■ ■ ■■ ■ ■■■■■ || \n");
|
|
|
|
printf(" || ■ ■■■ ■ ■ ■ ■■ ■ ■■■■■ || \n");
|
|
|
|
printf("|| ■ ■ ■■■■■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■■■■■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■■ ■ ■ ■ ■ ■■■■■ || \n");
|
|
|
|
printf(" || ■■ ■ ■ ■ ■ ■■■■■ || \n");
|
|
|
|
printf("|* *| \n");
|
|
|
|
printf(" |* *| \n");
|
|
|
|
color(4);
|
|
|
|
color(4);
|
|
|
|
printf("|* *| \n");
|
|
|
|
printf(" |* *| \n");
|
|
|
|
printf("|| ■■ ■ ■ ■■■■■ ■■■■ || \n");
|
|
|
|
printf(" || ■■ ■ ■ ■■■■■ ■■■■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■■■■■ ■■■■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■■■■■ ■■■■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf(" || ■ ■ ■ ■ ■ ■ ■ || \n");
|
|
|
|
printf("|| ■■ ■ ■■■■■ ■ ■ || \n");
|
|
|
|
printf(" || ■■ ■ ■■■■■ ■ ■ || \n");
|
|
|
|
printf(" @============================================================================@ \n");
|
|
|
|
printf(" @============================================================================@ \n");
|
|
|
|
if(MessageBox(NULL,"游戏结束.\n要重新来一局么?","Game Over",MB_YESNO|MB_ICONQUESTION)==IDYES)
|
|
|
|
if(MessageBox(NULL,"游戏结束.\n要重新来一局么?","Game Over",MB_YESNO|MB_ICONQUESTION)==IDYES)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
@ -694,9 +687,8 @@ for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
Clean(tetris);
|
|
|
|
Clean(tetris);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 清除痕迹
|
|
|
|
/*清除痕迹*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Clean(struct Tetris *tetris)
|
|
|
|
void Clean(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(i=0;i<4;i++) //数组b[4]中有4个元素,循环这4个元素,让每个元素的值都为0
|
|
|
|
for(i=0;i<4;i++) //数组b[4]中有4个元素,循环这4个元素,让每个元素的值都为0
|
|
|
@ -716,3 +708,217 @@ void Clean(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 随机产生俄罗斯方块*/
|
|
|
|
|
|
|
|
void Flag(struct Tetris *tetris)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tetris->number++; //记住产生方块的个数
|
|
|
|
|
|
|
|
srand(time(NULL)); //初始化随机数
|
|
|
|
|
|
|
|
if(tetris->number==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tetris->flag = rand()%19+1; //记住第一个方块的序号
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tetris->next = rand()%19+1; //记住下一个方块的序号
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*判断方块是否可以移动 */
|
|
|
|
|
|
|
|
int ifMove(struct Tetris *tetris)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(a[tetris->x][tetris->y]!=0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
|
|
|
( //田
|
|
|
|
|
|
|
|
tetris->flag==1 &&
|
|
|
|
|
|
|
|
( a[tetris->x][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //一
|
|
|
|
|
|
|
|
tetris->flag==2 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y]==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+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-2]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //T
|
|
|
|
|
|
|
|
tetris->flag==4 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x-2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺90 T
|
|
|
|
|
|
|
|
tetris->flag==5 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺180 T
|
|
|
|
|
|
|
|
tetris->flag==6 &&
|
|
|
|
|
|
|
|
( a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x-2][tetris->y]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺270 T
|
|
|
|
|
|
|
|
tetris->flag==7 &&
|
|
|
|
|
|
|
|
( a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //Z
|
|
|
|
|
|
|
|
tetris->flag==8 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺90 Z
|
|
|
|
|
|
|
|
tetris->flag==9 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //反 Z
|
|
|
|
|
|
|
|
tetris->flag==10 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x-2][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺90 反Z
|
|
|
|
|
|
|
|
tetris->flag==11 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //7
|
|
|
|
|
|
|
|
tetris->flag==12 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺90 7
|
|
|
|
|
|
|
|
tetris->flag==13 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y-1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺180 7
|
|
|
|
|
|
|
|
tetris->flag==14 &&
|
|
|
|
|
|
|
|
( a[tetris->x][tetris->y-2]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+2][tetris->y]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺270 7
|
|
|
|
|
|
|
|
tetris->flag==15 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+4][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( // 反 7
|
|
|
|
|
|
|
|
tetris->flag==16 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( // 顺90 反7
|
|
|
|
|
|
|
|
tetris->flag==17 &&
|
|
|
|
|
|
|
|
( a[tetris->x-2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x-4][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y+1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺180 反7
|
|
|
|
|
|
|
|
tetris->flag==18 &&
|
|
|
|
|
|
|
|
( a[tetris->x][tetris->y-2]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0&&
|
|
|
|
|
|
|
|
a[tetris->x-2][tetris->y]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
( //顺270 反7
|
|
|
|
|
|
|
|
tetris->flag==19 &&
|
|
|
|
|
|
|
|
( a[tetris->x+2][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x+4][tetris->y]==0&&
|
|
|
|
|
|
|
|
a[tetris->x][tetris->y-1]==0)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*判断方块是否满行 */
|
|
|
|
|
|
|
|
void Full(struct Tetris *tetris)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int k,del_rows=0;
|
|
|
|
|
|
|
|
for(j=FrameY+Frame_height-1;j>=FrameY+1;j--)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
k=0;
|
|
|
|
|
|
|
|
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(a[i][j]==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
k++;
|
|
|
|
|
|
|
|
if(k==Frame_width-2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(k=FrameX+2;k<FrameX+2*Frame_width-2;k+=2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
a[k][j]=0;
|
|
|
|
|
|
|
|
gotoxy(k,j);
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(k=j-1;k>FrameY;k--)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(a[i][k]==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
a[i][k]=0;
|
|
|
|
|
|
|
|
gotoxy(i,k);
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
a[i][k+1]=1;
|
|
|
|
|
|
|
|
gotoxy(i,k+1);
|
|
|
|
|
|
|
|
printf("■");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
j++; //方块下移后,重新判断删除行是否满行
|
|
|
|
|
|
|
|
del_rows++; //记录删除方块的行数
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tetris->score+=100*del_rows;
|
|
|
|
|
|
|
|
if( del_rows>0 && ( tetris->score%1000==0 || tetris->score/1000>tetris->level-1 ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tetris->speed-=20;
|
|
|
|
|
|
|
|
tetris->level++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|