[英]If statement not calling function
由于某种原因,我的if语句将无法执行其应做的工作。 我不确定为什么,因为我确定我已经正确格式化了。
def attack():
os.system('clear')
pAttack=random.randint(playerIG.attack/2, playerIG.attack)
eAttack=random.randint(enemy.attack/2, enemy.attack)
if pAttack==playerIG.attack/2:
print "You miss!"
else:
enemy.health-=pAttack
print "You deal %s damage" % pAttack
option=raw_input("")
if enemy.health<=0:
win()
os.system('clear')
if eAttack==enemy.attack/2:
print "The enemy missed!"
else:
playerIG.health-=eAttack
print "The enemy deals %s damage" % eAttack
option=raw_input("")
if playerIG.health<=0:
die()
else:
fight()
我们正在看的部分是:
if enemy.health<=0:
win()
我不知道为什么,但是即使敌人的生命值低于零,它也不会调用win()。
赢功能:
def win():
print "You have successfully killed the %s!" % enemy.name
print "You have gained %s gold!" % enemy.goldgain
任何解决方案都会有所帮助,谢谢!
您在win()
之后立即调用os.system('clear')
,因此您不会看到win消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.