如何使战斗序列使敌人的生命值降低?

时间:2019-10-05 15:39:00

标签: python

我正在尝试与游戏开发班中某个项目的向导进行战斗。它应该是一个简单的“当敌人的健康为零时,继续前进”,“当玩家的健康为零时,游戏结束”序列。

我将顺序本身调低了,但是HP有问题。我试图将对玩家和敌人的HP的if语句一遍又一遍地移动到wizardAttack()的while循环中和循环之前和之前的不同函数中,但是什么也没有。

import time
playerHealth = 15
wizardHealth = 15
inventory = ['Help Potion', 'Help Potion', 'Poison Dart', 'Dagger', 'Torch']
print('Your HP:', playerHealth)
print('Wizard\'s HP:', wizardHealth)
time.sleep(3)
if playerHealth <= 0:
    print('The wizard is too strong! You black out and get dragged back to your dungeon.')
    time.sleep(4)
    print('Game Over')
    playAgain()
if wizardHealth <= 0:
        print('The wizard goes down with a THUD! You win the battle!')
        time.sleep(4)
        print('On the wizard\'s body, you notice a dagger and take it.')
        time.sleep(4)
        inventory.append('Dagger')
        twowizards()

应该发生的是玩家和向导的生命值都应该降低,并且当一个角色的生命值等于0时,战斗应该正确结束并继续进行下一个序列,或者如果敌人获胜,则游戏结束。现实情况是,健康状况或多或少会重置为15,这让我一无所获。

1 个答案:

答案 0 :(得分:0)

您似乎尚未创建战斗序列。也许像这样:

import time
import random
playerHealth = 15
wizardHealth = 15
inventory = ['Help Potion', 'Help Potion', 'Poison Dart', 'Dagger', 'Torch']
print('Your HP:', playerHealth)
print('Wizard\'s HP:', wizardHealth)
time.sleep(3)
if 'Dagger' in inventory:
  playerDamage = 4
while playerHealth >=1 and wizardHealth >=1:
  wizardDamage = random.randint(1,5)
  playerHealth -= wizardDamage
  print("You bash the wizard, dealing "+str(playerDamage)+" damage!")
  time.sleep(2)
  wizardHealth -= playerDamage
  print("The wizard bashes you, dealing "+str(wizardDamage)+" damage!")
  time.sleep(2)

if playerHealth <= 0:
    print('The wizard is too strong! You black out and get dragged back to your dungeon.')
    time.sleep(4)
    print('Game Over')
    playAgain()
if wizardHealth <= 0:
        print('The wizard goes down with a THUD! You win the battle!')
        time.sleep(4)
        print('On the wizard\'s body, you notice a dagger and take it.')
        time.sleep(4)
        inventory.append('Dagger')
        twowizards()

尽管如此,您的某些功能仍未定义。

相关问题