Python RPG boss无限攻击循环

问题描述 投票:0回答:1

我是一名编程初学者,正在用 python 制作基于文本的角色扮演游戏。我在这里设置了一场 Boss 战来开始。我已经创建了供 Boss 以及所有玩家攻击的功能。我在这段代码中遇到的问题是,我为老板是否已经轮流攻击过一次创建了一个布尔值。该值开始时为 true,然后在 Boss 攻击功能结束时更改为 false。我已经设置了代码,让玩家按照速度的顺序进行攻击。老板是第一位的。现在继续战斗的条件是boss的生命值在0以上。由于某种原因,我第一次战斗时boss一直在攻击,尽管最后她是否可以攻击的值应该改为false她的攻击功能。如果她无法攻击,代码应该转到玩家的攻击函数。这是战斗的代码,boss 和玩家的攻击函数,以及底部布尔值的尝试更改。

def AriaMove():
   target = Player.NocturneEnemy
   if Player.Aria.hp > 0:
       print("What will Aria do?")
   choice = input()
   if choice == "attack":
       Player.Aria.NormalAttack
   if Player.Aria.attack <= target.defense:
       damage = 0
       target.hp = target.hp - damage
       print("Nocturne's health is:")
       print(target.hp)
   if choice == "healing song: Sereana":
       Player.Sereana.hp + 100
       print("Sereana's health is:")
       print(Player.Sereana.hp)
   if choice == "healing song: Lupin":
       Player.Lupin.hp + 100
       print("Lupin's health is:")
       print(Player.Lupin.hp)
   if choice == "healing song: Aria":
       Player.Aria.hp + 100
       print("Aria's health is:")
       print(Player.Aria.hp)
   if choice == "healing song: Anges":
       Player.Anges.hp + 100
       print("Anges's health is:")
       print(Player.Anges.hp)
   if choice == "healing song: Sylph":
       Player.Sylph.hp + 100
       print("Sylph's health is:")
       print(Player.Sylph.hp)

def AngesMove():
   target = Player.NocturneEnemy
   if Player.Anges.hp > 0:
       print("What will Anges do?")
   choice = input()
   if choice == "attack":
       damage = Player.Anges.attack - target.defense
       target.hp = target.hp - damage
       print("Nocturne's health is:")
       print(target.hp)
   if choice == "pirouette":
       damage = Player.Anges.Pirouette - target.defense
       target.hp = target.hp - damage
       print("Nocturne's health is:")
       print(target.hp)

def SylphMove():
   target = Player.NocturneEnemy
   if Player.Sylph.hp > 0:
       print("What will Sylph do?")
   choice = input()
   if choice == "attack":
       damage = Player.Sylph.attack - target.defense
       if Player.Sylph.attack <= target.defense:
           damage = 0
       target.hp = target.hp - damage
       print("Nocturne's health is:")
       print(target.hp)
   if choice == "health drain":
       damage = (Player.Sylph.attack + 20) - target.defense
       target.hp = target.hp - damage
       Player.Sylph.hp = Player.Sylph.hp + 40
       print("Sylph's health is:")
       print(Player.Sylph.hp)
       print("Nocturne's health is:")
       print(target.hp)

def SereanaMove():
   target = Player.NocturneEnemy
   if Player.Sereana.hp > 0:
       print("What will Sereana do?")
   choice = input()
   if choice == "attack":
       damage = Player.Sereana.attack - target.defense
       target.hp = target.hp - damage
       print(target.hp)
   if choice == "paintbrush spear":
       damage = (Player.Sereana.attack + 30) - target.defense
       target.hp = target.hp - damage
       print("Nocturne's health is:")
       print(target.hp)

def LupinMove():
   target = Player.NocturneEnemy
   if Player.Lupin.hp > 0:
       print("What will Lupin do?")
       choice = input()
   if choice == "attack":
       damage = Player.Lupin.attack - target.defense
       target.hp = target.hp - damage
       print("nocturne's health is:")
       print(target.hp)

