我正在尝试从LPTHW的练习 36 中获得一个游戏来工作。
我可以让游戏的整个部分正常工作,除非它进入战斗。这就是我认为问题所在。
def combat_engine():
global wins, hit_points, current_hp
if monster_current_hp or current_hp > 0:
print "You can type 'a' for attack, or 'q' for quit, choose one."
answer = raw_input(":> ")
if 'a' in answer:
attack(monster)
attack('player')
combat_engine()
elif 'q' in answer:
print t.white_on_red("You give up and are devoured by the %s.") % monster
exit(0)
else:
print "I dont understand %s." % answer
next()
combat_engine()
elif monster_hp == 0:
print "You defeated the %s, congradulations %s!" % monster, name
wins = wins + 1
if wins == 5:
you_win()
elif victim == 'player':
hit_points = hit_points + d6()
current_hp = hit_points
print "You feel hardier."
next()
barracks()
elif current_hp == 0:
print "You have been deafeted by the %s, better luck next time." % monster
next()
exit(0)
else:
print "Bug Somewhere"
我相信这个错误是在这个函数的某个地方。当我打印出每个角色的HP值时,怪物已经减少到-2 hp后战斗仍在继续。也许这是布尔值的问题?
我希望它做的是要么为获胜而进行所有的统计调整,如果你输了就退出游戏。我只是想克服这个问题,这样我就可以开始学习类和字典,这应该会让我的生活更轻松。如果我应该发布更多信息,请告诉我,我是新手,还不是在这里发布问题的最佳人选。
提前致谢!