2022-06-04 14:15:13 +00:00
|
|
|
|
#include "block.h"
|
2022-06-05 15:35:53 +00:00
|
|
|
|
#include "draw.h"
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
2022-06-06 01:40:49 +00:00
|
|
|
|
unsigned 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>
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
|
|
|
|
void blockInit()
|
|
|
|
|
{
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
|
|
|
|
base[0][0]=1;
|
|
|
|
|
base[0][1]=1;
|
|
|
|
|
base[0][2]=1;
|
|
|
|
|
// genPiece();
|
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 01:40:49 +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
|
|
|
|
{
|
|
|
|
|
//<2F><>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-05 15:35:53 +00:00
|
|
|
|
int random = rand() % 4;
|
|
|
|
|
int len = 2 + rand() % 3;
|
|
|
|
|
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
piece.mother.x=4;
|
|
|
|
|
piece.mother.y=8;
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
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 01:40:49 +00:00
|
|
|
|
base[4][8]=2; //
|
|
|
|
|
base[4][9]=2; //
|
|
|
|
|
}
|
2022-06-05 15:35:53 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-06 01:40:49 +00:00
|
|
|
|
base[3][8]=2; ////
|
|
|
|
|
base[4][8]=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 01:40:49 +00:00
|
|
|
|
base[4][8]=2;
|
|
|
|
|
base[4][9]=2;
|
|
|
|
|
base[4][10]=2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if(random == 1)
|
|
|
|
|
{
|
2022-06-06 01:40:49 +00:00
|
|
|
|
base[3][8]=2;
|
|
|
|
|
base[4][8]=2;
|
|
|
|
|
base[5][8]=2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if(random == 2)
|
|
|
|
|
{
|
2022-06-06 01:40:49 +00:00
|
|
|
|
base[3][9]=2;
|
|
|
|
|
base[3][8]=2;
|
|
|
|
|
base[4][8]=2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
else if (random == 3)
|
|
|
|
|
{
|
2022-06-06 01:40:49 +00:00
|
|
|
|
base[4][9]=2;
|
|
|
|
|
base[3][8]=2;
|
|
|
|
|
base[4][8]=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 01:40:49 +00:00
|
|
|
|
base[3][9]=2;
|
|
|
|
|
base[4][9]=2;
|
|
|
|
|
base[3][8]=2;
|
|
|
|
|
base[4][8]=2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unsigned char isIegal(unsigned char i,unsigned char j)
|
|
|
|
|
{
|
|
|
|
|
if(i>=0&&i<MAX_X&&j>=0&&j<MAX_Y)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
void dropPiece()
|
|
|
|
|
{
|
2022-06-06 01:40:49 +00:00
|
|
|
|
int i.j;
|
|
|
|
|
for(i=0,i<MAX_X,i++)
|
|
|
|
|
for(j=0,j<MAX_Y,j++)
|
|
|
|
|
{
|
|
|
|
|
if(base[i][j]==2&&isIegal(i,j-1))
|
|
|
|
|
{
|
|
|
|
|
base[i][j-1]=2;
|
|
|
|
|
base[i][j]=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void drawBlock()
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
for(i=0;i<8;i++)
|
|
|
|
|
for(j=0;j<8;j++)
|
|
|
|
|
if(base[i][j]==1)
|
|
|
|
|
placeIMG_BLOCK(i,j);
|
|
|
|
|
placeIMG_BLOCK(piece.mother.x,piece.mother.y);
|
2022-06-04 14:15:13 +00:00
|
|
|
|
}
|