我一直在做这个项目,我正在努力建立一个饥饿系统。我有消除饥饿在一定的时间设置,但当我使用我的“饮食系统”,只是不会增加。我用hunger += 50来加,但它只是停留在50.
,这是我的代码,如果你想看
这是循环的开始,我不确定是否应该在循环的内部或外部有饥饿变量.
def ifhealthlessthan50():
while health >0:
hunger = 50这是周期性的饥饿损失系统..。
def hungerSystemThread():
global hunger
while True:
time.sleep(65)
hunger = hunger - 15
print("\nYOU HAVE LOST SOME OF YOUR HUNGER\n>")
ifhealthlessthan50()
if hunger <= 0:
print("YOU HAVE RUN OUT OF HUNGER AND DIED!")
intro()这是饮食系统..。
elif choice2.lower() == 'eat':
eatingsystem = input("WHAT WOULD YOU LIKE TO EAT?\n> ")
if hunger <= 99:
if eatingsystem.lower() == "apple":
if things['APPLE'] > 1:
print("eating...")
time.sleep(3)
hunger += 50
things['APPLE'] -= 1
print("ONE APPLE EATEN")
ifhealthlessthan50()
elif hunger >= 100:
print("YOU CANNOT EAT!")
ifhealthlessthan50()请记住,ifhealthlessthan50()实际上并不意味着如果健康状况小于50,这仅仅是我无法更改的def(),它基本上是整个代码所处的整个循环。
发布于 2022-08-07 14:56:32
每次打电话给ifhealthlessthan50()时,都会将健康状态重置为50。
尽管使用hunger += 50正确地增加了饥数,但通过调用函数立即将其设置为50,因为while条件是真的。
也许您需要检查您的逻辑,并澄清您希望while health > 0:循环做什么。如果ifhealthlessthan50()是您的主要游戏循环,则不必每次调用它时重置hunger的值。
https://stackoverflow.com/questions/73268448
复制相似问题