我正在编写brick breaker代码,我的第三个和第四个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
if…elif…else的语法
相关问题 更多 >
编程相关推荐