#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#define ZL 4 //坐标增量, 不使游戏窗口靠边
#define W 36 //游戏窗口的宽度
#define H 20 //游戏窗口的高度
int i,j,Ta,Tb,Tc; // Ta,Tb,Tc用于记住和转换方块变量的值
int a[60][60]={0}; //标记游戏屏幕各坐标点:0,1,2分别为空、方块、边框
int b[4]; //标记4个"口"方块:1有,0无,类似开关
int x,y, level,score,speed; //方块中心位置的x,y坐标,游戏等级、得分和游戏速度
int flag,next; //当前要操作的方块类型序号,下一个方块类型序号
void gtxy(int m, int n); //以下声明要用到的自编函数
void setColor(unsigned short p, unsigned short q); //设定显示颜色
void gflag( ); //获得下一方块类型的序号
void csh( ); //初始化界面
void start( ); //开始部分
void prfk ( ); //打印方块
void clfk( ); //清除方块
void mkfk( ); //制作方块
void keyD( ); //按键操作
int ifmov( ); //判断能否移动
void clHA( ); //清除满行的方块
void clNEXT( ); //清除边框外的NEXT方块
int main( )
{ csh( );
while(1)
{ start( );
while(1)
{ setColor(5, 0);
prfk( ); Sleep(speed); clfk( );
Tb=x;Tc=flag; //临存当前x坐标和序号,以备撤销操作
keyD( );
y++; //方块向下移动
if (ifmov( )==0) { y--; setColor(2, 0);prfk( ); clHA( ); break;} //不可动时的操作
}
for(i=y-2;i<y+2;i++){ if (i==ZL) { j=0; } } //方块触到框顶
if (j==0) { system("cls");gtxy(10,10); setColor(6, 0);
printf("游戏结束!"); getch(); break; }
clNEXT( );
}
return 0;
}
void gtxy(int m, int n) //控制光标移动
{COORD pos; //定义变量
pos.X = m; //横坐标
pos.Y = n; //纵坐标
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); //获得显示器句柄
}
void setColor(unsigned short ForeColor = 7, unsigned short BackGroundColor = 0)
{ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, ForeColor + BackGroundColor * 0x10);
}
void csh( ) //初始化界面
{gtxy(ZL+W/2-5,ZL-2); setColor(10, 0); printf("俄罗斯方块"); //打印游戏名称
gtxy(ZL+W+3,ZL+7); setColor(5, 0);printf("******* NEXT:"); //打印菜单信息
gtxy(ZL+W+3,ZL+13); setColor(5, 0);printf("************");
gtxy(ZL+W+3,ZL+15); setColor(9, 0);p