4

私はPythonでテキストアドベンチャーをコーディングしていましたが、私はかなり新しいですが、自分のやり方を知っています. 私が問題を抱えているのは、私の敵(enemy1)が健康を失っていないことです. これが理解に役立つコードです。

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 に戻ります。私は敵1-xを入力し続けているため、それを理解しました。敵のヘルスを下げる方法を知りたいのですが、それが低いことを覚えておいてください。ゼロになると while ループが壊れます。

4

1 に答える 1

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

これらの行は、実際には変更されませhpenemy1代入ステートメントを使用して値を変更します: 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
于 2013-04-17T03:11:13.030 に答える