试图在一只乌龟与另一只碰撞时改变它的颜色。我想要什么:Nidas(一只乌龟)与绿色相撞变成红色。红色|绿色碰撞>>绿色变为红色。红色|红色或绿色|绿色无动作。发生的事情是 Nidas|Green 碰撞变为红色(如预期),但 Red|Green 碰撞变为红色变为绿色。我怎么弄乱了if语句,
for ball in balls:
ball.sety(ball.ycor() + ball.dy)
ball.setx(ball.xcor() + ball.dx)
for other_ball in balls:
if (other_ball is ball):
# We are not interested in balls colliding with themselves.
# Skip the current iteration of the inner for-loop, and move on to the next ball
continue
if is_collided_with(other_ball, nidas):
other_ball.color("red")
if (
is_collided_with(ball, other_ball) and
other_ball.color("green") and
ball.color("red")
):
other_ball.color("red")