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


Python Game.__new__方法代码示例

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


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

示例1: playback

# 需要导入模块: from hearthbreaker.engine import Game [as 别名]
# 或者: from hearthbreaker.engine.Game import __new__ [as 别名]
def playback(replay):
    """
    Create a game which can be replayed back out of a replay.

    :param replay: The replay to load the game out of
    :type replay: :class:`Replay`
    :return: A game which when played will perform all of the actions in the replay.
    :rtype: :class:`Game <hearthbreaker.game_objects.Game>`
    """
    move_index = -1
    k_index = 0
    random_index = 0
    game = None

    class ReplayAgent:

        def __init__(self):
            self.next_target = None
            self.next_index = -1
            self.next_option = None

        def do_card_check(self, cards):
            nonlocal k_index
            keep_arr = [False] * len(cards)
            for index in replay.keeps[k_index]:
                keep_arr[int(index)] = True
            k_index += 1
            return keep_arr

        def do_turn(self, player):
            nonlocal move_index, random_index
            while move_index < len(replay._moves) and not player.hero.dead and type(
                    replay._moves[move_index]) is not hearthbreaker.serialization.move.TurnEndMove:
                random_index = 0
                replay._moves[move_index].play(game)
                move_index += 1
            if move_index == len(replay._moves):
                player.game.game_ended = True

        def set_game(self, game):
            pass

        def choose_target(self, targets):
            return self.next_target

        def choose_index(self, card, player):
            return self.next_index

        def choose_option(self, options, player):
            return options[self.next_option]
    game = Game.__new__(Game)
    _old_random_choice = game.random_choice
    _old_start_turn = game._start_turn
    _old_end_turn = game._end_turn
    _old_pre_game = game.pre_game

    def _generate_random_between(lowest, highest):
        nonlocal random_index
        if len(replay.random) == 0:
            return 0
        else:
            random_index += 1
            if move_index == -1:
                return replay.random[random_index - 1]
            return replay._moves[move_index].random_numbers[random_index - 1]

    def random_choice(choice):
        nonlocal move_index, random_index
        if isinstance(replay._moves[move_index].random_numbers[random_index], hearthbreaker.proxies.ProxyCharacter):
            result = replay._moves[move_index].random_numbers[random_index].resolve(game)
            random_index += 1
            return result
        return _old_random_choice(choice)

    def _start_turn():
        nonlocal move_index, random_index
        random_index = 0
        _old_start_turn()
        move_index += 1

    def _end_turn():
        nonlocal move_index, random_index
        random_index = 0
        _old_end_turn()
        move_index += 1

    def pre_game():
        nonlocal move_index
        _old_pre_game()
        move_index = 0

    game.random_choice = random_choice
    game._generate_random_between = _generate_random_between
    game._end_turn = _end_turn
    game._start_turn = _start_turn
    game.pre_game = pre_game

    game.__init__(replay.decks, [ReplayAgent(), ReplayAgent()])
    return game
开发者ID:5alamander,项目名称:hearthbreaker,代码行数:101,代码来源:replay.py


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