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


Python Monster.take_damage方法代码示例

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


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

示例1: run

# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import take_damage [as 别名]
class World:
    def run(self):
        self.player = Monster(name='Player')
        self._load_history(self.player)

        monster = random.choice(list(monsters.viewkeys()))
        self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
        self.ui = UI(self.player)
        self.ui.monster = self.monster

        self.ui.welcome()
        
        a = 1
        while a != 0:
            self._load_history(self.monster)

            a = self.run_loop()

            if a != 0:
                self.ui.update_display()

            self._save_history(self.player)
            self._save_history(self.monster)
            
            monster = random.choice(list(monsters.viewkeys()))
            self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
            self.ui.monster = self.monster

    def run_loop(self):
        player_move = "Run"
        while player_move.lower() != ACTION_QUIT:

            if self.player.offbalance:
                moves = [MOVE_BASH, MOVE_DEFEND]
            else:
                moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]
            if self.monster.offbalance:
                monster_moves = [MOVE_BASH, MOVE_DEFEND]
            else:
                monster_moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]

            player_move = self.ui.player_move(moves)

            if player_move == ACTION_QUIT:
                break
            if player_move not in moves:
                self.ui.msg = "I don't understand your input, try again."
                self.ui.update_display()
                continue

            monster_move = self.monster.attack(monster_moves, self.player)
            
            self.ui.monster.move = monster_move
            self.ui.player.move = player_move

            if player_move + monster_move in action_table:
                outcome = action_table[player_move + monster_move]
                self.monster.take_damage(outcome[2])
                self.monster.offbalance = outcome[3]
                self.player.take_damage(outcome[0])
                self.player.offbalance = outcome[1]
            else:
                outcome = action_table[monster_move + player_move]
                self.monster.take_damage(outcome[0])
                self.monster.offbalance = outcome[1]
                self.player.take_damage(outcome[2])
                self.player.offbalance = outcome[3]

            # record the moves just made for the AI
            self.player.history.append(player_move)
            self.monster.history.append(monster_move)

            self.ui.update_display()

            if self.player.is_dead() and self.monster.is_dead():
                self.ui.msg = "You have slain the foul " + self.monster.name + ", but it appears that, in its dying throes, the " + self.monster.name + "has also slain you."
                return 0
            elif self.player.is_dead():
                self.ui.msg = "Oh no! You seem to have perished!"
                return 0
            elif self.monster.is_dead():
                self.ui.msg = "You have slain the " + self.monster.name + "."
                return 1
        return 0

    def _load_history(self, monster):
        name = 'player'
        if monster.name.lower() != 'player':
            name = 'monster'

        try:
            f = open(name + '.moves', 'r+')
            monster.history = pickle.load(f)
            f.close()
        except Exception:
            pass

    def _save_history(self, monster):
        name = 'player'
        if monster.name.lower() != 'player':
#.........这里部分代码省略.........
开发者ID:schiem,项目名称:ai_project,代码行数:103,代码来源:world.py


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