我正在使用python编写文本冒险,我很新,但我知道我的方式。我遇到麻烦的是我的敌人(敌人1)没有失去健康。这是帮助您理解的代码。
hp=100
punch=10
kick=20
kill=99999999
burger=10
soup=10
glass=999999999
nothing=100
enemy1=100
from time import sleep
print("What's Your name?")
usr=raw_input("> ")
print("Your starting health is 100"), usr
sleep(1)
print("You awake in your prison cell. You can go to the gym or outside.")
sleep(.5)
print("type gym or outside to go there")
cell=raw_input("> ")
if cell=="gym":
print("You go to the gym. There are 2 guards here and 5 prisoners. You can lift weights, go outside, go to the cells or fight a prisoner")
sleep(1)
print("Type fight, weights, outside or cells")
gym=raw_input("> ")
if gym=="fight":
print("You walk up to a prisoner and he stabs you.")
sleep(2)
print("Game Over"), usr
if gym=="weights":
print("You go and pick up some weights. You forget overwork yourself and die of a heart attack")
if gym=="outside":
print("You go outside to ")
if cell=="outside":
print("You go outside. There are some people playing basketball and some people doing drugs. You can do drugs, play bball or fight someone")
outside=raw_input("> ")
if outside=="fight":
print("You walk up to a guy")
sleep(1)
print("Hey, wanna fight?")
sleep(1)
print("Sure!")
sleep(1)
print("The stranger punches you.")
sleep(1)
print("Your health is now"), hp-punch
while enemy1>0:
print("You can kick or punch")
fight1=raw_input("> ")
if fight1=="punch":
print("You punch that mothafucka")
sleep(1)
print("His health is"), enemy1-punch
if fight1=="kick":
print("You kick that mothafucka")
sleep(1)
print("His health is now"), enemy1-kick
if fight1=="kill":
print("You evicerate that mothafucka")
sleep(1)
print("His health is now"), enemy1-kill
print("You win!")
当你外出时,不要和别人打架,他的健康状况可以追溯到100。我想通了,因为我一直在输入enemy1-x。我想知道如何让敌人的健康降低并记住它更低,当它达到零时它会打破while循环。
答案 0 :(得分:3)
print("Your health is now"), hp-punch
print("His health is"), enemy1-punch
print("His health is now"), enemy1-kick
print("His health is now"), enemy1-kill
这些行实际上并未更改hp
或enemy1
。使用分配声明更改其值a -= b
,这是a = a - b
的简写。
hp -= punch
print "Your health is now", hp
enemy1 -= punch
print "His health is", enemy1
enemy1 -= kick
print "His health is now", enemy1
enemy1 -= kill
print "His health is now", enemy1