我正在尝试为快速和简短的战斗游戏循环一部分代码。
我已经尝试了一些真实的陈述,但是我不确定我是否理解得太清楚。
print("A: Attack")
time.sleep(.2)
print("B: Skill")
time.sleep(.2)
print("C: Defend")
time.sleep(.2)
print("D: Rest")
time.sleep(.2)
turn1 = input("Input: ")
if turn1.lower() == "a" or turn1.lower() == "b" or turn1.lower() == "c" or turn1.lower() == "d":
if turn1.lower() == "a":
damaget1 = random.randint(1,5)
print("You did " + str(damaget1) + " damage!")
enemyHealth -= damaget1
print("AI is now at " + str(enemyHealth) + " health.")
damaget2 = random.randint(1,5)
print("The bot did" + damaget2 + " damage!")
healthValue -= damaget2
print("You are now at " + healthValue + " health!")
最后一部分是我希望它循环到顶部时。谢谢!
答案 0 :(得分:0)
只需将其放入while循环中并设置退出条件即可。
while enemyHealth > 0 or healthValue> 0
print("A: Attack")
time.sleep(.2)
print("B: Skill")
time.sleep(.2)
print("C: Defend")
time.sleep(.2)
print("D: Rest")
time.sleep(.2)
turn1 = input("Input: ")
if turn1.lower() == "a" or turn1.lower() == "b" or turn1.lower() == "c" or
turn1.lower() == "d":
if turn1.lower() == "a":
damaget1 = random.randint(1,5)
print("You did " + str(damaget1) + " damage!")
enemyHealth -= damaget1
print("AI is now at " + str(enemyHealth) + " health.")
damaget2 = random.randint(1,5)
print("The bot did" + damaget2 + " damage!")
healthValue -= damaget2
print("You are now at " + healthValue + " health!")
print("Game Over")
答案 1 :(得分:0)
这是工作代码,还可以选择提前退出程序
{{1}}