#include <stdio.h>
#include <stdlib.h>
main()
{int a,b,x=40,y=12,i=0,score=0,count=0,right=1,up=0;
int eggs[80][25],snakex[50]={0},snakey[50]={0};
long int k=0;
clrscr();
for (a=1;a<=80;a++)
{for (b=1;b<=24;b++)
{if (a==1||a==80||b==1||b==24) gotoxy(a,b),printf("#"),eggs[a][b]=-1;}
}
for (a=2;a<=79;a++)
{for (b=2;b<=23;b++)
gotoxy(a,b),eggs[a][b]=0;}
for (a=2;a<=79;a++)
{for (b=2;b<=23;b++)
{i=random(100);
if (i<=2) gotoxy(a,b),printf("*"),eggs[a][b]=1;
}
}
snakex[1]=40,snakey[1]=12,eggs[40][12]=-1;
/*gotoxy(40,12),putch('@');*/
for(;1;)
{snakex[1]=snakex[1]+right,snakey[1]=snakey[1]+up;
if (eggs[snakex[1]][snakey[1]]==1) score=score+1;
if (eggs[snakex[1]][snakey[1]]==-1) break;
if (eggs[snakex[1]][snakey[1]]==0)
{count=score+1;
if (count==1) gotoxy(snakex[2],snakey[2]),putch(' '),eggs[snakex[2]][snakey[2]]=0;
else
gotoxy(snakex[count],snakey[count]),putch(' '),eggs[snakex[count]][snakey[count]]=0;}
gotoxy(snakex[1],snakey[1]),putch('@'),eggs[1][1]=-1;
for(count=score+1;count>=3;count--)
{snakex[count]=snakex[count-1];
snakey[count]=snakey[count-1];
}
snakex[2]=snakex[1]-right,snakey[2]=snakey[1]-up;/*这句我认为放的地方不太对,请各位大侠帮我弄弄*/
/****************************************************************************/
for (k=0;k<=30000000;k++);
if (kbhit())
{i=getch();
if (i==0) i=getch();
}
if (right==1||right==-1)
{if (i==75||i==77);
if (i==72) right=0,up=-1;
if (i==80) right=0,up=1;
}
if (up==1||up==-1)
{if (i==72||i==80);
if (i==75) right=-1,up=0;
if (i==77) right=1,up=0;
}
}
clrscr();
gotoxy(25,12);
printf("Your Score is %d",score);
getch();
}
/*还有一个是弄了之后,好像eggs=-1没有用了,这是怎么一会事,请帮我看看先,我弄了好久了,实在不行.*/