下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 贪吃蛇游戏c语言源代码

贪吃蛇游戏c语言源代码.doc

贪吃蛇游戏c语言源代码

我爱_棒棒糖
2019-06-10 0人阅读 举报 0 0 暂无简介

简介:本文档为《贪吃蛇游戏c语言源代码doc》,可适用于综合领域

#include<stdlibh>#include<graphicsh>#include<biosh>#include<dosh>#include<conioh>#defineEnter#defineESC#defineUP#defineDOWN#defineLEFT#defineRIGHT#ifdefcplusplus#defineCPPARGS#else#defineCPPARGS#endifvoidinterrupt(*oldhandler)(CPPARGS)voidinterruptnewhandler(CPPARGS)voidSetTimer(voidinterrupt(*IntProc)(CPPARGS))voidKillTimer(void)voidInitgra(void)voidTheFirstBlock(void)voidDrawMap(void)voidInitsnake(void)voidInitfood(void)voidSnakeHeadmv(void)voidFlag(int,int,int,int)voidGameOver(void)voidSnakeBodymv(void)voidSnakeBodyadd(void)voidPrntScore(void)voidTimer(void)voidWin(void)voidTheSecondBlock(void)voidFood(void)voidDsnkorfd(int,int,int)voidDelay(int)structSnake{intxintyintcolor}SnkstructFood{intxintyintcolor}Fdintflag=,flag=,flag=,flag=,flag=,flag=,checkx,checky,num,key=,Times,Score,Hscore,Snkspeed,TimerCounter,TureorFalsecharSco,Timevoidmain(){Initgra()SetTimer(newhandler)TheFirstBlock()while(){DrawMap()SnakeHeadmv()GameOver()SnakeBodymv()SnakeBodyadd()PrntScore()Timer()Win()if(key==ESC)breakif(key==Enter){cleardevice()TheFirstBlock()}TheSecondBlock()Food()Delay(Snkspeed)}closegraph()KillTimer()}voidinterruptnewhandler(CPPARGS){TimerCounteroldhandler()}voidSetTimer(voidinterrupt(*IntProc)(CPPARGS)){oldhandler=getvect(xc)disable()setvect(xc,IntProc)enable()}voidKillTimer(){disable()setvect(xc,oldhandler)enable()}voidInitgra(){intgd=DETECT,gminitgraph(gd,gm,"d:tc")}voidTheFirstBlock(){setcolor()settextstyle(,,)outtextxy(,,"TheFirstBlock")loop:key=bioskey()if(key==Enter){cleardevice()Initsnake()Initfood()Score=Hscore=Snkspeed=num=Times=key=TureorFalse=TimerCounter=Time=''Time=''Time=':'Time=''Time=''Time=''}elseif(key==ESC)cleardevice()elsegotoloop}voidDrawMap(){line(,,,)line(,,,)line(,,,)line(,,,)line(,,,)line(,,,)line(,,,)line(,,,)}voidInitsnake(){randomize()num=Snkx=random()Snkx=SnkxSnkxSnky=random()Snky=SnkySnkySnkcolor=Snkx=SnkxSnky=SnkySnkcolor=}voidInitfood(){randomize()Fdx=random()Fdx=FdxFdxFdy=random()Fdy=FdyFdyFdcolor=random()}voidSnakeHeadmv(){if(bioskey()){key=bioskey()switch(key){caseUP:Flag(,,,)breakcaseDOWN:Flag(,,,)breakcaseLEFT:Flag(,,,)breakcaseRIGHT:Flag(,,,)breakdefault:break}}if(flag){checkx=Snkxchecky=SnkyDsnkorfd(Snkx,Snky,)Snky=Dsnkorfd(Snkx,Snky,Snkcolor)}if(flag){checkx=Snkxchecky=SnkyDsnkorfd(Snkx,Snky,)Snky=Dsnkorfd(Snkx,Snky,Snkcolor)}if(flag){checkx=Snkxchecky=SnkyDsnkorfd(Snkx,Snky,)Snkx=Dsnkorfd(Snkx,Snky,Snkcolor)}if(flag){checkx=Snkxchecky=SnkyDsnkorfd(Snkx,Snky,)Snkx=Dsnkorfd(Snkx,Snky,Snkcolor)}}voidFlag(inta,intb,intc,intd){flag=aflag=bflag=cflag=d}voidGameOver(){intiif(Snkx<||Snkx>||Snky<||Snky>){cleardevice()setcolor()settextstyle(,,)outtextxy(,,"GameOver")loop:key=bioskey()if(key==Enter){cleardevice()TheFirstBlock()}elseif(key==ESC)cleardevice()elsegotoloop}for(i=i<numi){if(Snkx==SnkixSnky==Snkiy){cleardevice()setcolor()settextstyle(,,)outtextxy(,,"GameOver")loop:key=bioskey()if(key==Enter){cleardevice()TheFirstBlock()}elseif(key==ESC)cleardevice()elsegotoloop}}}voidSnakeBodymv(){inti,s,tfor(i=i<numi){Dsnkorfd(checkx,checky,Snkicolor)Dsnkorfd(Snkix,Snkiy,)s=Snkixt=SnkiySnkix=checkxSnkiy=checkycheckx=schecky=t}}voidFood(){if(flag){randomize()Fdx=random()Fdx=FdxFdxFdy=random()Fdy=FdyFdyFdcolor=random()flag=}Dsnkorfd(Fdx,Fdy,Fdcolor)}voidSnakeBodyadd(){if(Snkx==FdxSnky==Fdy){if(Snknumx>Snknumx){numSnknumx=SnknumxSnknumy=SnknumySnknumcolor=Fdcolor}elseif(Snknumx<Snknumx){numSnknumx=SnknumxSnknumy=SnknumySnknumcolor=Fdcolor}elseif(Snknumy>Snknumy){numSnknumx=SnknumxSnknumy=SnknumySnknumcolor=Fdcolor}elseif(Snknumy<Snknumy){numSnknumx=SnknumxSnknumy=SnknumySnknumcolor=Fdcolor}flag=Score}}voidPrntScore(){if(Hscore!=Score){setcolor()settextstyle(,,)outtextxy(,,"SCORE")setcolor()setfillstyle(,)rectangle(,,,)floodfill(,,)Sco=(char)(Score)Sco=''Hscore=Scoresetcolor()settextstyle(,,)outtextxy(,,Sco)}}voidTimer(){if(TimerCounter>){Time=(char)(Time)if(Time<''){Time=''Time=(char)(Time)}if(Time<''){Time=''Time=(char)(Time)}if(TureorFalse){setcolor()settextstyle(,,)outtextxy(,,"TIMER")setcolor()setfillstyle(,)rectangle(,,,)floodfill(,,)setcolor()settextstyle(,,)outtextxy(,,Time)TureorFalse=}if(Time==''Time==''Time==''){setcolor()settextstyle(,,)outtextxy(,,"GameOver")loop:key=bioskey()if(key==Enter){cleardevice()TheFirstBlock()}elseif(key==ESC)cleardevice()elsegotoloop}TimerCounter=TureorFalse=}}voidWin(){if(Score==)Timesif(Times==){cleardevice()setcolor()settextstyle(,,)outtextxy(,,"YouWin")loop:key=bioskey()if(key==Enter){cleardevice()TheFirstBlock()key=}elseif(key==ESC)cleardevice()elsegotoloop}}voidTheSecondBlock(){if(Score==){cleardevice()setcolor()settextstyle(,,)outtextxy(,,"TheSecondBlock")loop:key=bioskey()if(key==Enter){cleardevice()Initsnake()Initfood()Score=Hscore=Snkspeed=num=key=}elseif(key==ESC)cleardevice()elsegotoloop}}voidDsnkorfd(intx,inty,intcolor){setcolor(color)setfillstyle(,color)circle(x,y,)floodfill(x,y,color)}voidDelay(inttimes){intifor(i=i<=timesi)delay()}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/22

贪吃蛇游戏c语言源代码

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利