def run(self): tournament_data = [] validator = TournamentDataValidator() prompt = (('Nom (max. 50 caractères): ', validator.is_name_ok), ('Description (max. 50 caractères): ', validator.is_description_ok), ('Lieu (max. 50 caractères): ', validator.is_place_ok), ('Date de début (jj/mm/aaaa): ', validator.is_start_date_ok), ('Date de fin (jj/mm/aaaa): ', validator.is_end_date_ok), ('Nombre de rounds: (entier positif, par défaut: 4): ', validator.is_number_of_rounds_ok), ('Contrôle du temps (blitz / bullet / coup rapide): ', validator.is_time_control_ok)) for message, check_function in prompt: user_input = ViewPrompt(message).show() while not check_function(user_input): ViewText("Erreur de saisie, veuillez recommencer.").show() user_input = ViewPrompt(message).show() tournament_data.append(user_input) tournament = Tournament(*tournament_data) if tournament not in self.tournament_database: tournament.players = ControllerChoosePlayer( self.player_database).run() self.tournament_database.append(tournament) ViewText("Création du tournoi terminée avec succès.").show() ControllerSaveTournament(tournament).run() else: ViewText( "Erreur: le tournoi existe déjà (même nom, dates, contrôle du temps." ).show()
def resume(tournament): tournament_instance = Tournament() tournament_instance.id = tournament["id"], tournament_instance.name = tournament["name"], tournament_instance.players = tournament_instance.deserialized_player(tournament["players"]) tournament_instance.date = tournament["date"], tournament_instance.number_of_turns = tournament["number_of_turns"], tournament_instance.turns = tournament_instance.deserialize_turns(tournament["turns"]), tournament_instance.turns = tournament_instance.turns[0] tournament_instance.time_control = tournament["time_control"], tournament_instance.description = tournament["description"], return tournament_instance