#define BLOCK_COUNT 5
#define BLOCK_WIDTH 5
#define BLOCK_HEIGHT 5
#define UNIT_SIZE 20 //小砖块的宽度和高度
int color[BLOCK_COUNT] = {
GREEN,CYAN,MAGENTA,BROWN,YELLOW
};
int NextIndex = -1;
int block[BLOCK_COUNT * 4][BLOCK_HEIGHT][BLOCK_WIDTH] = {
// | 形方块
{ 0,0,0,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,0,0,0,
0,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,0,0,0,
0,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
// L 形方块
{ 0,0,0,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,1,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,0,0,0,
0,1,1,1,0,
0,1,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,1,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,0,1,0,
0,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
// 田 形方块
{ 0,0,0,0,0,
0,1,1,0,0,
0,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,1,1,0,0,
0,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,1,1,0,0,
0,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,1,1,0,0,
0,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0 },
// T 形方块
{ 0,0,0,0,0,
0,1,1,1,0,
0,0,1,0,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,0,1,0,
0,0,1,1,0,
0,0,0,1,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,1,0,0,
0,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,1,0,0,0,
0,1,1,0,0,
0,1,0,0,0,
0,0,0,0,0 },
// Z 形方块
{ 0,0,0,0,0,
0,1,1,0,0,
0,0,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,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,0,0,0,
0,1,1,0,0,
0,0,1,1,0,
0,0,0,0,0,
0,0,0,0,0 },
{ 0,0,0,0,0,
0,0,1,0,0,
0,1,1,0,0,
0,1,0,0,0,
0,0,0,0,0 },
};
void clearBlock(int x, int y) {
setcolor(BLACK);
setfont(23, 0, "楷体");
for (int i = 0; i<BLOCK_HEIGHT; i++)
for (int j = 0; j<BLOCK_WIDTH; j++)
outtextxy(x + UNIT_SIZE*j, y + UNIT_SIZE*i, "■");
}
void drawBlock(int x, int y, int next) {
setfont(23, 0, "楷体");
setcolor(color[NextIndex]);
for (int i = 0; i<5; i++)
for (int j = 0; j<5; j++)
if (block[4 * NextIndex][i][j] == 1)
outtextxy(x + 20 * j, y + 20 * i, "■");
}
void nextblock()
{
int x = 391, y = 71;
//在右侧的提示区清除原来的方块
clearBlock(x, y);
// 在右侧的提示区绘制新方块
// 1. 产生新的方块
srand(time(NULL));
NextIndex = rand() % BLOCK_COUNT;
// 2. 绘制
drawBlock(x, y, NextIndex);
}
int main()
{
welcome();
initGameScene();
nextblock();
system("pause");
closegraph();
return 0;
}
|