2022-06-04 14:15:13 +00:00
|
|
|
|
#include "block.h"
|
2022-06-05 15:35:53 +00:00
|
|
|
|
#include "draw.h"
|
2022-06-06 05:41:14 +00:00
|
|
|
|
#include "button.h"
|
2022-06-06 05:55:35 +00:00
|
|
|
|
#include <reg52.h>
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ<30><CEAA> 1Ϊ<31><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2Ϊ<32><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
enum BLK_TP type = none;
|
2022-06-04 14:15:13 +00:00
|
|
|
|
void blockInit()
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
base[0][0] = 1;
|
|
|
|
|
base[0][1] = 1;
|
|
|
|
|
base[0][2] = 1;
|
|
|
|
|
|
2022-06-04 14:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
void blockDestroy()
|
2022-06-04 14:15:13 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
memset(base, 0, sizeof(base));
|
2022-06-04 14:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
void genPiece()
|
2022-06-04 14:15:13 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
char i, j;
|
2022-06-04 14:15:13 +00:00
|
|
|
|
//<2F><>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-06 05:55:35 +00:00
|
|
|
|
int random = TH0 % 4;
|
|
|
|
|
int len = 2 + TH0 % 3;
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵķ<C9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
if(base[i][j] == 2)
|
2022-06-06 05:55:35 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(len == 2)
|
|
|
|
|
{
|
|
|
|
|
if(random % 2 == 0)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[4][7] = 2; //
|
|
|
|
|
base[4][8] = 2; //
|
|
|
|
|
}
|
2022-06-05 15:35:53 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[3][7] = 2; ////
|
|
|
|
|
base[4][7] = 2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(len == 3)
|
|
|
|
|
{
|
|
|
|
|
if(random == 0)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[4][7] = 2;
|
|
|
|
|
base[4][8] = 2;
|
|
|
|
|
base[4][9] = 2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if(random == 1)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[3][7] = 2;
|
|
|
|
|
base[4][7] = 2;
|
|
|
|
|
base[5][7] = 2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if(random == 2)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[3][8] = 2;
|
|
|
|
|
base[3][7] = 2;
|
|
|
|
|
base[4][7] = 2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if (random == 3)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[4][8] = 2;
|
|
|
|
|
base[3][7] = 2;
|
|
|
|
|
base[4][7] = 2;
|
|
|
|
|
}
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(len == 3)
|
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[3][7] = 2;
|
|
|
|
|
base[4][7] = 2;
|
|
|
|
|
base[3][8] = 2;
|
|
|
|
|
base[4][8] = 2;
|
|
|
|
|
}
|
2022-06-06 01:40:49 +00:00
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>
|
|
|
|
|
unsigned char isIegal(char i, char j)
|
2022-06-06 01:40:49 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
if(i >= 0 && i < MAX_X && j >= 0 && j < MAX_Y && base[i][j] == 0)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void drawBlock()
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
char i, j;
|
|
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
|
for(j = 0; j < 8; j++)
|
|
|
|
|
if(base[i][j] != 0)
|
|
|
|
|
placeIMG_BLOCK(i, j);
|
|
|
|
|
else
|
|
|
|
|
place_VOID_BLOCK(i, j);
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
|
|
|
|
|
void dropPiece()
|
|
|
|
|
{
|
|
|
|
|
char i, j, flag = 0;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7>
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
|
|
|
|
if(flag == 1)
|
|
|
|
|
break;
|
|
|
|
|
if(base[i][j] == 2)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(flag == 0 && (base[i][j - 1] == 1 || j == 0))
|
|
|
|
|
{
|
|
|
|
|
flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(flag == 1)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//ת<><D7AA>Ƕ<EFBFBD><C7B6>
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
|
|
|
|
if(base[i][j] == 2)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ޱ<EFBFBD><DEB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(flag == 0 && isIegal(i, j - 1))
|
|
|
|
|
{
|
|
|
|
|
base[i][j - 1] = 2;
|
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
//<2F>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|
|
|
|
else if(flag == 1)
|
|
|
|
|
base[i][j] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
|
|
|
|
|
void movePiece(enum OPR opr)
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
char i, j;
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
if(base[i][j] == 2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(opr == left && isIegal(i - 1, j))
|
|
|
|
|
{
|
|
|
|
|
base[i - 1][j] = 2;
|
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(opr == left && isIegal(i + 1, j))
|
|
|
|
|
{
|
|
|
|
|
base[i + 1][j] = 2;
|
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|