我正在编写一个基本的格斗游戏,并试图让它在每次攻击时从敌人的生命值中减去攻击量并打印敌人的当前生命值。但是,在我运行脚本一次并循环后,运行状况会重置为其原始数量。我怎样才能用当前的健康放弃敌人的健康?
这是脚本:
import random
while True:
HEALTH = 20
ENEMY_HEALTH = 20
def punch():
mylist = (xrange(0,3))
x = random.choice(mylist)
if x == 3:
print"your hit was very effective enemy lost 3 hp"
print("Enemy Health is" ENEMY_HEALTH - x)
if x == 2:
print "Your punch was effective enemy lost 2 hp"
print("Enemy Health is" ENEMY_HEALTH - x)
if x == 1:
print "enemy lost 1 point"
print("Enemy Health is" ENEMY_HEALTH - x)
def kick():
mylist = (xrange(0,5))
x = random.choice(mylist)
if x > 3:
"%d" % x
print"your kick was very effective enemy lost %d hp"
print("Enemy Health is", ENEMY_HEALTH - x)
if x > 1 < 3:
"%d" % x
print "Your kick was effective enemy lost %d hp"
print("Enemy Health is" ENEMY_HEAlTH - x)
if x == 1:
print "enemy lost 1 point"
print("Enemy Health is" ENEMY_HEALTH - x)
def attackChoice(c):
if c == "punch":
punch()
if c == "kick":
kick()
c = raw_input("Choice Attack\nKick Or Punch: ")
attackChoice(c)
我希望它打印:
choose attack
kick or punch:kick
enemy lost 3 hp
enemy's heath is 17
choose attack
kick or punch:punch
enemy lost 1 hp
enemy's health is 16