




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/*运行是按任意键开始,不过呢,反向也算输哟*/#include #include #include #include #include #include #include #define UP 0x4800#define DOWN 0x5000#define LEFT 0x4b00#define RIGHT 0x4d00#define ESC 0x011b#define SPACE 0x3920#define M 25#define N 25#define blue 1#define green 2#define red 4#define yellow 14#define yes 1#define no 0struct snake int l,t,r,b; int color; int direction; /*0不动 1 上 2下 3左 4右 蛇头的方向 */qu1M*N;int d4=-25,25,-1,1; /*蛇头移动的方向 */int length; /*蛇身长度 */int speed=50000000; /*移动的速度 */int head; /*蛇头的位置 */int food;int appear;int key;int direct;int all_food;int tail,mark;int Q=1;void draw_map() /*地图 */int i,j,n=17,v=1;int a2525;for(i=0;i=24;i+) for(j=0;j=24;j+) if(j=0|j=24|i=24|i=0) aij=0; /* 0 stans for block */ else aij=1; for(i=0;i=24;i+) for(j=0;j=24;j+) if(aij=0) setfillstyle(1,green); qu1v.color=green; if(aij=1) setfillstyle(1,blue); qu1v.color=blue; qu1v.l=20+n*j; qu1v.t=20+n*i; qu1v.r=35+n*j; qu1v.b=35+n*i; qu1v.direction=0; bar( qu1v.l, qu1v.t, qu1v.r, qu1v.b); v+; void draw_snake() int v,j; v=head=303; all_food=10; length=0; for(j=0;j=1;j+,v-) setfillstyle(1,yellow); bar( qu1v.l, qu1v.t, qu1v.r, qu1v.b); qu1v.color=red; qu1v.direction=4; length+; void diamond()float t;int x0=540,y0=165;int n=16,i,j,r=90;int x50,y50;t=6.28318/n; for(i=0;in;i+) xi=x0+r*cos(i*t); yi=y0+r*sin(i*t);setcolor(yellow); for(i=0;i=n-2;i+) setcolor(YELLOW); for(j=1;j=n-1;j+) line(xi,yi,xj,yj);main()int gdrive=VGA; int gmode=VGAHI;int class;initgraph(&gdrive,&gmode,c:tc); setcolor(LIGHTRED);outtextxy(450,280,SPACE :Pause); outtextxy(450,300,ESC :Exit); outtextxy(450,320,Left); outtextxy(450,340,Right); outtextxy(450,360,Up ); outtextxy(450,380,Down ); outtextxy(450,400,THE FOUR KEYES TO MOVE); setcolor(YELLOW);outtextxy(40,2, Welcome to snake game and Please any key begin !); outtextxy(450,33,Class:); outtextxy(450,51,All_food:);randomize();diamond();for(class=1;class=10) printf(%d,all_food); else printf(0%d,all_food); if(all_food=0) setcolor(red+class); outtextxy(50,450, Congratulation and Please any key goto the next! ); break; if(appear=no) do food=random(600); while(qu1food.color=yellow|qu1food.color=red|qu1food.color=green|food=0); qu1food.color=red; qu1food.direction=0; setfillstyle(1,red); bar(qu1food.l, qu1food.t, qu1food.r, qu1food.b); appear=yes; star: do tail=head; mark=length; switch(qu1head.direction) case 1: head=head+d0; direct=1; break; case 2: head=head+d1; direct=2; break; case 3: head=head+d2; direct=3; break; case 4: head=head+d3; direct=4; if(qu1head.direction!=0|qu1head.color=green) /*撞墙或撞自己*/ if(Q=1) setcolor(red); outtextxy(450,200, Any key to exit ! ); getch();closegraph(); exit(0); else Q=1; qu1head.direction=direct; if(head=food) appear=no; delay(speed); all_food-; length+; continue; qu1head.color=yellow; setfillstyle(1,yellow); bar(qu1head.l, qu1head.t, qu1head.r, qu1head.b); setfillstyle(1,red); bar( qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b); for(;length1;length-) tail=tail-dqu1tail.direction-1; setfillstyle(1,blue); bar( qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b); qu1tail.color=blue; qu1tail.direction=0; length=mark; delay(speed); while(!kbhit(); key=bioskey(0); if(qu1head.direction=1) if(key=UP) Q=0; continue; if(qu1head.direction=2) if(key=DOWN) Q=0; continue; if(qu1head.direction=3) if(key=LEFT) Q=0; continue; if(qu1head.direction=4) if(key=RIGHT) Q=0; continue; tail=head; mark=length; switch(key) case UP : head=head+d0; direct=1; break; case DOWN : head=head+d1; direct=2; break; case LEFT : head=head+d2; direct=3; break; case RIGHT: head=head+d3; direct=4; break; case ESC : exit(0); case SPACE: getch(); goto star; /* 暂停*/ if(qu1head.direction!=0|qu1head.color=green) /*撞墙或撞自己*/ if(Q=1) setcolor(red); outtextxy(450,200, Any key to exit ! ); getch();closegraph(); exit(0); else Q=1; qu1head.direction=direct; if(head=food) appear=no; delay(speed); all_food-; length+; continue; qu1head.color=yellow; setfillstyle(1,yellow); bar(qu1head.l, qu1head.t, qu1head.r, qu1head.b); setfillstyle(1,red); bar( qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b); for(;length1;length-) tail=tail-dqu1tail.direction-1; setfillstyle(1,blue); bar( qu1tai
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人工智能教育培训手册
- 工作总结:提升专业能力业务水平
- 2025新疆克拉玛依市面向高校应届毕业生招聘事业编制高中教师48人笔试备考试题及答案解析
- 农学中的农业科技示范园规划设计
- 2025年天津安全工程师安全生产法事故直接原因的分析考试试题
- 2025年唐山市市直事业单位招聘277人笔试备考题库及参考答案详解一套
- 2025年事业单位笔试-江苏-江苏审计学(医疗招聘)历年参考题库含答案解析
- 2025年有色金属行业资源循环利用产业链产业链金融创新报告
- 2025四川达州宣汉县养老服务中心招聘临时工作人员10人笔试备考试题及答案解析
- 2025年医学遗传学病例诊断与咨询考核试卷答案及解析
- 常见肿瘤AJCC分期手册第八版(中文版)
- 绿色施工专项方案(技术方案)
- 《CAD CAM应用技术(CAXA 2020)》 课件 模块1-3 CAXA制造工程师2020软件基本操作、二维图形的绘制、曲面建模
- 挂篮检查验收记录表
- 专业技术职务资格申报材料真实性承诺书
- 快递员国家职业技能标准2019年版
- 脓毒症指南课件
- 生产副总经理岗位职责标准版本(五篇)
- 对颈椎概念和命名的再认识
- 2023年河北科技工程职业技术大学选聘15人笔试参考题库含答案解析
- 淀粉与变性淀粉知识
评论
0/150
提交评论