求基于arm-linux平台的贪吃蛇游戏arm linux 开发环境思路

基于μCOS系统ARM9硬件平台的贪吃蛇C语言游戏设计_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
12页2下载券15页2下载券24页2下载券2页免费25页4下载券2页免费29页7下载券14页2下载券6页免费
喜欢此文档的还喜欢26页4下载券39页免费18页7下载券4页免费15页2下载券
基于μCOS系统ARM9硬件平台的贪吃蛇C语言游戏设计|基​于​μ​C​O​S​系​统​A​R​M硬​件​平​台​的​贪​吃​蛇​C​语​言​游​戏​设​计
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢Linux 环境下C语言编译实现贪吃蛇游戏_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Linux 环境下C语言编译实现贪吃蛇游戏
来源:Linux社区&
作者:fbi987996
^_^一个小游戏,贪吃蛇,C语言实现 嘎嘎 在Linux 环境下 编译通过。
//mysnake1.0.c//编译命令:cc mysnake1.0.c -lcurses -o mysnake1.0//用方向键控制蛇的方向#include &stdio.h&#include &stdlib.h&#include &curses.h&#include &signal.h&#include &sys/time.h&#define NUM 60struct direct&&&&&&&&&&&&&&& //用来表示方向的{&&& int &&& int };typedef struct node&&&&&&&&&&& //链表的结点{&&& int &&& int &&& struct node *&&& struct node *}void initGame();&&&&&&&&&&& //初始化游戏int setTicker(int);&&&&&&&&&&& //设置计时器void show();&&&&&&&&&&&&&&& //显示整个画面void showInformation();&&&&&&& //显示游戏信息(前两行)void showSnake();&&&&&&&&&&& //显示蛇的身体void getOrder();&&&&&&&&&&& //从键盘中获取命令void over(int i);&&&&&&&&&&& //完成游戏结束后的提示信息void creatLink();&&&&&&&&&&&&&&& //(带头尾结点)双向链表以及它的操作void insertNode(int x, int y);&&&void deleteNode();void deleteLink();int &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //输入的命令int hour, minute,&&&&&&&&&&& //时分秒int length, tTime,&&&&&&&&&&& //(蛇的)长度,计时器,(游戏)等级struct direct dir,&&&&&&&&&&& //蛇的前进方向,食物的位置node *head, *&&&&&&&&&&&&&&&&&&& //链表的头尾结点int main(){&&& initscr();&&& initGame();&&& signal(SIGALRM, show);&&& getOrder();&&& endwin();&&& return <SPAN style="COLOR: #;}void initGame(){&&& cbreak();&&&&&&&&&&&&&&&&&&& //把终端的CBREAK模式打开&&& noecho();&&&&&&&&&&&&&&&&&&& //关闭回显&&& curs_set(<SPAN style="COLOR: #);&&&&&&&&&&&&&&& //把光标置为不可见&&& keypad(stdscr, true);&&&&&&& //使用用户终端的键盘上的小键盘&&& srand(time(<SPAN style="COLOR: #));&&&&&&&&&&&&&&& //设置随机数种子&&& //初始化各项数据&&& hour = minute = second = tTime = <SPAN style="COLOR: #;&&& length = <SPAN style="COLOR: #;&&& dir.cx = <SPAN style="COLOR: #;&&& dir.cy = <SPAN style="COLOR: #;&&& ch = 'A';&&& food.cx = rand() % COLS;&&& food.cy = rand() % (LINES-<SPAN style="COLOR: #) + <SPAN style="COLOR: #;&&& creatLink();&&& setTicker(<SPAN style="COLOR: #);}//设置计时器(这个函数是书本上的例子,有改动)int setTicker(int n_msecs){&&& struct itimerval new_&&& long&&& n_sec, n_&&& n_sec = n_msecs / <SPAN style="COLOR: #00 ;&&& n_usecs = ( n_msecs % <SPAN style="COLOR: #00 ) * <SPAN style="COLOR: #00L ;&&& new_timeset.it_interval.tv_sec& = n_&&&&&&& &&& new_timeset.it_interval.tv_usec = n_&&&&& &&& n_msecs = <SPAN style="COLOR: #;&&& n_sec = n_msecs / <SPAN style="COLOR: #00 ;&&& n_usecs = ( n_msecs % <SPAN style="COLOR: #00 ) * <SPAN style="COLOR: #00L ;&&& new_timeset.it_value.tv_sec&&&& = n_sec& ;&&&&& &&& new_timeset.it_value.tv_usec&&& = n_&&&& &&& return setitimer(ITIMER_REAL, &new_timeset, NULL);}void showInformation(){&&& tTime++;&&& if(tTime &= <SPAN style="COLOR: #00000)&&&&&&&&&&&&&&& //&&&&&&& tTime = <SPAN style="COLOR: #;&&& if(<SPAN style="COLOR: # != tTime % <SPAN style="COLOR: #)&&&&&&& return;&&& move(<SPAN style="COLOR: #, <SPAN style="COLOR: #);&&&&&& //显示时间&&& printw("time: %d:%d:%d %c", hour, minute, second);&&& second++;&&& if(second & NUM)&&& {&&&&&&& second = <SPAN style="COLOR: #;&&&&&&& minute++;&&& }&&& if(minute & NUM)&&& {&&&&&&& minute = <SPAN style="COLOR: #;&&&&&&& hour++;&&& }&&& //显示长度,等级&&& move(<SPAN style="COLOR: #, <SPAN style="COLOR: #);&&& int i;&&& for(i=<SPAN style="COLOR: #;i&COLS;i++)&&&&&&& addstr("-");&&& move(<SPAN style="COLOR: #, COLS/<SPAN style="COLOR: #-<SPAN style="COLOR: #);&&& printw("length: %d", length);&&& move(<SPAN style="COLOR: #, COLS-<SPAN style="COLOR: #);&&& level = length / <SPAN style="COLOR: # + <SPAN style="COLOR: #;&&& printw("level: %d", level);}//蛇的表示是用一个带头尾结点的双向链表来表示的,//蛇的每一次前进,都是在链表的头部增加一个节点,在尾部删除一个节点//如果蛇吃了一个食物,那就不用删除节点了void showSnake(){&&& if(<SPAN style="COLOR: # != tTime % (<SPAN style="COLOR: #-level))&&&&&&& return;&&& //判断蛇的长度有没有改变&&& bool lenChange = false;&&& //显示食物&&& move(food.cy, food.cx);&&& printw("@");&&& //如果蛇碰到墙,则游戏结束&&& if((COLS-<SPAN style="COLOR: #==head-&next-&cx && <SPAN style="COLOR: #==dir.cx)&&&&&&& || (<SPAN style="COLOR: #==head-&next-&cx && -<SPAN style="COLOR: #==dir.cx)&&&&&&& || (LINES-<SPAN style="COLOR: #==head-&next-&cy && <SPAN style="COLOR: #==dir.cy)&&&&&&& || (<SPAN style="COLOR: #==head-&next-&cy && -<SPAN style="COLOR: #==dir.cy))&&& {&&&&&&& over(<SPAN style="COLOR: #);&&&&&&& return;&&& }&&& //如果蛇头砬到自己的身体,则游戏结束&&& if('*' == mvinch(head-&next-&cy+dir.cy, head-&next-&cx+dir.cx) )&&& {&&&&&&& over(<SPAN style="COLOR: #);&&&&&&& return;&&& }&&& insertNode(head-&next-&cx+dir.cx, head-&next-&cy+dir.cy);&&& //蛇吃了一个“食物”&&& if(head-&next-&cx==food.cx && head-&next-&cy==food.cy)&&& {&&&&&&& lenChange = true;&&&&&&& length++;&&&&&&& //恭喜你,通关了&&&&&&& if(length &= <SPAN style="COLOR: #)&&&&&&& {&&&&&&&&&&& over(<SPAN style="COLOR: #);&&&&&&&&&&& return;&&&&&&& }&&&&&&& //重新设置食物的位置&&&&&&& food.cx = rand() % COLS;&&&&&&& food.cy = rand() % (LINES-<SPAN style="COLOR: #) + <SPAN style="COLOR: #;&&& }&&& if(!lenChange)&&& {&&&&&&& move(tail-&back-&cy, tail-&back-&cx);&&&&&&& printw(" ");&&&&&&& deleteNode();&&& }&&& move(head-&next-&cy, head-&next-&cx);&&& printw("*");}void show(){&&& signal(SIGALRM, show);&&&&&&& //设置中断信号&&& showInformation();&&& showSnake();&&& refresh();&&&&&&&&&&&&&&&&&&& //刷新真实屏幕}void getOrder(){&&& //建立一个死循环,来读取来自键盘的命令&&& while(<SPAN style="COLOR: #)&&& {&&&&&&& ch = getch();&&&&&&& if(KEY_LEFT == ch)&&&&&&& {&&&&&&&&&&& dir.cx = -<SPAN style="COLOR: #;&&&&&&&&&&& dir.cy = <SPAN style="COLOR: #;&&&&&&& }&&&&&&& else if(KEY_UP == ch)&&&&&&& {&&&&&&&&&&& dir.cx = <SPAN style="COLOR: #;&&&&&&&&&&& dir.cy = -<SPAN style="COLOR: #;&&&&&&& }&&&&&&& else if(KEY_RIGHT == ch)&&&&&&& {&&&&&&&&&&& dir.cx = <SPAN style="COLOR: #;&&&&&&&&&&& dir.cy = <SPAN style="COLOR: #;&&&&&&& }&&&&&&& else if(KEY_DOWN == ch)&&&&&&& {&&&&&&&&&&& dir.cx = <SPAN style="COLOR: #;&&&&&&&&&&& dir.cy = <SPAN style="COLOR: #;&&&&&&& }&&&&&&& setTicker(<SPAN style="COLOR: #);&&& }}void over(int i){&&& //显示结束原因&&& move(<SPAN style="COLOR: #, <SPAN style="COLOR: #);&&& int j;&&& for(j=<SPAN style="COLOR: #;j&COLS;j++)&&&&&&& addstr(" ");&&& move(<SPAN style="COLOR: #, <SPAN style="COLOR: #);&&& if(<SPAN style="COLOR: # == i)&&&&&&& addstr("Crash the wall. Game over");&&& else if(<SPAN style="COLOR: # == i)&&&&&&& addstr("Crash itself. Game over");&&& else if(<SPAN style="COLOR: # == i)&&&&&&& addstr("Mission Complete");&&& setTicker(<SPAN style="COLOR: #);&&&&&&&&&&&&&&& //关闭计时器&&& deleteLink();&&&&&&&&&&&&&&& //释放链表的空间}//创建一个双向链表void creatLink(){&&& node *temp = (node *)malloc( sizeof(node) );&&& head = (node *)malloc( sizeof(node) );&&& tail = (node *)malloc( sizeof(node) );&&& temp-&cx = <SPAN style="COLOR: #;&&& temp-&cy = <SPAN style="COLOR: #;&&& head-&back = tail-&next = NULL;&&& head-&next = &&& temp-&next = &&& tail-&back = &&& temp-&back = }//在链表的头部(非头结点)插入一个结点void insertNode(int x, int y){&&& node *temp = (node *)malloc( sizeof(node) );&&& temp-&cx = x;&&& temp-&cy = y;&&& temp-&next = head-&&&& head-&next = &&& temp-&back = &&& temp-&next-&back = }//删除链表的(非尾结点的)最后一个结点void deleteNode(){&&& node *temp = tail-&&&& node *bTemp = temp-&&&& bTemp-&next = &&& tail-&back = bT&&& temp-&next = temp-&back = NULL;&&& free(temp);&&& temp = NULL;}//删除整个链表void deleteLink(){&&& while(head-&next != tail)&&&&&&& deleteNode();&&& head-&next = tail-&back = NULL;&&& free(head);&&& free(tail);}
相关资讯 & & &
& (12/17/:12)
& (11/12/:49)
& (01月08日)
& (11/20/:23)
& (10/12/:25)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款
匿名 发表于 好多错
(0) 匿名 发表于 错误真的很多
(0) sdsfdsf 发表于 怎么这么多错
(0) dasfdsf 发表于 全是错mini2440_arm9 基于S3C2410的设计,各种小游戏,如俄罗斯方块,贪吃蛇 Game Program
182万源代码下载-
&文件名称: mini2440_arm9
& & & & &&]
&&所属分类:
&&开发工具: Windows_Unix
&&文件大小: 1845 KB
&&上传时间:
&&下载次数: 35
&&提 供 者:
&详细说明:基于S3C2410的设计,各种小游戏,如俄罗斯方块,贪吃蛇-design based on S3C2410
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&基于mini2440_arm9及ADS开发环境的俄罗斯方块程序\2440init.s&&..............................................\2440lib.c&&..............................................\2440slib.s&&..............................................\gilr.c&&..............................................\inc\2440addr.h&&..............................................\...\2440addr.inc&&..............................................\...\2440lib.h&&..............................................\...\2440slib.h&&..............................................\...\2440usb.h&&..............................................\...\AudioDrv.h&&..............................................\...\bootpara.h&&..............................................\...\camdata.h&&..............................................\...\camdef.h&&..............................................\...\camif.h&&..............................................\...\camproset.h&&..............................................\...\def.h&&..............................................\...\dma.h&&..............................................\...\Font_Libs.c&&..............................................\...\IIC.h&&..............................................\...\lcd.h&&..............................................\...\LCD_LTS350Q1_PE1.h&&..............................................\...\MAIN.h&&..............................................\...\MCP2510.h&&..............................................\...\Memcfg.inc&&..............................................\...\memtest.h&&..............................................\...\mmu.h&&..............................................\...\Nand.h&&..............................................\...\Option.h&&..............................................\...\Option.inc&&..............................................\...\profile.h&&..............................................\...\sdi.h&&..............................................\...\Test_OV9650.h&&..............................................\...\WindowsXP_Wav.h&&..............................................\Lcdstart.c&&..............................................\LCD_test.c&&..............................................\main.c&&..............................................\mmuint.c&&..............................................\random.s&&..............................................\randtest.c&&..............................................\RTC.c&&..............................................\Rusian.c&&..............................................\RusianBlock.mcp&&..............................................\..........._Data\CWSettingsWindows.stg&&..............................................\................\Debug\TargetDataWindows.tdt&&..............................................\................\.....Rel\list.txt&&..............................................\................\........\ObjectCode\2440init.o&&..............................................\................\........\..........\2440lib.o&&..............................................\................\........\..........\2440slib.o&&..............................................\................\........\..........\Font_Libs.o&&..............................................\................\........\..........\FriendlyARM_pic_240x320.o&&..............................................\................\........\..........\gilr.o&&..............................................\................\........\..........\Lcdstart.o&&..............................................\................\........\..........\LCD_test.o&&..............................................\................\........\..........\main.o&&..............................................\................\........\..........\mmuint.o&&..............................................\................\........\..........\random.o&&..............................................\................\........\..........\RTC.o&&..............................................\................\........\..........\Rusian.o&&..............................................\................\........\..........\Touchpanel.o&&..............................................\................\........\..........\未命名.o&&..............................................\................\........\RusianBlock.axf&&..............................................\................\........\RusianBlock.bin&&..............................................\................\........\TargetDataWindows.tdt&&..............................................\................\Release\TargetDataWindows.tdt&&..............................................\src\2440init.s&&..............................................\...\2440lib.c&&..............................................\...\2440slib.s&&..............................................\...\Adc.c&&..............................................\...\AudioDrv.c&&..............................................\...\camif.c&&..............................................\...\camproset.c&&..............................................\...\comload.c&&..............................................\...\dma.c&&..............................................\...\eeprom.c&&..............................................\...\FriendlyARM_pic_240x320.c&&..............................................\...\IIC.c&&..............................................\...\IrDA.c&&..............................................\...\keyscan.c&&..............................................\...\LCD_LTS350Q1_PE1.c&&..............................................\...\LCD_NEC35.c&&..............................................\...\LCD_TFT_800x480.c&&..............................................\...\LCD_VGA_.c&&..............................................\...\Main.c&&..............................................\...\memtest.c&&..............................................\...\mmu.c&&..............................................\...\nand.c&&..............................................\...\profile.c&&..............................................\...\RTC.c&&..............................................\...\sdi.c&&..............................................\...\Test_MCP2510.c&&..............................................\...\Test_OV9650.c&&..............................................\...\Touchpanel.c&&..............................................\...\UDA1341.c&&..............................................\Touchpanel.c&&..............................................\RusianBlock_Data\DebugRel\ObjectCode&&..............................................\................\Debug&&..............................................\................\DebugRel&&..............................................\................\Release&&..............................................\inc&&..............................................\RusianBlock_Data
&近期下载过的用户:
&相关搜索:
&输入关键字,在本站182万海量源码库中尽情搜索:
&[] - 优龙FS2410板的实时时钟源码,可以实现终端显示秒.分.时.日.月.年等实时时间,开发平台为ADS1.2
&[] - 一个很好的画板程序
&[] - c#数据结构的PDF格式的电子书,我个人找了很久,觉得非常有用哦,特别是对初学者哦!
&[] - 嵌入式设计及Linux驱动开发指南书中的源代码,希望对学习嵌入式驱动开发的人有所帮助
&[] - 此工具是arm-linux-gcc交叉编译工具(cross-3.4.4),这个是我自己编译的,我试过,我用它编译了u-boot1.2.0没有问题,这个交叉编译器编了好长时间,我之前在网上搜了好长时间,但是没搜到,所以今天贡献出来,免得大家还得费时间去编译,我现在用是没有问题,如果有问题请多指教。希望
&[] - S3C2440的中文资料,比较适合初学嵌入式开发的人。
&[] - ARM9 S3C2410 在其中编写的一个贪吃蛇游戏,非常有用,适合初入ARM 嵌入式 学习,没有操作系统。基于ARM9的贪吃蛇游戏_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
15页免费24页免费12页2下载券3页&#165;2.0013页免费13页免费8页免费8页免费24页2下载券19页2下载券
喜欢此文档的还喜欢18页7下载券12页2下载券39页免费7页免费18页7下载券
基于ARM9的贪吃蛇游戏|
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢

我要回帖

更多关于 arm linux 开发环境 的文章

 

随机推荐