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

上传资料

关闭

关闭

关闭

封号提示

内容

首页 c++贪吃蛇源代码

c++贪吃蛇源代码.doc

c++贪吃蛇源代码

章鱼miko
2017-09-30 0人阅读 举报 0 0 暂无简介

简介:本文档为《c++贪吃蛇源代码doc》,可适用于IT/计算机领域

c贪吃蛇源代码#include<iostream>#include<windowsh>#include<stdlibh>#include<conioh>#include<timeh>ÊÓõÇÊä×öÖÖ×Ó#include<fstream>enumdir{upkey=,downkey,leftkey,rightkey}ÃÙÀàÐÍenumdirÎÇusingnamespacestdclassFence{public:voidInitFence()voidOutp()public:chargame}fÒåÔÏó,òòvoidFence::InitFence(){for(inti=i<i)for(intj=j<j){if(i==||i==||j==||j==)gameij='#'elsegameij=''}}ÏÔÊòòvoidFence::Outp(){for(inti=i<i){for(intj=j<j)cout<<gameij<<''cout<<endl}}ÉßáµãclassSnakeNode{private:intx,ySnakeNode*prior,*nextpublic:voidaddhead(intx,inty)intgetx()intgety()voiddeletetail()SnakeNode*nextreturn(){returnnext}}*head=,*tail=åÈëÍáµãvoidSnakeNode::addhead(intx,inty){SnakeNode*q=newSnakeNodeq>x=xq>y=yq>next=headq>prior=if(head)head>prior=qhead=qif(!tail)tail=headfgamexy='*'fÔÏóÉÒÔÔÚÒåFenceÀàÊÒåÇÒFenceÀàÔÚSnakeNodeÀàÇÒå}intSnakeNode::getx(){returnx}intSnakeNode::gety(){returny}ÉýÎáµãvoidSnakeNode::deletetail(){SnakeNode*p=tailfgametail>getx()tail>gety()=''ÑÎáµãµÄ×øêíʵÄ'*'ÖÃΪÕñif(tail==head)tail=head=else{tail=tail>priortail>next=}deletep}moveÒÆclassmove{public:move(stringn):Name(n){score=}dirpointÃÙäÁpoint:ØÖÆÏòintfoodxintfoodypublic:charmoving(string*n,int*s)voidchangepoint(char)ÄäÏòvoidgetfood()intscorereturn(intn){cout<<"ÍæÒÐÕÃû:"<<Namecout<<"ýÖ:"<<scorecout<<"leavel:"<<n}stringNameintscore}voidfileup(string*name,int*s)charmove::moving(string*n,int*s){inta,b,k=charYNstringswpintswpSnakeNode*p=head,*q,*za=head>getx()ȵÃÍáµãºá×øêb=head>gety()Íáµã×Ý×øêswitch(point){case:abreakcase:abreakcase:bbreakcase:bbreak}if(a==||b==||a==||b==){ÅÐÏÊÇñ×Çif(score>s){s=scoren=Namefor(inti=i<i){for(intj=ij<j){if(sj>si){swp=njswp=sjnj=nisj=sisi=swpni=swp}}}}fileup(n,s)cout<<"ttttgameover!!!nnn"<<endlq=pwhile(q>nextreturn()!=){q=q>nextreturn()z=qdeletez}head=tail=cout<<"ص˵(yn)bb"cin>>YNif(YN=='N'||YN=='n')exit()returnYN}if(a==foodxb==foody){Ôfoodhead>addhead(a,b)score=getfood()}else{head>addhead(a,b)åÈëÍáµãhead>deletetail()ÉýÎáµã}}voidhelp(){cout<<"tttïÖú"<<endlcout<<"tttÊÓÃ'W','S,'A,'DØÖÆÉÏÏÂ×óÓÒ"<<endlcout<<"tttÈÎÒâÏòüªÊÓÎÏ'Q'üÔÝÍÓÎÏ"<<endlcout<<"ttt'E'éïÖú,'R'üéÓÐÛñ"<<endlcout<<"tttÍËöÓÎÏÇë'T'ü!!!"<<endlcout<<"tttÈÎÒâüÍËöïÖú"<<endlwhile(!kbhit()){Sleep()}getch()system("cls")}voidmove::changepoint(charkeydown){switch(keydown){case'W':case'w':point=upkeybreakcase'S':case's':point=downkeybreakcase'A':case'a':point=leftkeybreakcase'D':case'd':point=rightkeybreakcase'Q':case'q':while(!kbhit()){Sleep()}breakcase'E':case'e':help()breakcase'T':case't':cout<<"ÕýÔÚÍËö"Sleep()exit()break}}voidmove::getfood(){srand((unsignedint)time())×öÖÖ×Ó(ÌÐòÔËÐÐÊä)foodx=rand()foody=rand()fgamefoodxfoody='*'}intleave(intn){cout<<"ttttÓÎÏÄÑÈðªª"<<endlcout<<"ttttµÇÄÑÈ"<<n<<endlcout<<"ttttÑÔñÄÑÈbb"cin>>nsystem("cls")returnn}intmenu(){intk=cout<<"ttttªÊÓÎÏ"<<endlcout<<"ttttÑÔñÄÑÈ"<<endlcout<<"ttttÍËöÓÎÏ"<<endlcout<<"ttttÓÎÏïÖú"<<endlcout<<"ttttÅÅÐÐñ"<<endlcout<<"ttttÊäÈëÄãµÄÑÔñbb"cin>>kreturnk}voidgameplay(intn,string*name,int*s){stringnacout<<"ÊäÈëÍæÒêÇÆ:"cin>>nasystem("cls")movem(na)charkfInitFence()head>addhead(,)head>addhead(,)head>addhead(,)mgetfood()fOutp()while(true){charkeydown=getch()getch()µØüÅÌÉÏÁȵÄ×ÖûüºÍÎÄþ<conioh>mchangepoint(keydown)while(!kbhit()){ÅÐÏÓÐÃÓÐüÂäÏÂsystem("cls")ÇåÆÁºÊýk=mmoving(name,s)if(k=='y'||k=='Y')gotoendfOutp()mscorereturn(n)Sleep(n*)}}end:system("cls")}voidfileup(string*name,int*score){ofstreamfileout("E:ÌÔÉßtxt")if(!fileout){cout<<"ÄÚæíÎó!!"system("pause")exit()}for(inti=i<scorei!=i){fileout<<endl<<namei<<endlfileout<<scorei}fileoutclose()}voidfileread(string*name,int*score){ifstreamfileget("E:ÌÔÉßtxt")charnintsinti=while(!filegeteof()){fileget>>nfileget>>snamei=nscorei=si}filegetclose()}voidbang(string*name,int*score){fileread(name,score)for(inti=i<i){cout<<i<<"ÍæÒ:"<<namei<<endlcout<<"ýÖ:"<<scorei<<endl}system("pause")system("cls")}intmain(){intn=,k=stringnameintscore={}while(n){k=menu()system("cls")switch(k){case:gameplay(n,name,score)breakcase:n=leave(n)breakcase:cout<<"ttttÍËöÓÎÏÖÐ"Sleep()exit()breakcase:help()breakcase:bang(name,score)break}}return}

用户评价(0)

关闭

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

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

提示

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

文档小程序码

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

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/13

c++贪吃蛇源代码

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利