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


Python GameController.start_new_game方法代码示例

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


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

示例1: test_if_winner_is_ignored_first_move_is_selected_by_trump

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
    def test_if_winner_is_ignored_first_move_is_selected_by_trump(self):
        controller = GameController()
        controller._winner = controller._player1

        with patch.object(controller,
                          '_get_first_to_move_by_trump') as _get_first_mock:
            controller.start_new_game()
            self.assertEqual(controller._to_move, _get_first_mock.return_value)
开发者ID:drtyrsa,项目名称:durak,代码行数:10,代码来源:tests.py

示例2: test_if_winner_is_none_first_move_is_selected_by_trump

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
    def test_if_winner_is_none_first_move_is_selected_by_trump(self):
        controller = GameController()
        self.assertTrue(controller._winner is None)

        with patch.object(controller,
                          '_get_first_to_move_by_trump') as _get_first_mock:
            controller.start_new_game()
            self.assertEqual(controller._to_move, _get_first_mock.return_value)
开发者ID:drtyrsa,项目名称:durak,代码行数:10,代码来源:tests.py

示例3: test_if_winner_and_not_ignored_it_selects_first_move

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
    def test_if_winner_and_not_ignored_it_selects_first_move(self):
        controller = GameController()
        controller._winner = controller._player1

        with patch.object(controller,
                          '_get_first_to_move_by_trump') as _get_first_mock:
            controller.start_new_game(ignore_winner=False)
            self.assertEqual(controller._to_move, controller._player1)
            self.assertFalse(_get_first_mock.called)
开发者ID:drtyrsa,项目名称:durak,代码行数:11,代码来源:tests.py

示例4: test_start_new_game_players_and_deck_cards

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
    def test_start_new_game_players_and_deck_cards(self):
        controller = GameController()
        controller.start_new_game()
        self.assertEqual(controller._trump, controller._deck[-1])

        all_cards = []
        all_cards.extend(controller._deck)
        all_cards.extend(controller._player1.cards)
        all_cards.extend(controller._player2.cards)
        self.assertItemsEqual(all_cards, DurakCard.all())
开发者ID:drtyrsa,项目名称:durak,代码行数:12,代码来源:tests.py

示例5: test_start_new_game_return_value_and_state

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
 def test_start_new_game_return_value_and_state(self):
     controller = GameController()
     result = controller.start_new_game()
     self.assertDictEqual(result, {
         'player1_cards': set(controller._player1.cards),
         'player2_cards': set(controller._player2.cards),
         'trump': controller._trump,
     })
     self.assertEqual(controller.state, controller.States.MOVING)
开发者ID:drtyrsa,项目名称:durak,代码行数:11,代码来源:tests.py

