当前位置: 首页>>代码示例>>Python>>正文


Python View.ran_away_message方法代码示例

本文整理汇总了Python中view.View.ran_away_message方法的典型用法代码示例。如果您正苦于以下问题:Python View.ran_away_message方法的具体用法?Python View.ran_away_message怎么用?Python View.ran_away_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在view.View的用法示例。


在下文中一共展示了View.ran_away_message方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import ran_away_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
开发者ID:hrgunn,项目名称:MLH,代码行数:45,代码来源:controller.py


注:本文中的view.View.ran_away_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。