主程序
int main(void)
{
lcd_init();
Key_Init();
NVIC_Init(NVIC_PriorityGroup_2);
TIM3_Init(20,36000-1);
lcd_clear(WHITE);
welcome();
systick_delay_ms(10);
suijishu[0]=rand()%19+1;
suijishu[1]=rand()%19+1;
suijishu[2]=rand()%19+1;
suijishu[3]=rand()%19+1;
suijishu[4]=rand()%19+1;
/*
#define KEY_UP 1
#define KEY_DOWN 2
#define KEY_LEFT 3
#define KEY_RIGHT 4
#define KEY_MID 5 */
while(1)
{
switch(Key_Scan())
{
case 0:
break;
//功能区
case 1:
if(game==1){
game=2;
first();
begin();
}
else if(game==2){
game=4;
stop();
}
else if(game==4){
game=2;
star();
}
else if(game==3){
game=1;
}
break;
case 2:
if(game!=2)
break;
if(!panduan(x,y,what,2)){//方向判断
Down(x,y,what);
y=y+10;
}else{
xiaochu();
begin();
} break;
case 3:
if(game!=2)
break;
if(!panduan(x,y,what,1)){
Left(x,y,what);x=x-10;
}break;
case 4:
if(game!=2)
break;
if(!panduan(x,y,what,3)){
Right(x,y,what);x=x+10;
}break;
case 5:
if(game!=2)
break;
if(!panduan(x,y,what,4))
change();
break;
}
//方块下落
if(game==2)
{
if(i>speed)
{
i=0;
if(panduan(x,y,what,2))//若判断碰撞且满足消除条件,返回值并调用消除函数
{
xiaochu();
begin();
}
else
{
Down(x,y,what); //否则匀速下移
y=y+10;
}
}
}
}
}
|