本文整理汇总了Python中durak.controller.GameController.is_game_over方法的典型用法代码示例。如果您正苦于以下问题:Python GameController.is_game_over方法的具体用法?Python GameController.is_game_over怎么用?Python GameController.is_game_over使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durak.controller.GameController
的用法示例。
在下文中一共展示了GameController.is_game_over方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlayFrame
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_game_over [as 别名]
#.........这里部分代码省略.........
self._check_for_game_over()
def _engine_move(self):
assert self._controller.state == self._controller.States.MOVING
assert self._controller.to_move == self.ENGINE
card = self._engine.move(
self._controller.on_table,
self._controller.get_game_data_for(self.ENGINE)
)
self._controller.register_move(card)
if card:
self._table.move(card)
self._top_player_sizer.decrement()
if self._controller.state == self._controller.States.DEALING:
self._deal()
else:
self._set_enabled_cards_and_controls()
self._check_for_game_over()
def _deal(self):
deal_data = self._controller.deal()
self._engine.deal(
deal_data['player2_cards'],
self._controller.get_game_data_for(self.ENGINE)
)
self._top_player_sizer.increment(len(deal_data['player2_cards']))
self._table.remove_all()
self._deck.set_card_count(self._controller.deck_count)
for card in deal_data['player1_cards']:
self._bottom_player_sizer.add_card(card)
self._bottom_player_sizer.Layout()
self._set_enabled_cards_and_controls()
def _check_for_game_over(self):
if not self._controller.is_game_over():
return
wx.CallLater(0, self._new_game_dialog)
def _new_game_dialog(self):
if self._controller.winner == self.HUMAN:
text = u'Победа!'
elif self._controller.winner == self.ENGINE:
text = u'Вы проиграли.'
else:
text = u'Ничья.'
dialog = wx.MessageDialog(
None,
u'%s Сыграем еще раз?' % text,
u'Игра окончена',
wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION
)
if (dialog.ShowModal() == wx.ID_YES):
self._start_new_game()
else:
self.Close()
def _stop_engine(self):
if self._engine is not None:
self._engine.game_end()
self._engine = None
@property
def _remained_give_more(self):
assert self._controller.state == self._controller.States.GIVING_MORE
return (
(self._top_player_sizer.count - 1) -
len(self._table.given_more)
)
def _on_select_engine(self, event):
dialog = SelectEngineDialog()
dialog.ShowModal()
if dialog.selected_engine:
self._engine_path = dialog.selected_engine
dialog.Destroy()
def _get_engine_path(self):
if self._engine_path is not None:
return self._engine_path
path = None
engines = get_setting(consts.ENGINES_SETTING, consts.DEFAULT_ENGINES)
for engine_data in engines:
if engine_data.get('selected'):
path = engine_data['path']
break
self._engine_path = path
return self._engine_path
示例2: test_is_game_over_is_false_if_state_is_not_none
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_game_over [as 别名]
def test_is_game_over_is_false_if_state_is_not_none(self):
controller = GameController()
controller._state = controller.States.MOVING
self.assertFalse(controller.is_game_over())
示例3: _play_game
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_game_over [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
示例4: test_is_game_over_is_true_if_state_is_none
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_game_over [as 别名]
def test_is_game_over_is_true_if_state_is_none(self):
controller = GameController()
controller._state = None
self.assertTrue(controller.is_game_over())