• 2004-04-05

    C语言写的贪吃蛇 - [我的精品软件园]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://jiamingsoft.yourblog.org/logs/137586.html

    这个是用C语言编写的贪吃蛇游戏哦,原创原创,TurboC下写的,去年的作品,有源代码的哦 源文件下载:贪吃蛇源文件下载 可执行文件下载:贪吃蛇游戏下载 截图 /**********************************************************/ /* 本程序在Turbo C 2.0下编译通过 */ /* */ /* 文件名: snake.c */ /**********************************************************/ /**********************************************************/ /* 程序中用到的库函数所在头文件应用 #include 命令包含进来 */ #include<graphics.h> #include<bios.h> #include<stdio.h> #include<stdlib.h> #include<time.h> #include<dos.h> #include<conio.h> #include<ctype.h> /**********************************************************/ /* 定义符号常量 */ #define len sizeof(struct snake) #define Q (*que) #define FILENAME "c:\\person.dat" /*文件保存路径*/ /**********************************************************/ /* 定义数据结构*/ /*蛇节点*/ struct snake_base { int x; int y; }; /*队列节点 */ struct snake { struct snake_base data; struct snake *next; }; /*队列 */ struct queue { struct snake *front,*rear; }; /*排行榜结构*/ struct person { char name[20]; int score; }; /**********************************************************/ /* 定义全局变量 */ struct person per[5]; /**********************************************************/ /************************************************************************************/ /*自定义函数原型说明 */ void inques(struct queue *que,int x,int y); /*入队函数*/ void creatque(struct queue Q,int m); /*创建队列*/ struct snake_base delete(struct queue *que); /*出队函数,返回值为一个蛇节点*/ void *picture(int type); /*绘制方块函数*/ void draw(int x,int y,void *p); /*从图形缓存中读出数据,并显示在屏幕上*/ int search(int x,int y,struct snake *tmpHead); /*判断蛇头是否与蛇身相遇函数*/ void creat_menu(); /*产生主界面*/ void ReadFiles(); /*从文件中读取记录信息*/ void WriteFiles(struct person *); /*将记录写入文件中*/ void InitScoreFiles(); /*初始化记录文件*/ void CompareScore(struct person ); /*排行榜按分数进行排序*/ void pain_board(); /*绘制排行榜函数*/ void pain_gameover(); /*绘制游戏结束时的图形*/ void HelpMessage(); /***********************************************************************************/ /**********************************************************/ /*主函数*/ void main() { int gm=VGAHI,gd=VGA; int mark,level,m,key,hi,lo,h; int s1,m1,i,j,k,xn,yn,flag,bl; long time; unsigned s2; void *p1,*p2; char ch,string[3]; struct person CurPerson; struct queue *que; struct snake *q; struct snake_base x1; struct time t[1]; do { flag=1;bl=0;que=NULL; /*下面两行为初始化游戏变量*/ time=30000;mark=0;level=1;m=0; gettime(t);/*初始化随机数*/ s1=t[0].ti_sec; m1=t[0].ti_min; s2=s1*m1; srand(s2); initgraph(&gd,&gm,""); p1=picture(1); p2=picture(0); creatque(que,3); creat_menu(); itoa(mark,string,10); setcolor(15); outtextxy(545,30,string); itoa(level,string,10); outtextxy(545,50,string); q=Q.front->next; for(k=0;k<=2;k++) /*遍历队列,绘制初始状态的蛇身*/ { draw(q->data.x,q->data.y,p1); if(k==2) { /*队尾节点为蛇头,取出赋值给i,j*/ i=q->data.x;j=q->data.y; } q=q->next; } do { xn=((unsigned long)rand())%31+1; /*随即产生两个坐标,作为新节点*/ yn=((unsigned long)rand())

    收藏到:Del.icio.us




发表评论

您将收到博主的回复邮件
记住我