一个贪吃蛇源码

一个贪吃蛇源码

ID:37660495

大小:74.50 KB

页数:8页

时间:2019-05-28

一个贪吃蛇源码_第1页
一个贪吃蛇源码_第2页
一个贪吃蛇源码_第3页
一个贪吃蛇源码_第4页
一个贪吃蛇源码_第5页
资源描述:

《一个贪吃蛇源码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、#include#include#include#include#include#includeintgrade=5,point=0,life=3;voidset(),menu(),move_head(),move_body(),move(),init_insect(),left(),upon(),right(),down(),init_graph(),food_f(),ahead(),crate();structbug{intx;inty;structbug*last;str

2、uctbug*next;};structfd{intx;inty;intjudge;}food={0,0,0};structbug*head_f=NULL,*head_l,*p1=NULL,*p2=NULL;voidmain(){charch;initgraph(800,600);set();init_insect();while(1){food_f();Sleep(grade*10);setcolor(BLACK);circle(head_l->x,head_l->y,2);setcolor(WHITE);move_body();if(kbhit()){ch=getch();if(ch==

3、27){ahead();set();}elseif(ch==-32){switch(getch()){case72:upon();break;case80:down();break;case75:left();break;case77:right();break;}}elseahead();}else{ahead();}if(head_f->x==food.x&&head_f->y==food.y){Sleep(100);crate();food.judge=0;point=point+(6-grade)*10;if(food.x<30

4、

5、food.y<30

6、

7、food.x>570

8、

9、foo

10、d.y>570)life++;menu();}if(head_f->x<5

11、

12、head_f->x>595

13、

14、head_f->y<5

15、

16、head_f->y>595){Sleep(1000);life--;food.judge=0;init_graph();init_insect();menu();}for(p1=head_f->next;p1!=NULL;p1=p1->next){if(head_f->x==p1->x&&head_f->y==p1->y){Sleep(1000);life--;food.judge=0;init_graph();init_insect();menu();bre

17、ak;}}if(life==0){outtextxy(280,300,"游戏结束!");getch();return;}move();};}voidinit_graph(){clearviewport();setlinestyle(PS_SOLID,1,5);rectangle(2,2,600,598);setlinestyle(PS_SOLID,1,1);}voidset(){init_graph();outtextxy(640,50,"1、开始/返回");outtextxy(640,70,"2、退出");outtextxy(640,90,"3、难度");outtextxy(640,110

18、,"4、重新开始");switch(getch()){case'1':menu();setcolor(GREEN);circle(food.x,food.y,2);setcolor(WHITE);return;case'2':exit(0);break;case'3':outtextxy(700,90,":12345");grade=getch()-48;set();break;case'4':food.judge=0,grade=5;point=0;life=3;init_insect();menu();break;default:outtextxy(250,300,"输入错误!");se

19、t();break;}}voidmenu(){charstr[20],str1[]={"分数:"},str2[]={"难度:"},str3[]={"生命值:"};init_graph();sprintf(str,"%d",point);strcat(str1,str);outtextxy(640,50,str1);sprintf(str,"%d",grade);strcat(str2,str);outtext

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。