我做了一个小游戏让你杀死半兽人。你选择攻击或治疗,等等。我是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
发布于 2018-08-08 09:15:57
修正了lol在playerturn变量前有%s的问题!我是个傻子哈哈
https://stackoverflow.com/questions/51737312
复制相似问题