-1
下面是我在9-13行的遊戲的代碼我試圖讓飢餓變量每180秒減少10,但它不工作。如何隨着時間的推移減少變量的值
import threading
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print(" Welcome to my game")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
health = 100
stamina = 100
hunger = 100
def hungerdecrease(h):
global hunger
threading.Timer(180,hungerdecrease).start()
h -= 10
hungerdecrease(hunger)
while health > 0 and stamina >0 and hunger >0:
if hunger <50:
print("You are hungry.")
if stamina <10:
print("You are feeling exhausted.")
if health <50:
print("You are unhealthy.")
print("You are dead")
'hunger'是越來越被複制,因此函數的唯一修改拷貝。 – ForceBru
嘗試添加一個返回飢餓減少並做'飢餓=飢餓(飢餓)'。編輯之後,你不應該修改飢餓而不是h嗎? – themistoklik
我是相當新的python所以原諒我,如果我的問題聽起來很愚蠢,但我沒有得到你的意思,增加一個返回飢餓減少 – Wilziam