feat(MCU课设): 试图修改实现方法

This commit is contained in:
iridiumR 2022-06-06 09:40:49 +08:00
parent 5618c61ce4
commit 49a8fdaa76
2 changed files with 42 additions and 39 deletions

View file

@ -1,9 +1,7 @@
#include "block.h"
#include "draw.h"
Group piece;
unsigned char regenPieceFlag = 0;
unsigned char base[8][11]={0}; //x*y
unsigned char base[MAX_X][MAX_Y]={0}; //x*y //0为空 1为下落完成 2为正在下落
void blockInit()
{
@ -16,7 +14,7 @@ base[0][2]=1;
void blockDestroy()
{
piece.type=none;
memset(base, 0, sizeof(base));
}
void genPiece()
@ -36,11 +34,13 @@ void genPiece()
{
if(random % 2 == 0)
{
piece.type = two_v; //
} //
base[4][8]=2; //
base[4][9]=2; //
}
else
{
piece.type = two_h; ////
base[3][8]=2; ////
base[4][8]=2;
}
}
//当三个方块的情况
@ -48,53 +48,56 @@ void genPiece()
{
if(random == 0)
{
//
piece.type = three_h; //
//
base[4][8]=2;
base[4][9]=2;
base[4][10]=2;
}
else if(random == 1)
{
piece.type = three_v; //////
base[3][8]=2;
base[4][8]=2;
base[5][8]=2;
}
else if(random == 2)
{
//
piece.type = three_l; ////
base[3][9]=2;
base[3][8]=2;
base[4][8]=2;
}
else if (random == 3)
{
piece.type = three_r; //
} ////
base[4][9]=2;
base[3][8]=2;
base[4][8]=2;
}
}
//当四个方块的情况
if(len == 3)
{
piece.type = four; ////
} ////
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;
}
void dropPiece()
{
piece.mother.y--;
// int i;
// for(i = 0; i < len; i++)
// {
// //触底或下有base方块
// if(piece.list[i].x == 0 || base[piece.list[i].x][piece.list[i].y - 1] == 1)
// {
// for(i = 0; i < len;i++)
// {
// //全部方块转移到base
// base[piece.list[i].x][piece.list[i].y] == 1;
// }
// //重新生成
// genPiece();
// return;
// }
// else
// //正常下落
// piece.list[i].y--;
// }
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;
}
}
}

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
# include <string.h>
#define MAX_X 8
#define MAX_Y 8
#define MAX_Y 12
enum BLK_TP {none,two_h,two_v,three_l,three_r,three_h,three_v,four};
//点 结构体