fix(MCU课设): 修正方块生成逻辑

This commit is contained in:
iridiumR 2022-06-06 14:48:59 +08:00
parent 4f0e69ddab
commit 49cb727472
5 changed files with 807 additions and 750 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,10 +10,6 @@ extern enum OPR opr;
void blockInit() void blockInit()
{ {
base[0][0] = 1;
base[0][1] = 1;
base[0][2] = 1;
} }
void blockDestroy() void blockDestroy()
@ -26,8 +22,8 @@ void genPiece()
char i, j; char i, j;
//需要一点随机性 //需要一点随机性
int random = TH0 % 4; int random = TH0 % 9;
int len = 2 + TH0 % 3;
//若存在尚未下落完成的方块则打断 //若存在尚未下落完成的方块则打断
@ -36,52 +32,53 @@ void genPiece()
if(base[i][j] == 2) if(base[i][j] == 2)
return; return;
//当两个方块的情况
if(random == 0)
{
base[4][8] = 2;
}
//当两个方块的情况 //当两个方块的情况
if(len == 2) if(random == 1 || random == 2)
{ {
if(random % 2 == 0) base[4][8] = 2; //
{ base[5][8] = 2; //
base[4][8] = 2; //
base[4][8] = 2; //
}
else
{
base[3][8] = 2; ////
base[4][8] = 2;
}
} }
else if(random == 3)
{
base[3][8] = 2; ////
base[4][8] = 2;
}
//当三个方块的情况 //当三个方块的情况
if(len == 3) else if(random == 4 || random == 5)
{ {
if(random == 0)
{ base[4][10] = 2;
base[4][10] = 2; base[4][8] = 2;
base[4][8] = 2; base[4][9] = 2;
base[4][9] = 2;
}
else if(random == 1)
{
base[3][8] = 2;
base[4][8] = 2;
base[5][8] = 2;
}
else if(random == 2)
{
base[3][9] = 2;
base[3][8] = 2;
base[4][8] = 2;
}
else if (random == 3)
{
base[4][9] = 2;
base[3][8] = 2;
base[4][8] = 2;
}
} }
//µ±Ëĸö·½¿éµÄÇé¿ö else if(random == 6)
if(len == 3) {
base[3][8] = 2;
base[4][8] = 2;
base[5][8] = 2;
}
else if(random == 7)
{
base[3][9] = 2;
base[3][8] = 2;
base[4][8] = 2;
}
else if (random == 8)
{
base[4][9] = 2;
base[3][8] = 2;
base[4][8] = 2;
}
//当四个方块的情况
else if(random == 6)
{ {
base[3][9] = 2; base[3][9] = 2;
base[4][9] = 2; base[4][9] = 2;
@ -107,7 +104,7 @@ void drawBlock()
if(base[i][j] != 0) if(base[i][j] != 0)
placeIMG_BLOCK(i, j); placeIMG_BLOCK(i, j);
else else
place_VOID_BLOCK(i, j); placeVOID_BLOCK(i, j);
} }
//方块下落与合并 //方块下落与合并

View file

@ -264,7 +264,7 @@ void placeIMG_BLOCK(unsigned char x,unsigned char y)
} }
} }
void place_VOID_BLOCK(unsigned char x,unsigned char y) void placeVOID_BLOCK(unsigned char x,unsigned char y)
{ {
char j; char j;
for(j = 0 ; j < 8; j++) for(j = 0 ; j < 8; j++)
@ -284,4 +284,38 @@ void place_VOID_BLOCK(unsigned char x,unsigned char y)
P1 = 0x00; P1 = 0x00;
write(); write();
} }
}
void drawVerticalDottedLine(char x)
{
unsigned int j;
if(x<0||x>127)
return;
else if(x<64)
{
}
else
{
x=x-63;
CSA = 0;
CSB = 1;
}
for(j = 0 ; j < 8; j++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + j;
write();
P1 = 0X40 + x;
write(); //Ò³2ÁÐjÆÁA
RS = 1;
RW = 0;
P1 = 0x55;
write();
}
} }

View file

@ -9,5 +9,8 @@ void drawMAINMENU(unsigned char);
////=================== 方块 ================== ////=================== 方块 ==================
void placeIMG_BLOCK(unsigned char x,unsigned char y); void placeIMG_BLOCK(unsigned char x,unsigned char y);
void place_VOID_BLOCK(unsigned char x,unsigned char y); void placeVOID_BLOCK(unsigned char x,unsigned char y);
////=================== 섯부 ==================
void drawVerticalDottedLine(char x);
#endif #endif

View file

@ -106,6 +106,7 @@ void m_block(struct _menu* this)
if(LAST != &M_BLOCK) if(LAST != &M_BLOCK)
{ {
LAST = &M_BLOCK; LAST = &M_BLOCK;
drawVerticalDottedLine(64);
blockInit(); blockInit();
} }
//ÖØÖÃ //ÖØÖÃ