我正在制作一个基于python 2.7文本的RPG,而我的战斗功能运行不正常。这里是我的代码:函数运行不正确
def attack(self):
print "A %r appears! It wants to fight!" % (self.name)
while (player.health > 0) or (self.health > 0):
player.health = player.health - ((randint(0,5)) + attack_multiplier(self.level))
print "%r strikes! Your health is down to %r" %(self.name, player.health)
try:
player.weapon = (raw_input("What do you attack with? >>").lower)
if (player.inventory.get(player.weapon) > 0) and (player.health > 0) and (self.health > 0):
if weapon_probability() == "critical hit":
self.health = self.health - (((randint(0,5))) + (attack_multiplier(weapon_levels.get(player.weapon))) * 2)
print "Critical Hit!"
elif weapon_probability() == "hit":
self.health = self.health - ((((randint(0,5))) + (attack_multiplier(weapon_levels.get(player.weapon)))))
print "Hit!"
elif weapon_probability() == "miss":
self.health = self.health
print "Miss"
print "Enemy health down to %r!" % (self.health)
elif player.health <= 0:
print "Your health...it’s falling"
break
elif self.health <= 0:
print "Enemy vanquished!"
break
except ValueError:
print "You don't have that"
我看到的是:
'Bat' strikes! Your health is down to 95
What do you attack with? >>sword
'Bat' strikes! Your health is down to 91
What do you attack with? >>sword
'Bat' strikes! Your health is down to 87
What do you attack with? >>sword
'Bat' strikes! Your health is down to 85
What do you attack with? >>sword
'Bat' strikes! Your health is down to 82
What do you attack with? >>
这只是不断重复和player.health
甚至不断下降到底片。我找不到错误。这个函数是一个类的方法,并且player
是另一个类的一个实例。
OMG我怎么没有看到这一点。我很抱歉 – frg100 2015-04-03 17:39:23
对不起,接受这么长的时间来接受答案...它的第一个问题 – frg100 2015-04-04 19:06:08
@ frg100:不是问题!有些人已经等待了*年*,标记职位被接受,这一天几乎没有*长*。 :-) – 2015-04-05 15:33:08