嵌入式系统课程设计贪吃蛇Word文档格式.docx
- 文档编号:20559902
- 上传时间:2023-01-24
- 格式:DOCX
- 页数:33
- 大小:372.29KB
嵌入式系统课程设计贪吃蛇Word文档格式.docx
《嵌入式系统课程设计贪吃蛇Word文档格式.docx》由会员分享,可在线阅读,更多相关《嵌入式系统课程设计贪吃蛇Word文档格式.docx(33页珍藏版)》请在冰豆网上搜索。
#defineUP1//蛇的方向
#defineDOWN2
#defineLEFT3
#defineRIGHT4
#defineROW22//表格行数
#defineCOLUMN22//表格列数
//定义蛇的各项信息
structSnake
{
S32x[MAX_X];
S32y[MAX_Y];
S32length;
S32direction;
S32life;
}snake;
structFood
{
intx;
/*食物的横坐标*/
inty;
/*食物的纵坐标*/
intyes;
/*判断是否要出现食物的变量*/
}food;
/*食物的结构体*/
S16map_1[22][22]={//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21}
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//0
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//1
{0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0},//2
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},//3
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},//4
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},//5
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},//6
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//7
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//8
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//9
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},//10
{0,0,0,0,0,0,0,0,0,0,0,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1,1,1,1,0,0,0,0,1},//9
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//10
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//11
{1,0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,1},//12
{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},//13
{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},//14
{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},//15
{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},//16
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//17
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//18
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//19
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//20
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}//21
intoldDire=4;
//记录前一个方向
intscore=0;
//分数
intgametime=99;
//时间
intmapSelect=0;
//关卡
intgamespeed=0;
//难度,速度
intkey_F=0;
//标记F键
intsetUnit=0;
//设置游戏项,0表示关卡,1表示难度
intfoodIndex=0;
//第几个食物
intmySrand=0;
voidDraw_GUI();
//绘制游戏界面
voidRandom_Food();
//产生食物
voidGameOver();
//结束游戏
voidNewGame();
//新游戏
voidPrScore();
//输出新得分
voidDspTime(INT32U);
//显示倒计时
voidDrawMap();
//画障碍物
voidCheckMap();
//判断蛇是否撞到障碍物
voidSet_SelectFace();
//游戏设置
voidDrawSetForm();
//游戏设置键
voidTask_2();
-函数名称:
Task_4(void*pdata)
-函数说明:
GUI任务,优先级为56
-输入参数:
pdata
-输出参数:
无
voidTask_4(void*pdata)
I32k=0;
inti=0;
intj=0;
intx=0;
inty=0;
=0;
//活着
[0]=100;
[0]=40;
//蛇头
[1]=80;
[1]=40;
//第一节蛇
[2]=60;
[2]=40;
=3;
//节数
=RIGHT;
=0;
while
(1)
{
if(score>
=100)
{
score=0;
mapSelect++;
Set_Color(GUI_GREEN);
Set_Font(&
CHINESE_FONT16);
Disp_String(CN_start"
恭喜你,进入下一关!
"
CN_end,240,240);
OSTimeDly(200);
NewGame();
}
if(key_F==1)//是否进入游戏设置
//OSTimeDly(100);
OSTimeDly(50000);
if[0]==*20)+20&
&
[0]==*20)+20)/*吃到食物以后*/
{
Set_Color(GUI_WHITE);
//用白色去除蛇的的最后一节
Fill_Rect(*20)+20,*20)+20,*20)+40,*20)+40);
++;
//蛇的身体长一节
=0;
//画面上需要出现新的食物
score+=10;
PrScore();
//输出新得分
}
x=[];
y=[];
for(i=;
i>
0;
i--)//蛇的每个环节往前!
!
[i]=[i-1];
}
Set_Color(GUI_GREEN);
//画出蛇
for(j=0;
j<
j++)
Fill_Rect[j],[j],[j]+20,[j]+20);
if==0)//画食物
Random_Food();
Uart_Printf("
randomx=%x\n"
;
randomy=%x\n"
Set_Color(GUI_RED);
//设置食物颜色红色
Fill_Circle(*20)+30,*20)+30,10);
//画食物,为红色的圆
switch//蛇的方向
caseUP:
if(oldDire!
=DOWN)
{
[0]-=20;
oldDire=;
}
else
[0]+=20;
break;
caseDOWN:
=UP)
caseLEFT:
=RIGHT)
caseRIGHT:
=LEFT)
default:
Uart_Printf("
[0]=%d**************[0]=%d\n"
[0],[0]);
for(i=3;
i<
i++)//是否撞到自己了,因为蛇头为两节,第三节不可能拐过来
if[i]==[0]&
[i]==[0])
=1;
CheckMap();
//判断蛇死亡条件
if[0]<
20)
[0]=440;
elseif[0]>
440){
[0]=20;
elseif[0]<
20){
if(gametime<
=0)//时间到了
=1;
//蛇死
>
=%d\n"
if==1)//蛇是否死了
GameOver();
//本次游戏结束
if(gamespeed==0)//易
for(k=0;
k<
k++);
elseif(gamespeed==1)//中
1000000;
elseif(gamespeed==2)//难
100000;
else
Set_Color(GUI_WHITE);
//用灰色去除蛇的的最后一节
Fill_Rect(x,y,x+20,y+20);
OSTimeDly(10);
}
Task_3
任务3,向串口发送数据
voidTask_3(void*pdata)
for(;
)
{
if(key_number!
=0xff)
{
key_number=%x\n"
key_number);
//任务的干得活儿就是向超级终端发送内容
key_number=0xff;
OSTimeDly(30);
//延时100个节拍
//OSTimeDly(100);
}
voidTask_1(void*pdata)
INT8Uerr;
INT8U*Key_P;
INT8UKey_Val;
intys=0;
charcmapSelect[2];
Timer1_Init();
//打开时钟节拍,让操作系统跑起来
//OSTaskCreate(Task_2,(void*)0,(OS_STK*)&
Stack_Task_2[(STACKSIZE)-1],9);
//在任务里创建另一个任务
//OSTaskCreate(Task_3,(void*)0,(OS_STK*)&
Stack_Task_3[(STACKSIZE)-1],8);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 嵌入式 系统 课程设计 贪吃
![提示](https://static.bdocx.com/images/bang_tan.gif)