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 show(self): ViewText(self.title).show() if not self.tournament.rounds: ViewText("\tPas disponible").show() else: for round_ in self.tournament.rounds: ViewRoundResult(round_).show()
def run(self): player_data = [] validator = PlayerDataValidator() prompt = (('Nom (max. 50 caractères): ', validator.is_last_name_ok), ('Prénom (max. 50 caractères): ', validator.is_first_name_ok), ('Date de naissance (jj/mm/aaaa): ', validator.is_date_of_birth_ok), ('Sexe (m/f): ', validator.is_sex_ok), ('classement (entier positif): ', validator.is_ranking_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() player_data.append(user_input) player = Player(*player_data) if player not in self.database: self.database.append(player) ViewText("Création du joueur terminée avec succès.").show() ControllerSavePlayer(player).run() else: ViewText( "Erreur: le joueur existe déjà (même nom, prénom et date de naissance)." ).show()
def show(self): ViewText(self.title).show() string_output = "\n".join([ "\t{} : {}".format( field, self.database_object.__getattribute__(attribute)) for field, attribute in tuple( zip(self.fields, self.object_attributes)) ]) ViewText(string_output).show()
def run(self): if self.player in self.tournament_players_list: ViewText( "Saisie non valide, {} {} est déjà inscrit au tournoi".format( self.player.first_name, self.player.last_name)).show() else: self.tournament_players_list.append(self.player) ViewText("{} {} est inscrit au tournoi.".format( self.player.first_name, self.player.last_name)).show()
def run(self): self.tournament.play_tournament() ViewText("Démarrage du tournoi").show() for round_ in self.tournament.rounds: if round_.status == "terminé": ViewRoundResult(round_).show() else: while round_.status != "terminé": ViewRoundResult(round_, mode_view_results=False).show() if round_.status == "pas encore commencé": mc.ControllerCommandInterpreter( "(t) Procéder au tirage des matchs", { "t": ControllerDrawGames(round_) }).run() round_.start() ControllerSaveTournament(self.tournament).run() continue else: if not round_.status == "matchs terminé, en attente de validation": commands = { str(i + 1): ControllerEnterResults(round_.games[i]) for i in range(len(round_.games)) } commands.update({ "s": ControllerSaveTournament(self.tournament) }) mc.ControllerCommandInterpreter( "(X) Entrer le résultat du match X\n" "(s) Sauvegarder le tournoi", commands).run() else: commands = { str(i + 1): ControllerEnterResults(round_.games[i]) for i in range(len(round_.games)) } commands.update({ "s": ControllerEndRound(self.tournament, round_) }) mc.ControllerCommandInterpreter( "(X) Entrer le résultat du match X\n" "(s) Sauvegarder le tournoi et passer au round suivant", commands).run() ViewRoundResult(round_).show() ViewText("Tournoi Terminé").show() mc.ControllerCommandInterpreter( "(r) Afficher le rapport de tournoi", { "r": ctd.ControllerTournamentReport(self.tournament, self.tournament_database) }).run()
def show(self): ViewText(self.title).show() if not self.score_table.score_table: string_output = "\tPas disponible" else: sorted_score_table = sorted(self.score_table.score_table.items(), key=itemgetter(1), reverse=True) string_output = "\n".join([ "{}\t{}: {}".format(i + 1, player, score) for (i, (player, score)) in enumerate(sorted_score_table) ]) ViewText(string_output).show()
def run(self): validator = PlayerDataValidator() user_input = ViewPrompt( "Veuillez saisir le nouveau classement (entier positif): ").show() while not validator.is_ranking_ok(user_input): ViewText("Erreur de saisie, veuillez recommencer.").show() user_input = ViewPrompt( "Veuillez saisir le nouveau classement (entier positif): " ).show() self.player.update_ranking(user_input) ViewText( "Le classement du joueur {} {} a été modifié (nouveau classement: {})" .format(self.player.first_name, self.player.last_name, self.player.ranking)).show() ControllerSavePlayer(self.player).run()
def show(self): ViewText("\t{} - {}".format(self.round_.name, self.round_.status).upper()).show() if not self.round_.games: ViewText("\t\tPas disponible").show() else: if self.round_.start_time != datetime(1970, 1, 1): print("Date et heure de début:", self.round_.start_time.strftime("%d/%m/%y %H:%M")) if self.round_.end_time != datetime(1970, 1, 1): print("Date et heure de fin:", self.round_.end_time.strftime("%d/%m/%y %H:%M")) print('') for i, game in enumerate(self.round_.games): ViewGameResult( i + 1, game, mode_view_results=self.mode_view_results).show()
def run(self): ViewText(self.message).show() user_command = ViewPrompt('Saississez votre commande : ').show() while not self.is_user_command_valid(user_command): user_command = ViewPrompt( 'Commande invalide. Veuillez réessayer : ').show() controller = self.commands[user_command] controller.run()
def run(self): ViewText("{} VS {}".format(self.game.pair[0], self.game.pair[1])).show() mc.ControllerCommandInterpreter( "(1 / n / 2) Entrez le résultat\n", { "1": ControllerUpdateResult(self.game, "1"), "n": ControllerUpdateResult(self.game, "n"), "2": ControllerUpdateResult(self.game, "2"), }).run()
def show(self): match_result_string_output = "\t".join([ resize_string("{}: {}".format(player, score), 30) for player, score in self.game.score_table.score_table.items() ]) game_number_display = " {} ".format(self.game_number) if self.mode_view_results \ else "({})".format(self.game_number) string_output = ''.join([ resize_string(game_number_display, 5), resize_string(self.game.status + ":", 22), match_result_string_output ]) ViewText(string_output).show()
def show(self): ViewText(self.title).show() if not self.database: headers_string_output = "La base de données est vide." data_list_string_output = "" else: self.database.sort(key=attrgetter(self.sort_by_attribute), reverse=self.sort_order) if self.headers: headers_string_output = " " * 6 \ + "".join([resize_string(header, 25).upper() for header in self.headers])\ + "\n" else: headers_string_output = "" data_list_string_output = "\n".join([ resize_string(self.highlight_command(i + 1), 6) + "".join([ resize_string(str(getattr(data, attribute)), 25) for attribute in self.attributes ]) for i, data in enumerate(self.database) ]) ViewText(headers_string_output + data_list_string_output).show()
def run(self): ViewText("Chess Tournament Manager - Menu principal.").show() ControllerCommandInterpreter( "\t(1) Ajouter un joueur\n" "\t(2) Ajouter un Tournoi\n" "\t(3) Voir les joueurs\n" "\t(4) Voir les tournois\n" "\t(q) Quitter le programme", { "1": ControllerNewPlayer(self.player_database), "2": ControllerNewTournament(self.tournament_database, self.player_database), "3": ControllerPlayerDatabase(self.player_database), "4": ControllerTournamentDatabase(self.tournament_database), "q": ControllerQuitProgram() }, return_to_menu=False).run()
def run(self): TournamentDatabaseConverter().save_tournament(self.tournament) ViewText("Sauvegarde de la base de données Tournoi.").show()
def run(self): PlayerDatabaseConverter().delete_player(self.player) self.player_database.remove(self.player) ViewText( "Le joueur {} {} a été supprimé de la base de données.".format( self.player.first_name, self.player.last_name)).show()
def run(self): PlayerDatabaseConverter().save_player(self.player) ViewText("Sauvegarde de la base de données Joueurs.").show()
def run(self): TournamentDatabaseConverter().delete_tournament(self.tournament) self.tournament_database.remove(self.tournament) ViewText( "Le tournoi \"{}\" a été supprimé de la base de données.".format( self.tournament.name)).show()