|
|
@ -1,9 +1,8 @@
|
|
|
|
/****头文件****/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <time.h>
|
|
|
|
/****宏定义****/
|
|
|
|
|
|
|
|
#define FrameX 13 //游戏窗口左上角的X轴坐标为13
|
|
|
|
#define FrameX 13 //游戏窗口左上角的X轴坐标为13
|
|
|
|
#define FrameY 3 //游戏窗口左上角的Y轴坐标为3
|
|
|
|
#define FrameY 3 //游戏窗口左上角的Y轴坐标为3
|
|
|
|
#define Frame_height 20 //游戏窗口的高度为20
|
|
|
|
#define Frame_height 20 //游戏窗口的高度为20
|
|
|
@ -25,18 +24,18 @@ struct Tetris
|
|
|
|
} ;
|
|
|
|
} ;
|
|
|
|
HANDLE hOut; //控制台句柄
|
|
|
|
HANDLE hOut; //控制台句柄
|
|
|
|
/****函数声明****/
|
|
|
|
/****函数声明****/
|
|
|
|
void HideCursor();
|
|
|
|
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(); //游戏界面
|
|
|
|
void play(); //开始游戏
|
|
|
|
void Play(); //开始游戏
|
|
|
|
void explation(); //操作说明
|
|
|
|
void explation(); //操作说明
|
|
|
|
void rule(); //游戏规则
|
|
|
|
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不动
|
|
|
|
int If_move(struct Tetris *); //判断是否能移动,1动;0不动
|
|
|
|
void Flag(struct Tetris *); //随机产生方块
|
|
|
|
void Shui_Ji(struct Tetris *); //随机产生方块
|
|
|
|
void Full(struct Tetris *); // 判断方块是否满行
|
|
|
|
void Full(struct Tetris *); // 判断方块是否满行
|
|
|
|
|
|
|
|
|
|
|
|
/*隐藏控制台的光标*/
|
|
|
|
/*隐藏控制台的光标*/
|
|
|
@ -61,8 +60,6 @@ void gotoxy(int x,int y)
|
|
|
|
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
|
|
|
|
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*首页 */
|
|
|
|
/*首页 */
|
|
|
|
int main()
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -169,7 +166,7 @@ int main()
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
Game();
|
|
|
|
Game();
|
|
|
|
play();
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
explation();
|
|
|
|
explation();
|
|
|
@ -253,6 +250,7 @@ void rule()
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*游戏界面 */
|
|
|
|
/*游戏界面 */
|
|
|
|
void Game()
|
|
|
|
void Game()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -520,7 +518,7 @@ void Make(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 开始游戏*/
|
|
|
|
/* 开始游戏*/
|
|
|
|
void play()
|
|
|
|
void Play()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int n;
|
|
|
|
struct Tetris t,*tetris=&t;
|
|
|
|
struct Tetris t,*tetris=&t;
|
|
|
@ -532,7 +530,7 @@ void play()
|
|
|
|
HideCursor();
|
|
|
|
HideCursor();
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Flag(tetris);
|
|
|
|
Shui_Ji(tetris);
|
|
|
|
Temp=tetris->flag;
|
|
|
|
Temp=tetris->flag;
|
|
|
|
tetris->x=FrameX+2*Frame_width+6;
|
|
|
|
tetris->x=FrameX+2*Frame_width+6;
|
|
|
|
tetris->y=FrameY+10;
|
|
|
|
tetris->y=FrameY+10;
|
|
|
@ -545,7 +543,7 @@ void play()
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
loop:Print(tetris);
|
|
|
|
loop:Print(tetris);
|
|
|
|
Sleep(tetris->speed);
|
|
|
|
Sleep(tetris->speed); //延时
|
|
|
|
Clean(tetris);
|
|
|
|
Clean(tetris);
|
|
|
|
Temp1=tetris->x;
|
|
|
|
Temp1=tetris->x;
|
|
|
|
Temp2=tetris->flag; //记住当前俄罗斯方块序号
|
|
|
|
Temp2=tetris->flag; //记住当前俄罗斯方块序号
|
|
|
@ -562,11 +560,11 @@ void play()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch==80) //↓键则加速下落
|
|
|
|
if(ch==80) //↓键则加速下落
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(ifMove(tetris)!=0)
|
|
|
|
if(If_move(tetris)!=0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->y+=2;
|
|
|
|
tetris->y+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ifMove(tetris)==0)
|
|
|
|
if(If_move(tetris)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->y=FrameY+Frame_height-2;
|
|
|
|
tetris->y=FrameY+Frame_height-2;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -579,30 +577,42 @@ void play()
|
|
|
|
tetris->flag%=2;
|
|
|
|
tetris->flag%=2;
|
|
|
|
tetris->flag+=2;
|
|
|
|
tetris->flag+=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( tetris->flag>=4 && tetris->flag<=7 ) //如果是T字方块
|
|
|
|
if( tetris->flag>=4 && tetris->flag<=7 ) //如果是T字方块
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag+=4;
|
|
|
|
tetris->flag+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( tetris->flag>=8 && tetris->flag<=11 ) //如果是Z字方块
|
|
|
|
|
|
|
|
|
|
|
|
if( tetris->flag>=8 && tetris->flag<=9 ) //如果是Z字方块
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag%=2;
|
|
|
|
tetris->flag+=8;
|
|
|
|
tetris->flag+=8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( tetris->flag>=10 && tetris->flag<=11 ) //如果是反Z字方块
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tetris->flag++;
|
|
|
|
|
|
|
|
tetris->flag%=2;
|
|
|
|
|
|
|
|
tetris->flag+=10;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( tetris->flag>=12 && tetris->flag<=15 ) //如果是7字方块
|
|
|
|
if( tetris->flag>=12 && tetris->flag<=15 ) //如果是7字方块
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag+=12;
|
|
|
|
tetris->flag+=12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( tetris->flag>=16 && tetris->flag<=19 ) //如果是反7字方块
|
|
|
|
if( tetris->flag>=16 && tetris->flag<=19 ) //如果是反7字方块
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag++;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag%=4;
|
|
|
|
tetris->flag+=16;
|
|
|
|
tetris->flag+=16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ch == 32) //按空格键,暂停
|
|
|
|
if(ch == 32) //按空格键,暂停
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -625,7 +635,7 @@ void play()
|
|
|
|
memset(a,0,6400*sizeof(int)); //初始化a数组
|
|
|
|
memset(a,0,6400*sizeof(int)); //初始化a数组
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ifMove(tetris)==0)
|
|
|
|
if(If_move(tetris)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->x=Temp1;
|
|
|
|
tetris->x=Temp1;
|
|
|
|
tetris->flag=Temp2;
|
|
|
|
tetris->flag=Temp2;
|
|
|
@ -636,7 +646,7 @@ void play()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tetris->y++;
|
|
|
|
tetris->y++;
|
|
|
|
if(ifMove(tetris)==0)
|
|
|
|
if(If_move(tetris)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->y--;
|
|
|
|
tetris->y--;
|
|
|
|
Print(tetris);
|
|
|
|
Print(tetris);
|
|
|
@ -676,7 +686,7 @@ for(i=tetris->y-2;i<tetris->y+2;i++)
|
|
|
|
system("cls");
|
|
|
|
system("cls");
|
|
|
|
memset(a,0,6400*sizeof(int));
|
|
|
|
memset(a,0,6400*sizeof(int));
|
|
|
|
Game();
|
|
|
|
Game();
|
|
|
|
play();
|
|
|
|
Play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
@ -711,7 +721,7 @@ void Clean(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 随机产生俄罗斯方块*/
|
|
|
|
/* 随机产生俄罗斯方块*/
|
|
|
|
void Flag(struct Tetris *tetris)
|
|
|
|
void Shui_Ji(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tetris->number++; //记住产生方块的个数
|
|
|
|
tetris->number++; //记住产生方块的个数
|
|
|
|
srand(time(NULL)); //初始化随机数
|
|
|
|
srand(time(NULL)); //初始化随机数
|
|
|
@ -723,7 +733,7 @@ void Flag(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*判断方块是否可以移动 */
|
|
|
|
/*判断方块是否可以移动 */
|
|
|
|
int ifMove(struct Tetris *tetris)
|
|
|
|
int If_move(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(a[tetris->x][tetris->y]!=0)
|
|
|
|
if(a[tetris->x][tetris->y]!=0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -873,6 +883,7 @@ int ifMove(struct Tetris *tetris)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*判断方块是否满行 */
|
|
|
|
/*判断方块是否满行 */
|
|
|
|
void Full(struct Tetris *tetris)
|
|
|
|
void Full(struct Tetris *tetris)
|
|
|
|
{
|
|
|
|
{
|