该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
}
if(flag2&&Snk[i].direction!=1)
{checkx=Snk[0].x;
checky=Snk[0].y;
Dsnkorfd(Snk[0].x,Snk[0].y,0);
Snk[0].y+=20;
Dsnkorfd(Snk[0].x,Snk[0].y,Snk[0].color);
}
if(flag3&&Snk[i].direction!=4)
{checkx=Snk[0].x;
checky=Snk[0].y;
Dsnkorfd(Snk[0].x,Snk[0].y,0);
Snk[0].x-=20;
Dsnkorfd(Snk[0].x,Snk[0].y,Snk[0].color);
}
if(flag4&&Snk[i].direction!=3)
{checkx=Snk[0].x;
checky=Snk[0].y;
Dsnkorfd(Snk[0].x,Snk[0].y,0);
Snk[0].x+=20;
Dsnkorfd(Snk[0].x,Snk[0].y,Snk[0].color);
}
}
void Flag(int a,int b,int c,int d)
{flag1=a;flag2=b;flag3=c;flag4=d;
}
void GameOverOrWin()
{int i;
if(Snk[0].x<10||Snk[0].x>630||Snk[0].y<10||Snk[0].y>470)
{cleardevice();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(180,180,"YOU`LOST");
setcolor(YELLOW);
settextstyle(3,0,4);
outtextxy(100,240,"again`please`press`the`ENTER`key");
outtextxy(110,280,"quit`please`press`the`ESC`key");
key=bioskey(0);
}
else for(i=3;i
{if(Snk[0].x==Snk[i].x&&Snk[0].y==Snk[i].y)
{cleardevice();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(180,180,"YOU`LOST");
setcolor(YELLOW);
settextstyle(3,0,4);
outtextxy(100,240,"again`please`press`the`ENTER`key");
outtextxy(110,280,"quit please press the ESC key");
key=bioskey(0);
}
}
if(num>=20)
{cleardevice();
setcolor(GREEN);
settextstyle(0,0,4);
outtextxy(180,180,"YOU`WIN");
setcolor(YELLOW);
settextstyle(3,0,4);
outtextxy(100,240,"again`please`press`the`ENTER`key");
outtextxy(110,280,"quit`please`press`the`ESC`key");
key=bioskey(0);
}
}
void Snake_Bodymv()
{int i,s,t;
for(i=1;i
{Dsnkorfd(checkx,checky,Snk[i].color);
Dsnkorfd(Snk[i].x,Snk[i].y,0);
s=Snk[i].x;
t=Snk[i].y;
Snk[i].x=checkx;
Snk[i].y=checky;
checkx=s;
checky=t;
}
}
void Food()
{if(flag5)
{randomize();
Fd.x=random(580);
Fd.x=Fd.x-Fd.x%20+30;
Fd.y=random(420);
Fd.y=Fd.y-Fd.y%20+30;
Fd.color=random(14)+1;
flag5=0;
}
Dsnkorfd(Fd.x,Fd.y,Fd.color);
}
void Snake_Bodyadd()
{if(Snk[0].x==Fd.x&&Snk[0].y==Fd.y)
{if(Snk[num-1].x>Snk[num-2].x)
{num++;
Snk[num-1].x=Snk[num-2].x+20;
Snk[num-1].y=Snk[num-2].y;
Snk[num-1].color=Fd.color;
}
else
if(Snk[num-1].x
{num++;
Snk[num-1].x=Snk[num-2].x-20;
Snk[num-1].y=Snk[num-2].y;
Snk[num-1].color=Fd.color;
}
else
if(Snk[num-1].y>Snk[num-2].y)
{num++;
Snk[num-1].x=Snk[num-2].x;
Snk[num-1].y=Snk[num-2].y+20;
Snk[num-1].color=Fd.color;
}
else
if(Snk[num-1].y
{num++;
Snk[num-1].x=Snk[num-2].x;
Snk[num-1].y=Snk[num-2].y-20;
Snk[num-1].color=Fd.color;
}
flag5=1;
}
}
void Dsnkorfd(int x,int y,int color)
{setcolor(color);
setfillstyle(1,color); /*填充一定范围的函数*/
rectangle(x,y,x+15,y+15);
floodfill(x,y,color);
}
void DrawMap()
{line(5,6,635,6);
line(5,6,5,479);
line(5,479,635,479);
line(635,475,635,6);
}