我写了这个代码
hp0 = 100
atk0 = 30
hp1 = 100
atk1 = 5
print("Action? (attack, heal, nothing):")
act = input("> ")
while hp0 > 0 and hp1 > 0:
if act == "attack":
hp1 = hp1 - atk0
if hp1 <= 0:
print("You won!")
print("{} DMG".format(atk0)
)
if act == "heal":
hp0 = hp0 + 15
print("+15 HP")
else:
print("...")
print("Enemy attacked you! -{} hp".format(atk1))
hp0 = hp0 - atk1
print("{}HP player".format(hp0))
print("{}HP enemy".format(hp1))
print("Action? (attack, heal, nothing):")
act = input("> ")
if hp0 > 0:
if hp1 <= 0:
print("You won!")
if hp1 > 0:
if hp0 <= 0:
print("You lose")
这是一场你和怪物之间的战争。
当我继续攻击时,有一刻敌人的生命(hp1
)是-20,它让我决定一个行动之前,它告诉我我赢了。你知道吗
当我决定什么都不做,我的生命值(hp0
)变为0时,也会发生同样的事情,但它让我再做一次动作,我可以决定治疗,游戏继续。你知道吗
我怎样才能解决这个问题?你知道吗
将请求下一个操作移动到循环的顶部:
并删除其他
print("Action? ...")
和input("> ")
行。你知道吗相关问题 更多 >
编程相关推荐