Python,代码重复执行直到某个事件

时间:2018-08-08 01:07:59

标签: python

我做了一个小游戏,您可以杀死兽人。您选择攻击或治愈等等。我是python的新手。我似乎无法使代码循环如此循环直到兽人或你死亡。任何解决方案/提示?

from time import sleep
from random import randint
#here
game = True
health = 100
feeling_brave = True
playerturn = True
attackdmg = randint(2,4)
maxhealth = health
heal = randint(3,5)
playerab = 0
ahealth = randint(10,70)
amaxhealth = ahealth
attackadmg = randint(1,3)
orcturn = False


sssprint('Kill the orc! He has', (ahealth), ('health. '))
sleep(1)

while game == True:

    if playerturn == True:
        playerab = input('Attack or Heal? ')

        if playerab == ('Attack'):
            sleep(1)
            print('You decide to attack the Orc.')
            sleep(1)
            ahealth = ahealth - attackdmg
            print('You hit the orc for', (attackdmg))
            sleep(1)
            print('The Orc has', (ahealth), ('health remaining.'))
            orcturn = True
            playerturn = False

    if playerab == ('Heal') and health != maxhealth and playerturn == True:
        print('You cast a healing spell on yourself')



    if orcturn == True:
         sleep(1)
         print('Its the orcs turn to strike!')
         if ahealth > 9:
             sleep(1)
             health =  health - attackadmg
             print('The orc strikes you for', (attackadmg))
             print('You have', (health), 'health left')
             orcturn = False
             splayerturn = True

任何帮助都会很好:D

1 个答案:

答案 0 :(得分:0)

修复了大声笑,在playerturn变量之前有一个s!我是个白痴哈哈