C语言编的贪吃蛇, W控制蛇往上走的这段看不懂啊 有哪位大神能解答一下?
intx[200],y[200],i,j,food,life,m,n;charc;while(1){system("cls");begin();x[0]=10;y[0]=...
int x[200],y[200],i,j,food,life,m,n;
char c;
while(1)
{
system("cls");
begin();
x[0]=10;
y[0]=10;
i=0;
food=0;
life=1;
gotoxy(x[0],y[0]);
printf("%c",2);//设置初始蛇头的位置
c='w';
do
{
while(!kbhit())//检查当前是否有键盘输入,若有则返回一个非0值,否则返回0. 包含头文件: include <conio.h>
{
if(c=='q')
{
i++;
x[i]=x[i-1];
y[i]=y[i-1]-1;
gotoxy(x[i],y[i]);
printf("%c",2);
}
switch(c)
{
case 'w':
for(j=0;j<=i;j++)
{
gotoxy(x[j],y[j]);
printf(" ");
}
for(j=i;j>0;j--)
{
x[j]=x[j-1];
y[j]=y[j-1];
}
y[0]=y[0]-1;
for(j=0;j<=i;j++)
{
gotoxy(x[j],y[j]);
printf("%c",2);
}
if(food==0)
{
m=foodxy();
n=foodxy();
food=1;
gotoxy(m,n);
printf("%c",3);
} //没有食物时制造食物
if(m==x[0]&&n==y[0])
{
gotoxy(m,n);
printf("%c",2);
i++;
x[i]=x[i-1]-1;
y[i]=y[i-1];
gotoxy(x[i],y[i]);
printf("%c",2);
food=0;
}//吃到食物时身体长度+1
gotoxy(x[0],y[0]);
break; 展开
char c;
while(1)
{
system("cls");
begin();
x[0]=10;
y[0]=10;
i=0;
food=0;
life=1;
gotoxy(x[0],y[0]);
printf("%c",2);//设置初始蛇头的位置
c='w';
do
{
while(!kbhit())//检查当前是否有键盘输入,若有则返回一个非0值,否则返回0. 包含头文件: include <conio.h>
{
if(c=='q')
{
i++;
x[i]=x[i-1];
y[i]=y[i-1]-1;
gotoxy(x[i],y[i]);
printf("%c",2);
}
switch(c)
{
case 'w':
for(j=0;j<=i;j++)
{
gotoxy(x[j],y[j]);
printf(" ");
}
for(j=i;j>0;j--)
{
x[j]=x[j-1];
y[j]=y[j-1];
}
y[0]=y[0]-1;
for(j=0;j<=i;j++)
{
gotoxy(x[j],y[j]);
printf("%c",2);
}
if(food==0)
{
m=foodxy();
n=foodxy();
food=1;
gotoxy(m,n);
printf("%c",3);
} //没有食物时制造食物
if(m==x[0]&&n==y[0])
{
gotoxy(m,n);
printf("%c",2);
i++;
x[i]=x[i-1]-1;
y[i]=y[i-1];
gotoxy(x[i],y[i]);
printf("%c",2);
food=0;
}//吃到食物时身体长度+1
gotoxy(x[0],y[0]);
break; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询