私は基本的な格闘ゲームを書いており、攻撃ごとに敵の健康から攻撃の量を差し引き、敵の現在の健康を出力するようにしようとしています。ただし、スクリプトを 1 回実行してループすると、ヘルスは元の量にリセットされます。現在のヘルスで敵のヘルスを辞任するにはどうすればよいですか?
スクリプトは次のとおりです。
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