我是C编程的新手,找到了一个蛇游戏代码,但是我不明白在这里创建尾巴的逻辑部分是代码
void Logic()
{
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for (int i = 1; i < nTail; i++)
{
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
实际上,根据我的理解,我不了解 循环部分
1)prev2X = tailX[1] // prev2X = 0
2)prev2Y = tailY[1] // again 0
3)tailX[1] = prevX // assuming value of prevX 5
4)tailY[1] = prevY // assuming value of prevY 6
5)prevX = prev2X // prevX =0
6)prevY = prev2Y // again 0
第二次迭代
1)prev2X = tailX[2] // prev2X = 0
2)prev2Y = tailY[2] // again 0
3)tailX[1] = prevX // prevX is 0 bcz of 1st iteration
4)tailY[1] = prevY // same 0
5)prevX = prev2X // 0
6)prevY = prev2Y // again 0
但是我知道这是错误的,因此此逻辑如何工作,请至少逐步解释两次迭代