|
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "remote.h"
-
- u8 key;
- u8 *str=0;
- u8 num,total=3;
- u8 suiji=0;
- u16 pos[100]={30,30,54,30,78,30};
- u16 xx=3,yy=3;
- int i;
- int main(void)
- {
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init(); //LED端口初始化
- LCD_Init();
- KEY_Init();
- Remote_Init(); //红外接收初始化
-
-
-
- // LCD_Fill(pos[0],pos[1],pos[0]+19,pos[1]+19,GREEN);
- //LCD_Fill(pos[2],pos[3],pos[2]+19,pos[3]+19,BLUE);
- //LCD_Fill(pos[4],pos[5],pos[4]+19,pos[5]+19,RED);
-
- LCD_Fill(xx*24+6,yy*24+6,xx*24+25,yy*24+25,RED);
-
-
- while(1)
- {
- key=Remote_Scan();
- if(key!=0)num=key;
-
- for(i=total*2-1;i>=2;i--)
- {
- pos[i]=pos[i-2];
- }
-
- switch(num)
- {
- case 98:
- {
- pos[1]-=24;
- };break;
- case 194:
- {
- pos[0]+=24;
- };break;
- case 34:
- {
- pos[0]-=24;
- };break;
- case 168:
- {
- pos[1]+=24;
- };break;
- }
-
- LCD_Fill(pos[0],pos[1],pos[0]+19,pos[1]+19,GREEN);
- for(i=1;i<total;i++)
- {
- LCD_Fill(pos[i*2],pos[i*2+1],pos[i*2]+19,pos[i*2+1]+19,BLUE);
- }
-
-
-
- //吃到食物,产生随机位置的食物
- suiji++;
- if(suiji>209)suiji=0;
- if((pos[0]==xx*24+6)&&(pos[1]==yy*24+6))
- {
- xx=suiji%11;
- yy=suiji%11;
- total++;
- }
- LCD_Fill(xx*24+6,yy*24+6,xx*24+25,yy*24+25,RED);
- delay_ms(800);
- LCD_Clear(WHITE);
-
-
-
- //游戏结束
- if((pos[0]<6)||(pos[0]>294)||(pos[1]<6)||(pos[1]>294))
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- LCD_ShowString(30,90,200,24,24,"GAME OVER");
- LCD_ShowString(30,140,240,24,24,"Your Grade Is:");
- LCD_ShowNum(200,140,total,3,24);
- total=3;
- beef=1;
- delay_ms(500);delay_ms(500);delay_ms(500);delay_ms(500);
- }
- for(i=8;i<=(2*total-2);i=i+2)
- if((pos[0]==pos[i])&&(pos[1]==pos[i+1]))
- {
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- LCD_ShowString(30,90,200,24,24,"GAME OVER");
- LCD_ShowString(30,140,240,24,24,"Your Grade Is:");
- LCD_ShowNum(240,140,total,5,24);
- total=3;
- beef=1;
- delay_ms(500);delay_ms(500);delay_ms(500);delay_ms(500);
- }
-
-
- }
- }
复制代码
|
|