|
|
|
@ -7,6 +7,7 @@
|
|
|
|
|
#define FrameY 3 //游戏窗口左上角的Y轴坐标为3
|
|
|
|
|
#define Frame_height 20 //游戏窗口的高度为20
|
|
|
|
|
#define Frame_width 18 //游戏窗口的宽度为18
|
|
|
|
|
|
|
|
|
|
/****全局变量****/
|
|
|
|
|
int i,j,Temp,Temp1,Temp2; //Temp,Temp1,Temp2用于记住和转换方块变量的值
|
|
|
|
|
int a[80][80]={0}; //标记游戏屏幕的图案:2,1,0 分别表示该位置为游戏边框、方块、无图案;初始化为无图案
|
|
|
|
@ -22,6 +23,12 @@ struct Tetris
|
|
|
|
|
int score; //游戏的分数
|
|
|
|
|
int level; //游戏的等级
|
|
|
|
|
} ;
|
|
|
|
|
struct jilu_info
|
|
|
|
|
{
|
|
|
|
|
int first;
|
|
|
|
|
int second;
|
|
|
|
|
int third;
|
|
|
|
|
}jilu={0,0,0};
|
|
|
|
|
HANDLE hOut; //控制台句柄
|
|
|
|
|
/****函数声明****/
|
|
|
|
|
void HideCursor(); //隐藏光标
|
|
|
|
@ -31,13 +38,15 @@ void Game(); //
|
|
|
|
|
void Play(); //开始游戏
|
|
|
|
|
void explation(); //操作说明
|
|
|
|
|
void rule(); //游戏规则
|
|
|
|
|
void Ji_Lu(); //游戏记录
|
|
|
|
|
void Make(struct Tetris *); //制作方块
|
|
|
|
|
void Print(struct Tetris *); //打印方块
|
|
|
|
|
void Clean(struct Tetris *); //清除痕迹
|
|
|
|
|
int If_move(struct Tetris *); //判断是否能移动,1动;0不动
|
|
|
|
|
void Shui_Ji(struct Tetris *); //随机产生方块
|
|
|
|
|
void Full(struct Tetris *); // 判断方块是否满行
|
|
|
|
|
|
|
|
|
|
void tihuan(int x);
|
|
|
|
|
void panduan(int x);
|
|
|
|
|
/*隐藏控制台的光标*/
|
|
|
|
|
void HideCursor()
|
|
|
|
|
{
|
|
|
|
@ -63,6 +72,7 @@ void gotoxy(int x,int y)
|
|
|
|
|
/*首页 */
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
HideCursor();
|
|
|
|
|
/*图案*/
|
|
|
|
|
color(11);
|
|
|
|
@ -155,12 +165,14 @@ int main()
|
|
|
|
|
gotoxy(25,17);
|
|
|
|
|
printf("3.游戏规则");
|
|
|
|
|
gotoxy(45,17);
|
|
|
|
|
printf("4.退出");
|
|
|
|
|
printf("4.游戏记录");
|
|
|
|
|
gotoxy(21,22);
|
|
|
|
|
color(3);
|
|
|
|
|
printf("按其他键退出");
|
|
|
|
|
gotoxy(21,24);
|
|
|
|
|
printf("请选择[1 2 3 4]:[ ]\b\b");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
|
|
|
|
|
printf("\a\a\a\a");
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
@ -175,6 +187,9 @@ int main()
|
|
|
|
|
rule();
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
Ji_Lu();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
@ -251,6 +266,55 @@ void rule()
|
|
|
|
|
main();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*记录*/
|
|
|
|
|
void Ji_Lu()
|
|
|
|
|
{
|
|
|
|
|
int i,j = 1;
|
|
|
|
|
system("cls");
|
|
|
|
|
color(6);
|
|
|
|
|
gotoxy(30,3);
|
|
|
|
|
printf("游 戏 纪 录");
|
|
|
|
|
for (i = 6; i <= 18; i++)
|
|
|
|
|
{
|
|
|
|
|
for (j = 12; j <= 70; j++)
|
|
|
|
|
{
|
|
|
|
|
gotoxy(j, i);
|
|
|
|
|
if (i == 6 || i == 18) printf("=");
|
|
|
|
|
else if (j == 12 || j == 69) printf("||");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("f1.txt","w");
|
|
|
|
|
fscanf(fp,"%d%d%d",&jilu.first,&jilu.second,&jilu.third);
|
|
|
|
|
color(12);
|
|
|
|
|
gotoxy(30,9);
|
|
|
|
|
printf("第一名: %d分",jilu.first);
|
|
|
|
|
color(10);
|
|
|
|
|
gotoxy(30,12);
|
|
|
|
|
printf("第二名: %d分",jilu.second);
|
|
|
|
|
color(11);
|
|
|
|
|
gotoxy(30,15);
|
|
|
|
|
printf("第三名: %d分",jilu.third);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
getch(); //按任意键返回主界面
|
|
|
|
|
system("cls");
|
|
|
|
|
main();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*判断*/
|
|
|
|
|
void panduan(int x)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("f1.txt","w");
|
|
|
|
|
fscanf(fp,"%d%d%d",&jilu.first,&jilu.second,&jilu.third);
|
|
|
|
|
if(x>jilu.third)
|
|
|
|
|
{
|
|
|
|
|
printf("你破了一个记录哦!!!");
|
|
|
|
|
tihuan(x);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*游戏界面 */
|
|
|
|
|
void Game()
|
|
|
|
|
{
|
|
|
|
@ -657,7 +721,7 @@ void Play()
|
|
|
|
|
for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
|
{
|
|
|
|
|
if(i==FrameY)
|
|
|
|
|
{
|
|
|
|
|
{ panduan(tetris->score);
|
|
|
|
|
system("cls");
|
|
|
|
|
gotoxy(29,7);
|
|
|
|
|
printf("\n");
|
|
|
|
@ -685,8 +749,7 @@ for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
memset(a,0,6400*sizeof(int));
|
|
|
|
|
Game();
|
|
|
|
|
Play();
|
|
|
|
|
main();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
exit(0);
|
|
|
|
@ -699,6 +762,24 @@ for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tihuan(int x)
|
|
|
|
|
{
|
|
|
|
|
if(x>jilu.first)
|
|
|
|
|
{
|
|
|
|
|
jilu.third =jilu.second;
|
|
|
|
|
jilu.second =jilu.first;
|
|
|
|
|
jilu.first =x;
|
|
|
|
|
}
|
|
|
|
|
else if(x<jilu.first&&x>jilu.second )
|
|
|
|
|
{
|
|
|
|
|
jilu.third =jilu.second ;
|
|
|
|
|
jilu.second =x;
|
|
|
|
|
}
|
|
|
|
|
else if(x<jilu.second&&x>jilu.third )
|
|
|
|
|
{
|
|
|
|
|
jilu.third =x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*清除痕迹*/
|
|
|
|
|
void Clean(struct Tetris *tetris)
|
|
|
|
|
{
|
|
|
|
@ -716,6 +797,7 @@ void Clean(struct Tetris *tetris)
|
|
|
|
|
gotoxy(i,j);
|
|
|
|
|
printf(" "); //清除方块
|
|
|
|
|
}
|
|
|
|
|
printf("\a");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|