- 13
- 0
- 约1.35万字
- 约 8页
- 2019-01-27 发布于广东
- 举报
基于C语言实现的贪吃蛇游戏完整实例代码.doc
基于C语言实现的贪吃蛇游戏完整实例代码
这篇文章主要介绍了基于C语言实现的贪吃蛇游戏完整实例代码,对于学习游戏开发的朋友 有一定的借鉴价值,需要的朋友可以参考下
本文以实例的形式讲述了基于c语言实现的贪吃蛇游戏代码,这是一个比较常见的游戏,代 码备有比较详细的注释,对于读者理解有一定的帮助。
贪吃蛇完整实现代码如下:
#include graphics.h#include vconio.h#include stdlib.h#include dos.h#define NULL
0#define UP 18432#define DOWN 20480#define LEFT 19200#define RIGHT 19712#define ESC
283#define ENTER 7181 struct snakefint centerx; int centery; int newx; int newy; struct snake *next;};struct snake *head; int grade=60; /*控制速度的*******/int a,b;
严背静遮的位置*/void *farlz*far2/far3/far4; /*蛇身指针 背静遮的指针
虫子 */int sizel,size2,size3,size4; /* ** 全局变量 **/int ch=RIGHT;
/**************存按键 开始蛇的方向为 RIGHT***********/int chy=RIGHT; int flag=O;
/***** ****
判
断
是
否
退
出
游
戏
**************/j nt con trol=4*
/* * * ********
判
断上次
方
向
和下;
欠方
向
不冲突 ***/int nextshow=l;
/******* 拎
制
下
次
蛇
身
是否
显
示
***************/)nt see nterx;
/***************
随即矩
形
中
心坐
标 ***************/jnt scentery;int sx;
/*******在a b未改变前 得到他们的值 保证随机矩形也不在此出现*******/jnt sy;
**************************************************/void snakede(){ struct snake *pl,*p2; head=pl=p2=(struct snake *)malloc(sizeof(struct snake)); pl-centerx=80; pl-newx=80; pl-centery二58; pl-newy=58; pl=(struct snake *)malloc(sizeof(struct snake));
p2-n ext=pl; pl-ce nterx 二 58; pl-n ewx=58; pl-ce ntery=58; pl-newy=58;
*******************/vo | d/*************游戏开始界面,可以选择速度welcome!)**********{ int key;
*******************/vo | d
/*************游戏开始界面,可以选择速度
welcome!)
**********
{ int key;
int size; int x=240; int y=300; int f; void *buf; setfillstyle(SOLID_FILL,BLUE); bar(9 100,11 乙 125);
setfillstyle(SOLID_FILL,RED); bar(98J12J12J:L4); setfillstyle(SOLID_FILL,GREEN);
bar(100z100,110z125); size=imagesize(98,100,112,125); buf=malloc(size);
getimage(98/100/112,125,buf); cleardevicef); setf i 11 sty I e (SO LI D_F ILL, B LU E);
bar(240,300,390,325); outtextxy(193,310/speecT); setfillstyle(SOLID_FILL,RED);
bar(240,312,390,314); setcolor(YELLOW); outtextxy(240,330/DOWN”); outtextxy(390,330/UP“);
outtextxy(240,360,ENTER to start
原创力文档

文档评论(0)