def NocturneAttack():
   attackID = random.randint(1, 2)
   targetID = random.randint(1, 5)
   if attackID == 1:
       if targetID == 1 and Player.Sereana.hp > 0:
           target = Player.Sereana
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense
           Player.Sereana.hp = Player.Sereana.hp - Nocturnedamage
           print("Sereana's health is:")
           print(Player.Sereana.hp)
       elif Player.Sereana.hp < 0:
           targetID = random.randint(2, 5)

       if targetID == 2 and Player.Lupin.hp > 0:
           target = Player.Lupin
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense
           Player.Lupin.hp = Player.Lupin.hp - Nocturnedamage
           print("Lupin's health is:")
           print(Player.Lupin.hp)
       elif Player.Lupin.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 3 and Player.Aria.hp > 0:
           target = Player.Aria
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense
           Player.Aria.hp = Player.Aria.hp - Nocturnedamage
           print("Aria's health is:")
           print(Player.Aria.hp)
       elif Player.Aria.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 4 and Player.Anges.hp > 0:
           target = Player.Anges
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense
           Player.Anges.hp = Player.Anges.hp - Nocturnedamage
           print("Anges's health is:")
           print(Player.Anges.hp)
       elif Player.Anges.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 5 and Player.Sylph.hp > 0:
           target = Player.Sylph
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense
           Player.Sylph.hp = Player.Sylph.hp - Nocturnedamage
           print("Sylph's health is:")
           print(Player.Sylph.hp)
       elif Player.Sylph.hp < 0:
           targetID = random.randint(1, 4)
           Nocturnedamage = Player.NocturneEnemy.attack - target.defense

   if attackID == 2:
       if targetID == 1 and Player.Sereana.hp > 0:
           target = Player.Sereana
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense
           Player.Sereana.hp = Player.Sereana.hp - Nocturnedamage
           print("Sereana's health is:")
           print(Player.Sereana.hp)
       elif Player.Sereana.hp < 0:
           targetID = random.randint(2, 5)

       if targetID == 2 and Player.Lupin.hp > 0:
           target = Player.Lupin
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense
           Player.Lupin.hp = Player.Lupin.hp - Nocturnedamage
           print("Lupin's health is:")
           print(Player.Lupin.hp)
       elif Player.Lupin.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 3 and Player.Aria.hp > 0:
           target = Player.Aria
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense
           Player.Aria.hp = Player.Aria.hp - Nocturnedamage
           print("Aria's health is:")
           print(Player.Aria.hp)
       elif Player.Aria.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 4 and Player.Anges.hp > 0:
           target = Player.Anges
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense
           Player.Anges.hp = Player.Anges.hp - Nocturnedamage
           print("Anges's health is:")
           print(Player.Anges.hp)
       elif Player.Anges.hp < 0:
           targetID = random.randint(1, 5)

       if targetID == 5 and Player.Sylph.hp > 0:
           target = Player.Sylph
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense
           Player.Sylph.hp = Player.Sylph.hp - Nocturnedamage
           print("Sylph's health is:")
           print(Player.Sylph.hp)
       elif Player.Sylph.hp < 0:
           targetID = random.randint(1, 4)
           Nocturnedamage = (Player.NocturneEnemy.attack + 30) - target.defense

       if targetID == 1:
           Player.Sereana.hp = Player.Sereana.hp - Nocturnedamage
           print("Sereana's health is:")
           print(Player.Sereana.hp)
       if targetID == 2:
           Player.Lupin.hp = Player.Lupin.hp - Nocturnedamage
           print("Lupin's health is:")
           print(Player.Lupin.hp)
       if targetID == 3:
           Player.Aria.hp = Player.Aria.hp - Nocturnedamage
           print("Aria's health is:")
           print(Player.Aria.hp)
       if targetID == 4:
           Player.Anges.hp = Player.Anges.hp - Nocturnedamage
           print("Anges's health is:")
           print(Player.Anges.hp)
       if targetID == 5:
           Player.Sylph.hp = Player.Sylph.hp - Nocturnedamage
           print("Sylph's health is:")
           print(Player.Sylph.hp)

CanNocturneAttack = True
while Player.NocturneEnemy.hp > 0:
   while Player.Sereana.hp > 0 or Player.Lupin.hp > 0 or Player.Aria.hp > 0 or Player.Anges.hp > 0 or Player.Sylph.hp > 0:
       if CanNocturneAttack:
           NocturneAttack()
       CanNocturneAttack = False

while Player.NocturneEnemy.hp > 0:
   NocturneAttack()
   AriaMove()
   AngesMove()
   SylphMove()
   SereanaMove()
   LupinMove()
python python-3.x
1个回答
0
投票

这里有问题。玩家身份不明。如果您将代码放入 replit 中,它会说该玩家未识别。要解决这个问题,您需要说出玩家是什么。我不太擅长编码,所以我无法告诉你到底该怎么做。

© www.soinside.com 2019 - 2024. All rights reserved.