簡體   English   中英

如果語句不調用函數

[英]If statement not calling function

由於某種原因,我的if語句將無法執行其應做的工作。 我不確定為什么,因為我確定我已經正確格式化了。

def attack():
    os.system('clear')
    pAttack=random.randint(playerIG.attack/2, playerIG.attack)
    eAttack=random.randint(enemy.attack/2, enemy.attack)
    if pAttack==playerIG.attack/2:
        print "You miss!"
    else:
        enemy.health-=pAttack
        print "You deal %s damage" % pAttack
    option=raw_input("")
    if enemy.health<=0:
        win()
    os.system('clear')
    if eAttack==enemy.attack/2:
        print "The enemy missed!"
    else:
        playerIG.health-=eAttack
        print "The enemy deals %s damage" % eAttack
    option=raw_input("")
    if playerIG.health<=0:
        die()
    else:
        fight()

我們正在看的部分是:

if enemy.health<=0:
        win()

我不知道為什么,但是即使敵人的生命值低於零,它也不會調用win()。

贏功能:

def win():
    print "You have successfully killed the %s!" % enemy.name
    print "You have gained %s gold!" % enemy.goldgain

任何解決方案都會有所幫助,謝謝!

您在win()之后立即調用os.system('clear') ,因此您不會看到win消息。

暫無
暫無

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

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