这是我的代码 在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")
答案 0 :(得分:0)
您的问题在于这一行:death == True
这比较了变量' death'使用True
功能,这将永远不会奏效。您需要做的是将其替换为death = True
。
这应该可以修复您的代码。