def test_prepare_turn(self, mocker): mocker.spy(Deck, 'check_stack') mocker.spy(Round, 'check_knocked') round1 = Round(1) round1.prepare_turn() assert Deck.check_stack.call_count == 1 assert Round.check_knocked.call_count == 1
class Play: def __init__(self): ConsoleConfig.colorama() setup = SetupPlayers() self.players = setup.create_players() self.ai_only = not any(isinstance(x, Human) for x in self.players) self.score = Score(self.players) self.round = Round(self.players) self.round.deal_cards(self.players) self.play_game() def play_game(self): while self.round.last_turn != len(self.players): self.round.prepare_turn() player = self.players[self.round.current_player] player.turn(self.round, self.ai_only) self.round.end_turn() self.end_round() sleep(1.2) self.start_new_round_or_end_game() def start_new_round_or_end_game(self): if self.score.is_end_of_game(): self.score.end_game() else: self.round.rotate_first_player() if not self.ai_only: self.confirm_start_new_round() self.round.prepare_new_round() self.round.deal_cards(self.players) self.play_game() def confirm_start_new_round(self): print("\nReady %s?" % self.players[self.round.current_player]) ready = '' while ready.lower() != 'y': ready = input("Enter " + Colour.green('y') + " when you are ready for the next round: ") def end_round(self): self.score.update_player_scores() self.score.render_this_round_score()
class Play: def __init__(self): self.colorama() players = Players() players.choose_players() players.choose_opponents() self.players = players.get_players() self.ai_only = players.is_ai_only() self.score = Score(self.players) self.round = Round(self.players) self.round.deal_cards(self.players) self.play_game() @staticmethod def colorama(): if 'PYCHARM_HOSTED' in os.environ: convert = False # in PyCharm, we should disable convert strip = False else: convert = None strip = None colorama.init(convert=convert, strip=strip) def play_game(self): while self.round.last_turn != len(self.players): self.round.prepare_turn() player = self.players[self.round.current_player] player.turn(self.round) # Todo: Views should be agnostic. Each template will have placeholders for data. # Todo: Player should return data to be displayed in views placeholders. controller = self._select_player_controller(player) controller.show_start_turn(player) controller.show_knocked(player) controller.draw_card(player) controller.show_end_turn(player) controller.discard_or_knock(player) controller.show_discard(player) self.round.end_turn() View.render(self.end_round()) sleep(1.2) if self.score.is_end_of_game(): View.render(self.score.show_winners()) else: self.start_new_round() def _select_player_controller(self, player): if isinstance(player, Human): controller = HumanController else: controller = AiController return controller def start_new_round(self): self.round.rotate_first_player() if not self.ai_only: self.confirm_start_new_round() self.round.prepare_new_round() self.round.deal_cards(self.players) self.play_game() @staticmethod def confirm_start_new_round(): UserInput.create_input(MenuActionDialog.next_round()) def end_round(self): self.score.update_player_scores() return RoundView.this_round_score(self.score.get_end_of_round_scores(), self.score.get_current_game_scores())