【发布时间】:2016-01-09 10:53:40
【问题描述】:
这是我的代码 在 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")
【问题讨论】:
-
death == True。您没有将True分配给death,您只是在比较它们。
标签: python function python-3.x while-loop statements