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


Python AI.remove_creature_state方法代码示例

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


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

示例1: Game

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import remove_creature_state [as 别名]
class Game(object):

    def __init__(self, game_name, cursor_lib):
        self.game_name = game_name
        self.ai = AI()
        self.turn_counter = 0
        self.time = 0

        self.world = get_world()
        self.io, self.user_controller = self.init_nonserializable_objects(cursor_lib)

    def init_nonserializable_objects(self, cursor_lib_callback):
        self.io = WindowSystem(cursor_lib_callback())
        self.user_controller = UserController(GameActions(self, self.player))
        register_status_texts(self.io, self, self.player)
        return self.io, self.user_controller

    player = property(lambda self: self.world.player)
    active_level = property(lambda self: self.world.player.level)

    def main_loop(self):
        ai_game_actions = GameActions(self)
        self.io.msg("{0} for help menu".format(Bind.Help.key))
        while True:
            creature, time_delta = self.active_level.turn_scheduler.advance_time()
            self.time += time_delta

            if creature is self.player:
                self.update_view(creature)
                self.user_controller.actions._clear_action()
                self.user_controller.act()
                action_cost = self.user_controller.actions.action_cost

                if action_cost > 0:
                    self.turn_counter += 1
            else:
                ai_game_actions._clear_action(and_associate_creature=creature)
                self.ai.act(ai_game_actions, self.player.coord)
                action_cost = ai_game_actions.action_cost

            assert action_cost >= 0, \
                "Negative cost actions are not allowed (yet at least).{}".format(action_cost)

            creature_check, time_delta = self.active_level.turn_scheduler.addpop(creature, action_cost)
            assert creature is creature_check
            assert time_delta == 0

    def move_creature_to_level(self, creature, world_point):
        try:
            target_level = self.world.get_level(world_point.level_key)
        except LevelNotFound:
            return False

        creature.level.remove_creature(creature)
        target_level.add_creature_to_location(creature, world_point.level_location)

        try:
            creature.vision.clear()
        except AttributeError:
            pass

        if creature is self.player:
            self.redraw()

        return True

    def creature_death(self, creature):
        self.ai.remove_creature_state(creature)
        if creature is self.player:
            self.io.get_key("You die...", keys=Bind.Cancel)
            self.endgame()
        creature.level.remove_creature(creature)

    def endgame(self):
        exit()

    def savegame(self):
        try:
            raw, compressed = state_store.save(self, self.game_name)
        except IOError as e:
            msg_str = str(e)
        else:
            msg_str = "Saved game '{}', file size: {:,} b, {:,} b compressed. Ratio: {:.2%}"
            msg_str = msg_str.format(self.game_name, raw, compressed, raw / compressed)
        return msg_str

    def update_view(self, creature):
        """
        Update the vision set of the creature.

        This operation should only be done on creatures that have the .vision
        attribute ie. AdvancedCreatures for instance.
        """
        if not isinstance(creature, RemembersVision):
            raise ValueError("Creature {} doesn't have the capacity to remember its vision.")

        lvl = creature.level
        new_vision = ShadowCast.get_light_set(lvl.is_see_through, creature.coord,
                                              creature.sight, lvl.rows, lvl.cols)
        creature.vision, old_vision = new_vision, creature.vision
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


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