📄 tetris.c
字号:
/*****************************************************/
/* 方块游戏 */
/* 环境:ADS1.2 */
/* 作者:Liuwei */
/* E-mail:liuweiele@163.com */
/* QQ:304466616 */
/* 2009年02月21日 */
/*****************************************************/
/*****************************************************/
#include "Include.h"
#include "Tetris.h"
/*============================================================================*/
/*============================================================================*/
struct BLOCK
{
U16 Index;
U16 Rotate;
};
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
#define xGrids 30
#define yGrids 35
static U8 TetrisMap[xGrids*yGrids];
static U32 BlockCount,UserPoint;
static struct BLOCK CurBlock,NextBlock;
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
char BlockTab[]={
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
/////////////////0
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,1,1,
0,0,0,1,
0,0,0,1,
1,1,1,1,
0,0,0,0,
1,1,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
1,1,1,1,
1,0,0,0,
1,0,0,0,
////////////////1
0,0,1,0,
0,0,1,0,
0,0,1,0,
1,1,1,0,
0,0,0,0,
1,1,1,1,
0,0,0,1,
0,0,0,1,
0,1,1,1,
0,1,0,0,
0,1,0,0,
0,1,0,0,
1,0,0,0,
1,0,0,0,
1,1,1,1,
0,0,0,0,
///////////////////2
0,0,0,0,
0,1,0,0,
0,1,1,0,
0,0,1,0,
0,0,0,0,
0,0,1,1,
0,1,1,0,
0,0,0,0,
0,1,0,0,
0,1,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
1,1,0,0,
0,0,0,0,
///////////////////3
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,1,0,
0,0,1,1,
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,0,0,0,
1,1,0,0,
0,1,1,0,
0,0,0,0,
////////////////////4
0,0,0,0,
0,0,0,0,
1,1,1,1,
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
1,1,1,1,
0,0,0,0,
0,0,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
/////////////////////5
0,0,0,0,
0,1,0,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,0,1,0,
0,0,0,0,
/////////////////////6
0,0,0,0,
0,1,0,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,0,1,0,
0,1,1,1,
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0,
/////////////////////7
0,0,0,0,
0,1,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,0,0,
1,1,1,0,
0,1,0,0,
/////////////////////8
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,1,0,0,
0,1,0,0,
0,0,0,0,
/////////////////////9
0,0,0,0,
1,1,1,1,
1,0,0,1,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,1,0,0,
0,1,1,0,
0,0,0,0,
1,0,0,1,
1,1,1,1,
0,0,0,0,
0,1,1,0,
0,0,1,0,
0,0,1,0,
0,1,1,0,
/////////////////////10
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,1,1,0,
0,0,0,0,
1,1,1,1,
0,0,0,1,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,0,0,0,
1,0,0,0,
1,1,1,1,
0,0,0,0,
/////////////////////11
0,0,0,0,
0,1,0,0,
0,1,1,1,
0,1,0,0,
0,0,1,0,
0,0,1,0,
0,1,1,1,
0,0,0,0,
0,0,1,0,
1,1,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
1,1,1,0,
0,1,0,0,
0,1,0,0,
/////////////////////12
0,1,0,0,
0,1,0,0,
0,1,1,1,
0,0,0,0,
0,0,1,0,
0,0,1,0,
1,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,1,
0,1,0,0,
0,1,0,0,
0,0,0,0,
1,1,1,0,
0,0,1,0,
0,0,1,0,
////////////////////13
0,0,0,0,
1,1,1,0,
1,0,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,1,1,0,
0,0,0,0,
0,1,0,1,
0,1,1,1,
0,0,0,0,
0,1,1,0,
0,0,1,0,
0,1,1,0,
0,0,0,0,
/////////////////////14
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,1,1,0,
0,0,0,0,
0,1,1,1,
0,0,0,1,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0,
0,0,0,0,
1,0,0,0,
1,1,1,0,
0,0,0,0,
///////////////////////15
};
/*============================================================================*/
//
void DrawBlockDot(int x,int y,int Color)
{
GUI_Rectangle(x,y,8,8,Color);
GUI_FillRectangle(x+2,y+2,8-4,8-4,Color);
}
/*============================================================================*/
void SetMapDot(U8 *pBuf,int xgrd,int ygrd)
{
pBuf[(ygrd*xGrids)+xgrd]=1;
}
/*============================================================================*/
void ClrMapDot(U8 *pBuf,int xgrd,int ygrd)
{
pBuf[(ygrd*xGrids)+xgrd]=0;
}
/*============================================================================*/
int GetMapDot(U8 *pBuf,int xgrd,int ygrd)
{
if(xgrd<0) xgrd=0;
return pBuf[(ygrd*xGrids)+xgrd];
}
/*============================================================================*/
void DrawBlock(int x,int y,int Color,int BlockID)
{
int xx,yy,i,offset;
////
offset=BlockID*(16);
xx =x;
yy =y;
for(i=0;i<16;i++)
{
xx=(i%4)*7;
yy=(i/4)*7;
if(BlockTab[offset+i])
{
DrawBlockDot(x+xx,y+yy,Color);
}
}
}
/*============================================================================*/
//检查在指定的位置是否可以放下该方块
int CheckBlockInTray(U8 *pBuf,int xgrd,int ygrd,int BlockID)
{
int offset,xx,yy;
/////
//if(xgrd<0) xgrd=0;
//if(ygrd<0) ygrd=0;
////
offset=BlockID*16;
for(yy=0;yy<4;yy++)
{
for(xx=0;xx<4;xx++)
{
if(BlockTab[offset+(yy*4)+xx])
{
if(GetMapDot(pBuf,xgrd+xx,ygrd+yy)) return 0; //该格已占用
}
}
}
return 1;
}
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
//在托盘里指定位置画一个方块.
int DrawBlockInMap(U8 *pBuf,int xgrd,int ygrd,int BlockID)
{
int offset,xx,yy;
/////
// if(!CheckBlockInTray(pBuf,xgrd,ygrd,BlockID)) return 0;
////
offset=BlockID*16;
for(yy=0;yy<4;yy++)
{
for(xx=0;xx<4;xx++)
{
if(BlockTab[offset+(yy*4)+xx])
{
SetMapDot(pBuf,xgrd+xx,ygrd+yy);
}
}
}
}
/*============================================================================*/
//清除一行方块.
void ClrMapLine(U8 *pBuf,int Line)
{
int xx,yy;
////
yy=Line;
for(xx=0;xx<xGrids;xx++)
{
if(xx<4) continue;
if(xx>(xGrids-4-1)) continue;
ClrMapDot(pBuf,xx,yy);
}
}
/*============================================================================*/
//读一行
void GetMapLine(U8 *pMap,int Line,U8 *pBuf)
{
int i,xx,yy;
////
i=0;
yy=Line;
for(xx=4;xx<(xGrids-4);xx++)
{
pBuf[i++]=GetMapDot(pMap,xx,yy);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -