我一直在努力通過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