示例6: PlayFrame

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
class PlayFrame(wx.Frame):
    WIDTH = 800
    HEIGHT = 450

    HUMAN = GameController.PLAYER1
    ENGINE = GameController.PLAYER2

    def __init__(self):
        super(PlayFrame, self).__init__(
            parent=None,
            title='Durak GUI',
            size=(self.WIDTH, self.HEIGHT)
        )

        self._create_layout()

        self._controller = GameController(
            player1_name='HUMAN',
            player2_name='ENGINE',
            log_filename=get_filename('last_game'),
            overwrite_log=True
        )
        self._engine = None
        self._engine_path = None

        self._trump = None

        self._start_new_game()

    def _create_layout(self):
        self.Bind(wx.EVT_CLOSE, self._on_close)

        self._panel = wx.Panel(parent=self)

        self._top_player_sizer = EnemyCardSizer(
            wx.HORIZONTAL, parent=self._panel
        )
        self._bottom_player_sizer = CardSizer(
            wx.HORIZONTAL,
            parent=self._panel,
            on_click=self._on_bottom_player_card_click
        )

        self._table_sizer = wx.FlexGridSizer(cols=2, rows=1)
        self._table_sizer.AddGrowableCol(0)

        self._table = TablePanel(parent=self._panel)
        self._table_sizer.Add(self._table, proportion=1)

        self._deck = DeckPanel(self._panel, size=(100, 130))
        self._table_sizer.Add(self._deck)

        self._control_sizer = ControlSizer(wx.HORIZONTAL, parent=self._panel)
        self._control_sizer.set_on_discard_button_click(
            self._on_discard_button_click
        )
        self._control_sizer.set_on_enough_button_click(
            self._on_enough_button_click
        )
        self._control_sizer.set_on_take_button_click(
            self._on_take_button_click
        )

        self._main_sizer = wx.FlexGridSizer(cols=1, rows=4)
        self._main_sizer.AddGrowableCol(0)
        self._main_sizer.AddGrowableRow(1)
        self._main_sizer.Add(
            self._top_player_sizer, flag=wx.EXPAND, proportion=1
        )
        self._main_sizer.Add(
            self._table_sizer, flag=wx.ALIGN_CENTER_VERTICAL, proportion=1
        )
        self._main_sizer.Add(self._control_sizer, flag=wx.EXPAND, proportion=1)
        self._main_sizer.Add(
            self._bottom_player_sizer, flag=wx.EXPAND, proportion=1
        )

        self._panel.SetSizer(self._main_sizer)

        self.CreateStatusBar()

        self._create_menu()

        self._panel.Layout()
        self.Layout()
        self.Refresh()

    def _create_menu(self):
        self.menu = wx.MenuBar()
        menu = wx.Menu()  # Игра
        item = menu.Append(wx.ID_NEW, u'Новая игра', u'Начать новую игру')
        self.Bind(wx.EVT_MENU, self._start_new_game, item)
        item = menu.Append(wx.ID_EXIT, u'Выход', u'Выйти из игры')
        self.Bind(wx.EVT_MENU, self._on_close, item)
        self.menu.Append(menu, u'Игра')

        menu = wx.Menu()  # Настройки
        self._by_winner_menu_item = menu.AppendCheckItem(
            wx.ID_ANY,
            u'Ход под дурака',
#.........这里部分代码省略.........
开发者ID:drtyrsa,项目名称:durak,代码行数:103,代码来源:play.py

示例7: _play_game

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
def _play_game(engine1_path, engine2_path, log_filename=''):
    engine1 = EngineWrapper(engine1_path)
    engine2 = EngineWrapper(engine2_path)
    controller = GameController(
        player1_name=engine1_path,
        player2_name=engine2_path,
        log_filename=log_filename,
    )
    new_game_data = controller.start_new_game()

    engine1.init(new_game_data['trump'])
    engine2.init(new_game_data['trump'])

    engine1.deal(
        new_game_data['player1_cards'],
        controller.get_game_data_for(controller.PLAYER1)
    )
    engine2.deal(
        new_game_data['player2_cards'],
        controller.get_game_data_for(controller.PLAYER2)
    )

    while True:
        if controller.state == controller.States.MOVING:
            if controller.is_player1_to_move():
                engine_to_move = engine1
            else:
                engine_to_move = engine2

            card = engine_to_move.move(
                controller.on_table,
                controller.get_game_data_for(controller.MOVER)
            )
            controller.register_move(card)

        elif controller.state == controller.States.RESPONDING:
            if controller.is_player1_to_move():
                engine_to_respond = engine2
            else:
                engine_to_respond = engine1

            card = engine_to_respond.respond(
                controller.on_table,
                controller.get_game_data_for(controller.RESPONDER)
            )
            controller.register_response(card)

        elif controller.state == controller.States.GIVING_MORE:
            if controller.is_player1_to_move():
                engine_to_give_more = engine1
            else:
                engine_to_give_more = engine2

            cards = engine_to_give_more.give_more(
                controller.on_table,
                controller.get_game_data_for(controller.MOVER)
            )
            controller.register_give_more(cards)

        elif controller.state == controller.States.DEALING:
            deal_data = controller.deal()
            engine1.deal(
                deal_data['player1_cards'],
                controller.get_game_data_for(controller.PLAYER1)
            )
            engine2.deal(
                deal_data['player2_cards'],
                controller.get_game_data_for(controller.PLAYER2)
            )

        if controller.is_game_over():
            break

    engine1.game_end()
    engine2.game_end()

    if controller.winner == controller.PLAYER1:
        return ENGINE1
    elif controller.winner == controller.PLAYER2:
        return ENGINE2
    else:
        return DRAW
开发者ID:drtyrsa,项目名称:durak,代码行数:84,代码来源:autoplay.py

示例8: test_start_new_game_cards_are_shuffled

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import start_new_game [as 别名]
 def test_start_new_game_cards_are_shuffled(self):
     controller = GameController()
     with patch('durak.controller.random') as random_mock:
         controller.start_new_game()
         random_mock.shuffle.assert_called_once_with(list(DurakCard.all()))
开发者ID:drtyrsa,项目名称:durak,代码行数:7,代码来源:tests.py


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