當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。