贪吃蛇Word文档下载推荐.docx

上传人:b****1 文档编号:960029 上传时间:2023-04-29 格式:DOCX 页数:14 大小:18.13KB
下载 相关 举报
贪吃蛇Word文档下载推荐.docx_第1页
第1页 / 共14页
贪吃蛇Word文档下载推荐.docx_第2页
第2页 / 共14页
贪吃蛇Word文档下载推荐.docx_第3页
第3页 / 共14页
贪吃蛇Word文档下载推荐.docx_第4页
第4页 / 共14页
贪吃蛇Word文档下载推荐.docx_第5页
第5页 / 共14页
贪吃蛇Word文档下载推荐.docx_第6页
第6页 / 共14页
贪吃蛇Word文档下载推荐.docx_第7页
第7页 / 共14页
贪吃蛇Word文档下载推荐.docx_第8页
第8页 / 共14页
贪吃蛇Word文档下载推荐.docx_第9页
第9页 / 共14页
贪吃蛇Word文档下载推荐.docx_第10页
第10页 / 共14页
贪吃蛇Word文档下载推荐.docx_第11页
第11页 / 共14页
贪吃蛇Word文档下载推荐.docx_第12页
第12页 / 共14页
贪吃蛇Word文档下载推荐.docx_第13页
第13页 / 共14页
贪吃蛇Word文档下载推荐.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

贪吃蛇Word文档下载推荐.docx

《贪吃蛇Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《贪吃蛇Word文档下载推荐.docx(14页珍藏版)》请在冰点文库上搜索。

贪吃蛇Word文档下载推荐.docx

graphics.h>

stdlib.h>

ctype.h>

#defineLENsizeof(structlist)

#defineucharunsignedchar

intn,sco,r,t,speed=8800;

uchari,a,x1,y1,hit,long1=16,cycy=0,str1[200],xisu;

structlist

{

 

intx,y;

 

structlist*next,*last;

};

structlist*p1,*p2,*head,*eof1;

voidup(void);

voiddown();

voidleft();

voidright();

voidunit(uchar,uchar,uchar);

voidscore();

voiddl(int);

voidsave1();

voidload1();

voidsave();

main()

intdriver=VGA,mode=VGAHI;

unsignedcharss[8];

initgraph(&

driver,&

mode,"

c:

\\tc"

);

setfillstyle(1,8);

setcolor(8);

bar(2,2,600,400);

setfillstyle(1,7);

setcolor(7);

bar(117,117,170,140);

bar(118,118,170,140);

setcolor(14);

/*settextstyle(2,0,5);

*/

sprintf(ss,"

enter"

outtextxy(120,125,ss);

setcolor(0);

line(118,141,171,141);

line(118,142,172,142);

line(171,118,171,141);

line(172,118,172,142);

setfillstyle(1,14);

circle(15,15,10);

sprintf(ss,"

fast"

/*threestatuses,selectuse'

Tab'

*/

outtextxy(30,15,ss);

circle(15,55,10);

normol"

outtextxy(30,55,ss);

circle(15,95,10);

slow"

outtextxy(30,95,ss);

circle(15,15,6);

floodfill(15,15,14);

xisu=0;

do

{

a=getch();

if(a==9) 

/*Tab*/

a=8;

xisu++;

circle(15,15+(xisu%3)*40,6);

floodfill(15,15+(xisu%3)*40,14);

circle(15,15+((xisu-1)%3)*40,6);

floodfill(15,15+((xisu-1)%3)*40,7);

}

if((a==76)||(a==108)) 

/*'

L'

or'

l'

loadthestatusoflasttime*/

load1();

xisu=2;

gotoLOOP;

while(a!

=13);

dl(speed);

p2=(structlist*)malloc(LEN);

hit=1;

/*headofsnake*/

p1=p2;

head=p2;

p2->

x=20;

y=20;

last=NULL;

next=NULL;

rectangle(0,0,600,450);

setfillstyle(1,0);

bar(1,1,599,449);

speed=speed*(xisu%3+1);

for(i=0;

i<

15;

i++) 

/*16unitswhencreating*/

x=21+i;

unit(21+i,20,14);

p1->

next=p2;

last=p1;

eof1=p2;

unit(head->

x,head->

y,14);

/*srand(100);

LOOP:

while

(1)

if(hit==1) 

/*createarandomunit*/

randomize();

x1=random(30);

y1=random(20);

x1=x1+3;

y1=y1+3;

p2=head;

while(p1->

next!

=NULL)

if((x1==p2->

x)&

&

(y1==p2->

y)) 

/*maketheunitnotinthesnake*/

x1=random(30)+3;

y1=random(20)+3;

}/*ifin,new*/

else

p2=p1->

next;

unit(x1,y1,14);

hit=0;

if(kbhit()!

=0)

switch(a) 

/*dowithkey-down*/

case72:

up();

break;

case80:

down();

case75:

left();

case77:

right();

case83:

case115:

dl(500);

save1();

/*'

S'

s'

savestatusandexit*/

if(cycy==1)

break;

a=getch();

while((a>

14)||(a<

13));

/*while'

Enter'

exit*/

closegraph();

voidup(void)

p2=head->

if((head->

x==p2->

(head->

y-1==p2->

y))/*ifhitself,out*/

score();

if((hit==0)&

x==x1)&

y-1==y1)) 

