This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/MCU_REAL _FINAL/block.c

89 lines
No EOL
1.2 KiB
C

#include "block.h"
Group *base;
Group *piece;
void blockInit()
{
base=(Group*)calloc(1,sizeof(Group));
groupInit(*base,64);
}
void genPiece()
{
unsigned char i=2+rand()%3;
piece=(Group*)calloc(1,sizeof(Group));
groupInit(*piece,i);
}
void genShape(Group g)
{
//需要一点随机性
int random=rand()%4;
//当两个方块的情况
if(g.len==2)
{
if(random%2==0)
{
g.list[0].x=4; //
g.list[0].y=8; //
g.list[1].x=4;
g.list[1].y=9;
}
else
{
g.list[0].x=4; ////
g.list[0].y=8;
g.list[1].x=5;
g.list[1].y=8;
}
}
//当三个方块的情况
if(g.len==3)
{
if(random%2==0)
{
g.list[0].x=4; //
g.list[0].y=8; //
g.list[1].x=4; //
g.list[1].y=9;
g.list[2].x=4;
g.list[2].y=10;
}
else
{
g.list[0].x=4; //////
g.list[0].y=8;
g.list[1].x=5;
g.list[1].y=8;
g.list[2].x=4;
g.list[2].y=9;
}
}
//当四个方块的情况
if(g.len==3)
{
if(random==0)
{
g.list[0].x=4; //
g.list[0].y=8; //
g.list[1].x=4; ////
g.list[1].y=9;
g.list[2].x=4;
g.list[2].y=10;
g.list[3].x=5;
g.list[3].y=8;
}
else
{
g.list[0].x=4;
g.list[0].y=8;
g.list[1].x=5;
g.list[1].y=8;
g.list[2].x=4;
g.list[2].y=9;
}
}
}