c语言贪吃蛇游戏源码.pdf

上传人:l*** 文档编号:73151193 上传时间:2023-02-15 格式:PDF 页数:8 大小:133.49KB
返回 下载 相关 举报
c语言贪吃蛇游戏源码.pdf_第1页
第1页 / 共8页
c语言贪吃蛇游戏源码.pdf_第2页
第2页 / 共8页
点击查看更多>>
资源描述

《c语言贪吃蛇游戏源码.pdf》由会员分享,可在线阅读,更多相关《c语言贪吃蛇游戏源码.pdf(8页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、/*运行是按任意键开始,不过呢,反向也算输哟*/#include#include#include#include#include#include#include#define UP 0 x4800#define DOWN 0 x5000#define LEFT 0 x4b00#define RIGHT 0 x4d00#define ESC 0 x011b#define SPACE 0 x3920#define M 25#define N 25#define blue 1#define green 2#define red 4#define yellow 14#define yes 1#defi

2、ne no 0struct snake int l,t,r,b;int color;int direction;右 蛇头的方向*/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;/*0 不动 1 上 2 下 3 左 4蛇头移动的方向*/*蛇身长度*/*移动的速度*/蛇头的位置*/地图*/*/*/*int

3、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 stansfor 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(q

4、u1v.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

5、=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);ou

6、ttextxy(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,al

7、l_food);else printf(0%d,all_food);if(all_food=0)setcolor(red+class);outtextxy(50,450,Congratulation andPlease 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,r

8、ed);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)/*撞墙或撞自

9、己*/if(Q=1)setcolor(red);outtextxy(450,200,Any key toexit!);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(qu

10、1tail.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(

11、qu1head.direction=2)if(key=DOWN)0;direct=1;break;DOWN:direct=2;break;LEFT:direct=3;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 case case head=head+d UP:head=head+d1;head=head+d2;break;caseRIGHT:he

12、ad=head+d3;direct=4;break;case ESC:exit(0);case SPACE:getch();gotostar;/*暂停*/if(qu1head.direction!=0|qu1head.color=green)/*撞墙或撞自己*/if(Q=1)setcolor(red);outtextxy(450,200,Any key toexit!);getch();closegraph();exit(0);else Q=1;qu1head.direction=direct;if(head=food)appear=no;delay(speed);all_food-;leng

13、th+;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);speed=speed-15000;setcolor(LIGHTRED);outtextxy(200,460,You are wining the game.);getch();closegraph();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 工作报告

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com