基于文本的游戏

时间:2016-11-14 17:16:51

标签: python

ERROR at line 1: Unknown command '\U'.

如果有人可以帮助我不做每个健康部分,并在每次有帮助的战斗/攻击后打印它。请不要太复杂,这是我上学的作业,而我几周前才开始。

2 个答案:

答案 0 :(得分:0)

您可以直接打印熊的健康状况:

print("bear's health:", bear)

如果这就是你要找的东西。你真的很模糊......

答案 1 :(得分:0)

你的代码中有很多错误。你没有正确地降低健康状况,你也需要将健康状况连续循环,以便游戏继续进行直到有人死亡。这是更正后的代码:

import random
import time

attackers=random.randint(0,100)
val1=random.randint(0,1)

health=100
bear=100

name=input("What is your name hero? ")
print("Okay ",name," i need to teach you the basics of combat")
time.sleep (1)
print ("Bear spawns")
while((health or bear) > 0):
    if val1==0:
        print ("Bear attacks -25 HP")
        health -= 25
        print("Health = ", health)


    attack=int(input("Press 1 to attack "))

    if attack==1:
        print ("Bears HP -25")
        bear -= 25
        print("Bears HP = ", bear)
    else:
        print ("Why didn't you attack?!?!?")

else:
    if health < bear:
        print("You lost!")
    else:
        print("You won!")