簡體   English   中英

Elif語句被忽略

[英]Elif Statements are Being Ignored

我正在編碼打磚塊,而我的第三和第四條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的語法

if test expression:
    Body of if
elif test expression:
    Body of elif
else: 
    Body of else

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM