我是从事基于文本的RPG的新手程序员,由于某种原因,当您选择Bowman类时用箭头击中敌人时,如果按预期,它会造成相同程度的伤害每次都造成随机伤害,并且每次伤害不会减少敌人的生命值。我的代码很乱,但是请耐心等待。另外,如果您总体上对我有任何建议,请告诉我。
while action == "attack":
if player_class == "warrior":
enemy_damage = 30
enemy_health = enemy_health - enemy_damage
elif player_class == "bowman":
target_general = randint(1, 3)
if target_general == 1:
action = input(f"You shot to the left of the {enemy}. What will you do now? Attack, evade or run?")
elif target_general == 2:
target_specific = randint(1, 5)
if target_specific == 5:
enemy_damage = "way too much"
enemy_health = 0
print("Critical hit!")
else:
enemy_damage = target_specific * 10
enemy_health = enemy_health - enemy_damage
else:
action = input(f"You shot to the right of the {enemy}. What will you do now? Attack, evade or run?")
if enemy_health < 0:
enemy_health = 0
if enemy_health == 0:
player_gold = player_gold + treasure
print(f"You defeated the {enemy}! You found {treasure} gold.")
action = leave()
elif action == "attack" and enemy_damage != 0:
action = input(f"You attacked the {enemy}, and did {str(enemy_damage)} damage. The enemy has {enemy_health} health left. What will you do now?Attack, evade or run?")
答案 0 :(得分:2)
找到了。
您无需重置enemy_damage
,因此,在第一次成功攻击后,即使您错过了第二枪,您也将打印错过的消息,然后打印损坏消息。
#This message is turn 1
You attacked the Thor, and did 10 damage. The enemy has 460 health left. What will you do now?Attack, evade or run?attack
#this message is turn 2
You shot to the left of the Thor. What will you do now? Attack, evade or run?attack
#this message is ALSO turn 2
You attacked the Thor, and did 10 damage. The enemy has 460 health left. What will you do now?Attack, evade or run?attack
将此输入:
while action == "attack":
enemy_damage = 0 # Reset the damage every turn
### The rest