我一直在努力通过Python的艰难的方式书,它提出了写作战系统的挑战如何退出战斗系统?
我想知道如何打破'赢''条款或移动到下一个场景的while循环。
目前,游戏在用户'死亡'时起作用,但在击败对手双方时,游戏以错误消息结束。
File "fight_test.py", line 146, in <module>
a_game.play()
File "fight_test.py", line 20, in play
next_scene_name = current_scene.enter()
AttributeError: 'NoneType' object has no attribute 'enter'
while health > 0 and (customer1 or customer2):
#While loop runs whilst health > 0 and one of the customers remains.
print "\n", "-" * 20
your_attack = randint(4,12)
customer1_attack = randint(1,4)
customer2_attack = randint(3,6)
if customer2_hitpoints == 0 and customer1_hitpoints == 0:
return 'Win'
attack = int(raw_input("Type 1 to attack Customer 1, 2 to attack Customer 2 >"))
if attack == 1:
if customer1:
customer1_hitpoints = customer1_hitpoints - your_attack
print "You refuse service to Customer 1, %d damage." % your_attack
if customer1_hitpoints <= 0:
customer1 = False
print "Customer 1 is removed from the building."
else:
print "Customer 1 has already been removed and left an angry Trip Advisor review."
elif attack == 2:
if customer2:
customer2_hitpoints = customer2_hitpoints - your_attack
print "You tell customer 2 that they have had too much already, %d damage." % your_attack
if customer2_hitpoints <= 0:
customer2 = False
print "Customer 2 falls over and throws up, they are promptly removed from the building."
else:
print "They have already left to get a late night burger."
else:
print "Why are you just doing nothing?"
if customer1:
health = health - customer1_attack
print "Customer 1 tells you that the service is better in Wetherspoons."
print "It causes %d damage and you have d% health left." % (customer1_attack, health)
if health <= 0:
return 'death'
break
if customer2:
health = health - customer2_attack
#print Fight.quotes[randint(0, len(self.quips)-1)]
print "The customer tells you \"This isn't how I make this drink at home!\""
print "It causes %d damage and you have %d health left." % (customer2_attack, health)
if health <= 0:
return 'death'
break
中断或返回将退出循环...您似乎已经有那些 –
具体是什么问题?这是很多代码,通过 –
嗨,欢迎来到堆栈溢出!虽然为你遇到的代码提供上下文总是很有用,“[越多的代码可以通过,越不可能找到你的问题](http://stackoverflow.com/help/mcve )”。你可以试着把它分解为[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve)? – GoBusto