这是密码
# TEST.PY
import sys
import random
class Fight(object):
def enter(self):
print "\n", "-" * 10
print "There are two muchachos:"
print "MUCHACHO1"
print "MUCHACHO2"
print "One of them looks wounded or something."
your_hit_points = 20
muchacho1_hit_points = 6
muchacho2_hit_points = 11
muchacho1 = True
muchacho2 = True
while your_hit_points > 0 or (not muchacho1 and not muchacho2):
print "\n", "-" * 10
your_attack = random.randint(4,12)
muchacho1_attack = random.randint(1,4)
muchacho2_attack = random.randint(4,8)
attack = int(raw_input("Type 1 to attack MUCHACHO1, 2 to attack MUCHACHO2 >"))
if attack == 1:
muchacho1_hit_points - your_attack
print "You hit MUCHACHO1 for %d hit points." % your_attack
if muchacho1_hit_points <= 0 and muchacho1:
muchacho1 = False
print "MUCHACHO1 killed!"
else:
pass
elif attack == 2:
muchacho2_hit_points - your_attack
print "You hit MUCHACHO2 for %d hit points." % your_attack
if muchacho2_hit_points <= 0 and muchacho2:
muchacho2 = False
print "MUCHACHO2 killed!"
else:
pass
else:
print "DOES NOT COMPUTE"
pass
your_hit_points - muchacho1_attack
print "MUCHACHO1 hit you for %d points, you have %d hit points left." % (muchacho1_attack, your_hit_points)
your_hit_points - muchacho2_attack
print "MUCHACHO2 hit you for %d points, you have %d hit points left." % (muchacho2_attack, your_hit_points)
exit(1)
a_fight = Fight()
a_fight.enter()我没有遇到什么困难。基本上,WHILE循环从未完成,似乎每个人的命中点都没有被减去。我有一种直觉,我忽略了一些非常基本的东西,因为我已经编码了几个小时,所以我可能看不到简单的东西。
我知道通过使用更多的类或函数可以做得更好,但是现在我想这样做(对于80+ char行也很抱歉)。
发布于 2014-03-06 20:53:55
我认为您要做的是muchacho1_hit_points -= your_attack,muchacho2也是如此。现在你只是放弃了减法的结果。
https://stackoverflow.com/questions/22235607
复制相似问题