我正在尝试让用户选择他们想要的课程。战士还是无赖。每次战士攻击将增加10%的伤害,每次无赖攻击都有10%的几率增加一倍。我的代码按我的想法工作并重复,但是我想不出如何在攻击老板后让它保持健康状态。我希望老板每次用户按1直到老板= 0时都失去健康。我已经尝试过使用while和for循环的所有方法。我这样做是完全错误的吗?
import random
Boss = 1000
def war_attack():
rand = random.randrange(2,102, 2)
warratk = rand + rand * .10
healthleft = Boss - warratk
print("You did", warratk, "damage!")
print(healthleft)
def rogue_attack():
rand = random.randrange(2,102, 2)
a = random.randrange(1,11)
if a == 4:
rogueattk = rand + rand
else:
rogueattk = rand
healthleft = Boss - rogueattk
print("You did", rogueattk, "damage!")
print("Boss Health Remaining : ", healthleft)
print("")
print("Please choose a class. Warrior or Rogue.")
print("-Warriors have 10% increased strength.")
print("-Rogues have a 10% chance for critical damage.")
Class = str(input("Enter your class: "))
while Boss >= 0:
attack = int(input("Enter '1' to attack: "))
if Class == "Warrior" or Class == "warrior":
war_attack()
elif Class == "Rogue" or Class == "rogue":
rogue_attack()