2015-10-12 15 views
-3

這是我的代碼 在Python 3.4它只是繼續運行循環,直到系統退出時,當玩家死亡這是一個RPG遊戲的一部分,我一直製作的樂趣當我的條件是錯誤的時候它變成真的爲什麼不會循環停止

而不是整個代碼,請注意,如果你想看到整個代碼,請詢問只顯示戰鬥功能

def combat(h, a, d, x): 
    global attack 
    global health 
    global defence 
    global xp 
    death = False 
    while death == False: 
     eab = random.randint(1, 10) 
     yab = random.randint(1, 10) 
     cattack = 0 
     cdefence = 0 
     cattack = attack 
     cdefence = defence 
     cattack = cattack + yab 
     a = a + eab 
     d = d - cattack 
     print("you strike for " + str(cattack) + " damage") 
     cattack = cattack - d 
     if cattack > 0: 
      h = h - cattack 
     if d > 0: 
      print("the enemy has " + str(d) + "defence left") 
     if h > 0: 
      print("the enemy has " + str(h) + "Health left") 
     else : 
      print("the enemy dies") 
      death == True 
      xp = xp + x 
     print("they strike back for " + str(a)) 
     cdefence = cdefence - a 
     a = a - cdefence 
     if a > 0: 
      health = health - a 
     if cdefence > 0: 
      print("you have " + str(cdefence) + " defence left!") 
     if health > 0: 
      print("you have " + str(health) + " health left") 
     else : 
      sys.exit("YOU DIED A HORRIBLE DEATH") 
+7

'death == True'。你並沒有將「真」分配給「死亡」,你只是比較它們。 –

回答

0

你的問題與該行:death == True

這比較variab與True函數「死亡」,這將永遠不會工作。你需要做的是用death = True替換。

這應該修復你的代碼。

相關問題