我正在编码打砖块,而我的第三和第四条Elif条件被忽略了。
为了区分水平或横向击打砖块侧面以相应地改变球的方向,我指定了一个连续检查的5像素边距。我的代码正确地确定了球何时落在顶部或底部边缘,但是即使我以相同的方式编写了这些条件,球也只是穿过了侧面。我知道该语句被完全忽略了,因为该语句的所有功能都被忽略了。
砖块中用于指定边距的边界标记的末尾带有B
def collision(self):
if (ball.xcor() > self.colisL) and (ball.xcor() < self.colisR) and (ball.ycor() > self.colisD) and (ball.ycor() < self.colisDB):
self.turtle.hideturtle()
ball.dy *= -1
self.colisU = 1000
self.colisD = 1000
self.colisL = 1000
self.colisR = 1000
global score
score += 1
elif (ball.xcor() > self.colisL) and (ball.xcor() < self.colisR) and (ball.ycor() < self.colisU) and (ball.ycor() > self.colisUB):
self.turtle.hideturtle()
ball.dy *= -1
self.colisU = 1000
self.colisD = 1000
self.colisL = 1000
self.colisR = 1000
score += 1
elif (ball.xcor() > self.colisL) and (ball.xcor() < self.colisLB) and (ball.ycor() > self.colisD) and (ball.ycor() < self.colisU):
self.turtle.hideturtle()
ball.dx *= -1
self.colisU = 1000
self.colisD = 1000
self.colisL = 1000
self.colisR = 1000
score += 1
elif (ball.xcor() > self.colisR) and (ball.xcor() < self.colisRB) and (ball.ycor() > self.colisU) and (ball.ycor() < self.colisU):
self.turtle.hideturtle()
ball.dx *= -1
self.colisU = 1000
self.colisD = 1000
self.colisL = 1000
self.colisR = 1000
score += 1
答案 0 :(得分:0)
if ... elif ... else
的语法if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else