|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题,求助各位大佬,也求助@Mr.屎壳螂,拜托,谢谢啦。
下列snakemove()函数中,加深、斜体、下划线的while的条件部分,为什么不是
while(q->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
而是 while(q->next->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
求解惑,拜托了,谢谢。。。
void snakemove()//蛇前进,上U,下D,左L,右R
{
cantcrosswall();
snake *nexthead;
nexthead=(snake*)malloc(sizeof(snake));
if(status==U)
{
nexthead->x=head->x;
nexthead->y=head->y-1;
if(nexthead->x==food->x && nexthead->y==food->y)//如果下一个有食物//
{
nexthead->next=head;
head=nexthead;
q=head;
while(q!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
score=score+add;
createfood();
}
else //如果没有食物//
{
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
Pos(q->next->x,q->next->y);
printf(" ");
free(q->next);
q->next=NULL;
}
}
if(status==D)
{
nexthead->x=head->x;
nexthead->y=head->y+1;
if(nexthead->x==food->x && nexthead->y==food->y) //有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
score=score+add;
createfood();
}
else //没有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
Pos(q->next->x,q->next->y);
printf(" ");
free(q->next);
q->next=NULL;
}
}
if(status==L)
{
nexthead->x=head->x-2;
nexthead->y=head->y;
if(nexthead->x==food->x && nexthead->y==food->y)//有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
score=score+add;
createfood();
}
else //没有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
Pos(q->next->x,q->next->y);
printf(" ");
free(q->next);
q->next=NULL;
}
}
if(status==R)
{
nexthead->x=head->x+2;
nexthead->y=head->y;
if(nexthead->x==food->x && nexthead->y==food->y)//有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
score=score+add;
createfood();
}
else //没有食物
{
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next!=NULL)
{
Pos(q->x,q->y);
printf("■");
q=q->next;
}
Pos(q->next->x,q->next->y);
printf(" ");
free(q->next);
q->next=NULL;
}
}
if(biteself()==1) //判断是否会咬到自己
{
endgamestatus=2;
endgame();
}
} |
|