本文整理汇总了Python中view.View.blocked_attack_message方法的典型用法代码示例。如果您正苦于以下问题:Python View.blocked_attack_message方法的具体用法?Python View.blocked_attack_message怎么用?Python View.blocked_attack_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.blocked_attack_message方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import blocked_attack_message [as 别名]
class Battle:
def __init__(self, player, level):
self.player = player
self.level = level
self.monster = MonsterFactory.create(level)
self.is_players_turn = bool(random.getrandbits(1))
self.lost = False
self.view = View()
def take_turn(self):
if self.is_players_turn:
choice = self.view.battle_decision()
if choice == 0:
self.monster.take_damage(self.player.attack)
if self.monster.is_dead():
self.view.killed_monster_message(self.monster.race)
return False
else:
self.view.attacked_monster_message(self.monster.race, self.player.attack)
self.is_players_turn = False
return True
elif choice == 1:
self.view.blocked_attack_message()
self.is_players_turn = True
return True
elif choice == 2:
able_to_flee = bool(random.getrandbits(1))
if able_to_flee:
self.view.ran_away_message()
return False
else:
self.view.couldnt_run_away_message()
self.is_players_turn = False
return True
elif not self.is_players_turn:
self.view.got_attacked_message(self.monster.race, self.monster.attack)
self.player.take_damage(self.monster.attack)
self.is_players_turn = True
if self.player.is_dead():
self.view.player_died_message()
self.lost = True
return False
self.view.player_health_message(self.player.hp)
return True