/*ifhitnewunit,add*/

x=x1;

y=y1;

next=head;

head->

last=p2;

head=p2;

hit=1;

long1++;

p2=eof1;

eof1=p2->

last;

/*p2->

eof1->

/*eof1disappear,headadd1unit*/

unit(p2->

x,p2->

y,0);

x=head->

x;

y=head->

y-1;

if(p2->

y<

1)

voiddown(void)

y+1==p2->

/*hitself,out*/

y+1==y1)) 

/*hitunit,add*/

y+1;

y>

=30) 

/*hitwall,out*/

voidleft(void)

x-1==p2->

y==p2->

y))

x-1==x1)&

y==y1))

p2=eof1;

x-1;

y;

x<

dl(speed);

voidright(void)

x+1==p2->

x+1==x1)&

x+1;

x>

=40)

voiddl(inta)

intr,n;

for(r=0;

r<

a;

r++)

for(n=0;

n<

6000;

n++)

n++;

n--;

voidunit(ucharx,uchary,ucharcolor)

setfillstyle(1,color);

setcolor(color);

bar(x*15,y*15,(x+1)*15-2,(y+1)*15-2);

voidscore(void)

ucharss[20];

if(long1>

50)

sco=(long1-50)*3+(long1-30)*2+14;

elseif(long1>

30)

sco=(long1-30)*2+14;

sco=long1-16;

yourscoreis%d"

sco);

outtextxy(50,50,ss);

cycy=1;

save();

voidsave(void)

FILE*fp;

inti;

i=0;

fp=fopen("

snascore.txt"

"

rb+"

i=(int)(fgetc(fp))-48;

if(fp==NULL)

fclose(fp);

if(i<

sco)

wb+"

fprintf(fp,"

%d"

fclose(fp);

printf("

\n"

Yourscore:

%darethehighest!

"

/* 

getch();

voidsave1()

FILE*fl1;

dl(1500);

p1=head;

p2=p1;

while(p1!

str1[i]=(char)(p1->

x+30);

str1[i+1]=(char)(p1->

y+30);

i=i+2;

p1=p2->

fl1=fopen("

snasave.txt"

w+"

if(fl1!

fwrite(str1,i,1,fl1);

fclose(fl1);

bad\n"

voidload1()

intcc;

r"

fseek(fl1,0,SEEK_SET);

while(feof(fl1)==0)

str1[i++]=fgetc(fl1);

cc=i-1;

/*fread(str1,200,1,fl1);

cc=ftell(fl1);

setcolor(8);

x=(int)(str1[0])-30;

y=(int)(str1[1])-30;

xisu=1;

for(i=2;

cc;

i+=2)

x=(int)(str1[i])-30;

y=(int)(str1[i+1])-30;

p1->

long1=cc/2;

}_

里面有个速度设置,这样一句话:

“speed=8800;

”其实是个延迟时间,各位根据电脑CPU的速度可以改动一下,到你自己舒服为止哦。

我做了个存储功能,记分功能,还可以加一些其他功能的

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 营销活动策划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2