[docs]classGameFlow:""" Manages the flow of the Mastermind game. Args: game_state (GameState): The state of the game. player_logic (PlayerLogic): The logic for the players. """def__init__(self,game_state:GameParameter,player_logic:PlayerLogic)->None:self.game_state=game_stateself.player_logic=player_logic
[docs]defstart_game(self)->Optional[str]:""" Starts the game. Returns: Optional[str]: A command from the player, if any. """ifself.game_state.game_started:raiseNotImplementedError("Game has already started.")self.game_state.game_started=Trueself.player_logic.initialize_players()ifself.player_logic.PLAYER_SETTER.set_secret_code()=="d":return"d"# code setter discarded the gamereturnself._play_game()
[docs]defresume_game(self)->Optional[str]:""" Resumes the game. Returns: Optional[str]: A command from the player, if any. """ifnotself.game_state.game_started:raiseNotImplementedError("Game has not started yet.")returnself._play_game()
def_play_game(self)->Optional[str]:""" Plays the game and retrieves a command from the player, if any. Returns: Optional[str]: A command from the player, if any. """command=self.player_logic.process_player_guessing()self.output_result()returncommand
[docs]defoutput_result(self)->None:""" Outputs the result of the game. """self.game_state.check_and_update_win_status()ifself.game_state.win_statusisNone:returnifself.game_state.win_status:self.player_logic.PLAYER_CRACKER.win_message()else:self.player_logic.PLAYER_CRACKER.lose_message()