#include <graphics.h>
#include<conio.h>
#include<time.h>
#define WIDTH 10
#define HEIGHT 22
#define UNIT 30
enum CMD
{
CMD_ROTATE,
CMD_LEFT,CMD_RIGHT,CMD_DOWN,
CMD_SINK,
CMD_QUIT
};
enum DRAW
{
SHOW,
CLEAR,
FIX,
};
struct BLOCK
{
WORD dir[4];
OLORREF color;
};
BIOCK g_Blocks[7]={{0x0F00,0x4444,0x0F00,0x4444,RED},
{0x0660,0x0660,0x0660,0x0660,BLUE},
{0x4460,0x02E0,0x0622,0x0740,MAGENTA},
{0x2260,0x0E20,0x0644,0x0470,YELLOW},
{0x0C60,0x2640,0x0C60,0x2640,CYAN},
{0x0360,0x4620,0x0360,0x4620,GREEN},
{0x4E00,0x4C40,0x0E40,0x4640,BROWN}};
struct BLOCKINFO
{
byte id;
char x,y;
byte dir:2;
g_CurBlock,g_NextBlock;
BYTE g_World[WIDTH][HEIGHT]={0};
void Init();
void Quit();
void NewGame();
void GameOver();
CMD GetCmd();
void DispatchCmd(CMD_cmd);
void NewBlock();
bool CheckBlock(BLOCKINFO_block);
void DrawUnit(int x,int y,COLORREF c,DRAW_draw);
void DrawBlock(BLOCKINFO_block,DRAW_draw=SHOW);
void OnRotate();
void OnLeft();
void OnRight();
void OnDown();
void OnSink();
void main()
{
Init();
CMD c;
while (true)
{
c=GetCmd();
DispatchCmd(c);
if(c==CMD_QUIT)
{
HWND wnd=GetHWnd();
if(MessageBox(wnd,_T("您要退出游戏吗?"),_T("提醒"),
MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
Quit();
}
}
}
void Init()
{
initgraph(640,480);
srand((unsigned)time(NULL));
setbkmode(TRANSPARENT);
settextstyle(14,0,_T("宋体"));
outtextxy(20,330,_T("操作说明"));
outtextxy(20,350,_T("上:旋转"));
outtextxy(20,370,_T("左:左移"));
outtextxy(20,390,_T("右:右移"));
outtextxy(20,410,_T("下:下移"));
outtextxy(20,430,_T("空格:沉底"));
outtextxy(20,450,_T("ESC:退出"));