I encoded a text adventure in python, and I'm pretty new, but I know what is going on. I have problems with my enemy (enemy1) does not lose health. Here is the code to help you understand.
hp=100 punch=10 kick=20 kill=99999999 burger=10 soup=10 glass=999999999 nothing=100 enemy1=100 from time import sleep print("What 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!")
Do not go out when you go out, you are fighting with someone, his health goes back to a hundred. I realized that this is because I continue to recruit the enemy1's. I want to know how to make the enemyβs health fall and remember that itβs lower, and when it reaches zero, that it breaks the while loop.
source share