python - 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
解决方案
修复了和之前的 playerturn 变量一样的问题!我是个白痴哈哈
推荐阅读
- python - 在 txt 文件中导出矩阵
- javascript - 前六个手机号码不能相同
- docker - Docker:无法连接到 localhost 端口 80:连接被拒绝
- javascript - Mongoose:findOneAndUpdate ~500k 文档
- android - 在哪个库中声明了“android.view.vector”?
- python - 数据框中的Python函数搜索
- c# - C#,在 Windows 服务的 OnStart 中调用异步方法
- r - 如何使用命中和未命中和 Halton 逼近 R 中双积分的解?
- windows - 防止 COM 激活服务器可执行文件?
- reactjs - React-Native 渲染太早了?