1、贪吃蛇新贪吃蛇新.txt男人应该感谢20多岁陪在自己身边的女人。因为20岁是男人人生的最低谷,没钱,没事业;而20岁,却是女人一生中最灿烂的季节。只要锄头舞得好,哪有墙角挖不到?/*/* #说明: C main 函数,ucos-ii初始化等定义 - Bug - - TODO list - -修正- 2010-1-12 创建*/#include./ucos-ii/includes.h /* uC/OS interface */#include ./ucos-ii/add/osaddition.h#include ./inc/drivers.h#include ./inc/sys/lib.h#in
2、clude ./src/gui/gui.h#include #include #pragma import(_use_no_semihosting_swi) / ensure no functions that use semihosting OS_EVENT *Mbox;/*任务定义*/OS_STK Main_StackSTACKSIZE=0, ; /Main_Test_Task堆栈void Main_Task(void *Id); /Main_Test_Task#define Main_Task_Prio 12OS_STK Bioskey_StackSTACKSIZE=0, ; /bios
3、key_Test_Task堆栈void Bioskey_Task(void *Id); /bioskey_Test_Task#define Bioskey_Task_Prio 15OS_STK LED_StackSTACKSIZE=0,;void LED_Task(void *Id);#define LED_Task_Prio 18/*/#define WHITE 0x0FFF#define BLACK 0x0000#define SIZE 16 /定义SIZE将原坐标系简化 #define BGCOLOR BLACK/ 背景色#define FORECOLOR WHITE/前景色,用来标志游
4、戏已被填充的部分#define SCOREINTERVAL 30/升级间隔的分数#define GPFCON (*(volatile unsigned *)0x56000050)#define GPFUP (*(volatile unsigned *)0x56000058)/*游戏 定义*/#define N 30#define ROW 25#define COLUMN 25U16 speed=0,score=0;int x=0, y=0;int boardROWCOLUMN; /* 记录游戏板当前状态的数组 */*结构定义*/struct Snake int xN; int yN; int
5、node; int direction; int life;snake;struct Bean int x; int y; int yes;bean;/*功能函数定义*/* 画 基 本 块 */void DrawBeanSnake(PDC dc,int x,int y,int color) if(y1)return; FillRect(dc,SIZE*(x+9)+1,SIZE*(y+4)+1,SIZE*(x+10)-1,SIZE*(y+5)-1,0,color);/* 画 蛇 */void DrawSnake(PDC dc) int i=0; DrawBeanSnake(dc,snake.x0
6、,snake.y0,FORECOLOR); for(i=1;isnake.node;i+) DrawBeanSnake(dc,snake.xi,snake.yi,FORECOLOR); /* 画 豆 子 */void DrawBean(PDC dc) int i; if(bean.yes=1) DrawBeanSnake(dc,bean.x,bean.y,FORECOLOR); else for(;) bean.x=rand()%23+1; bean.y=rand()%23+1; bean.yes=1; for(i=0;i0;i-) snake.xi=snake.xi-1; snake.yi=
7、snake.yi-1; switch(snake.direction) case 1:/left if(snake.x0-1!=snake.x2) snake.x0=snake.x0-1; else snake.x0=snake.x0+1; break; case 2: /right if(snake.x0+1!=snake.x2) snake.x0=snake.x0+1; else snake.x0=snake.x0-1; break; case 3: /up if(snake.y0-1!=snake.y2) snake.y0=snake.y0-1; else snake.y0=snake.
8、y0+1; break; case 4: /down if(snake.y0+1!=snake.y2) snake.y0=snake.y0+1; else snake.y0=snake.y0-1; break; /* 吃 豆 子 */void EatBean() if(snake.x0=bean.x&snake.y0=bean.y) bean.yes=0; score+; speed=score/3; if(snake.node0;j-) for (i=COLUMN-2;i0;i-) DrawBeanSnake(dc,i,j,BGCOLOR); snake.node=4; snake.life
9、=1;/1为活着,0为死亡 score=0; speed=0; snake.direction=1; for(i=0;isnake.node;i+) snake.xi=11+i; snake.yi=12; DrawSnake(dc); /* 蛇 生 命 判 断 */void SnakeLife() int i; if(snake.x0=0|snake.x0=24|snake.y0=0|snake.y0=24) snake.life=0; for(i=4;i0) OSTimeDly(600-50*speed); else OSTimeDly(50); DrawBean(pdc); msg=(U8
10、 *)OSMboxPend(Mbox,0,&err); switch(msg0) case 4: snake.direction=1; break; case 6: snake.direction=2; break; case 8: snake.direction=3; break; case 2: snake.direction=4; break; SnakeMove(pdc); SnakeLife(); if(snake.life=1) EatBean(); DrawSnake(pdc); else break; /break; /可以询问是否重新开始 GameOver(pdc); msg
11、=(U8 *)OSMboxPend(Mbox, 0, &err); if(msg0!=5) break; DestoryDC(pdc);/删除绘图设备上下文/void Bioskey_Task(void *Id) /bioskey_Test_Task U8 key; unsigned char KeyBoard_Map=0,0,11,0,0,0,0,0,0,0,0 ,14,0,0,0,0,0,10,0,13,0 ,12,0,0,0,0,0,22,0,0,0 ,0,0,1,0,3,17,2,0,0,0 ,4,0,6,0,5,0,0,0,7,0 ,9,15,8,0,0,0,0,0,0,0 ,0,0
12、,0 ; /64,键值映射表 for(;) key=IIC_Read(0x70, 1); hudelay(10); if(key=0) continue; key= KeyBoard_Mapkey; OSMboxPost(Mbox, &key); OSTimeDly(80); /for/bioskey/void LED_Task(void *Id) U8 key,key1,value,value1; int i; value=0; value1=0; for(;) key=score; key1=speed; hudelay(3000); IIC_Write(0x70, 0x07, 0x60)
13、; IIC_Write(0x70, 0x08, key); hudelay(3000); IIC_Write(0x70, 0x07, 0x64); IIC_Write(0x70, 0x08, key1); /* if(key=10) value=key/10; key=key%10; hudelay(30); IIC_Write(0x70, 0x07, 0x60); IIC_Write(0x70, 0x08, key); IIC_Write(0x70, 0x07, 0x61); IIC_Write(0x70, 0x08, value); hudelay(30); if(key1=10) value1=key1/10; key1=key1%10; hudelay(30); IIC_Write(0x70, 0x07, 0x64); IIC_Write(0x70, 0x08, key1); IIC_Write(0x70, 0x07, 0x65); IIC_Write(0x70, 0x08, value1); */ OSTimeDly(80);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1