def resume_tournament(self):
     """
     request the name of the tournament
     :return:name of tournmaent (string)
     """
     cls()
     icon()
     self.list_tournament_not_over = list()
     for self.tournament_name in search_all_tournament():
         self.tournament = Tournament()
         self.tournament.read_in_db(self.tournament_name)
         if not self.tournament.tournament_over:
             self.list_tournament_not_over.append(self.tournament)
     print('Vous souhaitez reprendre un Tournoi, si la liste est vide, '
           'taper Entrée pour revenir au menu principal\n')
     print(("=" * 113).center(width_calculated()))
     print(f'| {"Nom du Tournoi".center(35)} |'
           f'{"Ville".center(35)} |'
           f'{"Date".center(35)} |'.center(width_calculated())
           )
     for self.tournament in self.list_tournament_not_over:
         print(("-" * 113).center(width_calculated()))
         print(f'| {self.tournament.name.center(35)} |'
               f'{self.tournament.location.center(35)} |'
               f'{self.tournament.date.center(35)} |'.center(width_calculated())
               )
     print(("-" * 113).center(width_calculated()))
     self.name_tournament = " "
     while not (self.name_tournament in search_all_tournament() or self.name_tournament == ""):
         self.name_tournament = input('Tapez le nom du Tournoi : ').capitalize()
     return self.name_tournament
 def read_player(self):
     """
     Generates a table of players and allows to choose a day thanks to its TinyDB ID
     :return: ID choice
     """
     cls()
     icon()
     self.list_all_players = list()
     for self.player_id in search_all_player():
         self.player = Player()
         self.player.load_player(self.player_id)
         self.list_all_players.append(self.player)
     print('Rechercher un Joueur pour ce Tournoi\n')
     print(("=" * 177).center(width_calculated()))
     print(f'| {"ID du Joueur".center(25)} |'
           f'{"Nom du Joueur".center(35)} |'
           f'{"Prénom du Joueur".center(35)} |'
           f'{"Date de naissance du joueur".center(35)} |'
           f'{"Rang".center(35)} |'.center(width_calculated())
           )
     self.list_all_players = sorted(self.list_all_players, key=lambda player: player.name)
     for self.player in self.list_all_players:
         print(("-" * 177).center(width_calculated()))
         print(f'| {str(self.player.id).center(25)} |'
               f'{self.player.name.center(35)} |'
               f'{self.player.first_name.center(35)} |'
               f'{self.player.date_born.center(35)} |'
               f'{str(self.player.rank).center(35)} |'.center(width_calculated())
               )
     print(("-" * 177).center(width_calculated()))
     self.ID = str()
     while not re.match(r"^[0-9]+$", self.ID):
         self.ID = input('Taper l ID du Joueur : ')
     return self.ID
 def show_match(self):
     """
     Displays a table of matches in the selected tournament
     """
     print("Stat des Matchs du Tournois\n".center(width_calculated()))
     self.counter = 0
     for self.round_dict in self.tournament_choice.list_rounds_played:
         for self.round, self.date in self.round_dict.items():
             self.counter += 1
             print("\n")
             print(("-" * 113).center(width_calculated()))
             print(
                 f'| {("Tour " + str(self.counter) + "  " + self.date).center(110)} |'
                 .center(width_calculated()))
             print(f'| {"Joueur 1".center(53)} VS'
                   f'{"Joueur 2".center(54)} |'.center(width_calculated()))
             print(("-" * 113).center(width_calculated()))
             self.list_matchs = []
             for self.player_id in self.round.round:
                 for self.player in self.tournament_choice.list_players:
                     if int(self.player_id) == self.player.id:
                         self.list_matchs.append(
                             str(self.player.name + " " +
                                 self.player.first_name + " -- point : " +
                                 str(self.round.round[self.player_id])))
             while self.list_matchs:
                 print(f'| {self.list_matchs.pop(0).center(53)} VS'
                       f'{self.list_matchs.pop(0).center(54)} |'.center(
                           width_calculated()))
                 print(("-" * 113).center(width_calculated()))
 def show_one_tournament(self):
     """
     Search if a tournament exists by entering its name
     :return: True if the torunoi exists, False if it does not exist
     """
     self.show_list_all_tournament()
     self.choice_tournament_name = input(
         "Taper le nom du Tournoi : ").capitalize()
     cls()
     icon()
     for self.tournament in self.list_tournaments:
         if self.choice_tournament_name == self.tournament.name:
             self.tournament_choice = self.tournament
             print("Stat du Tournoi Tournois\n".center(width_calculated()))
             print(("=" * 113).center(width_calculated()))
             print(f'| {"Nom du Tournoi".center(35)} |'
                   f'{"Ville".center(35)} |'
                   f'{"Date".center(35)} |'.center(width_calculated()))
             print(("-" * 113).center(width_calculated()))
             print(f'| {self.tournament.name.center(35)} |'
                   f'{self.tournament.location.center(35)} |'
                   f'{self.tournament.date.center(35)} |'.center(
                       width_calculated()))
             print(("-" * 113).center(width_calculated()))
             print("\n")
             return True
         else:
             return False
 def show_players_sort(self, sort_rank):
     """
     Displays a table of all the players in the database
     :param sort_rank: if sort_rank is True then the players are sorted according to their rank
     otherwise they will be sorted according to their name
     """
     cls()
     icon()
     print("Liste des Joueurs\n".center(width_calculated()))
     print(("=" * 150).center(width_calculated()))
     print(f'| {"ID du Joueur".center(35)} |'
           f'{"Nom du Joueur".center(35)} |'
           f'{"Prénom du Joueur".center(35)} |'
           f'{"Rang".center(35)} |'.center(width_calculated()))
     if sort_rank:
         self.list_players = sorted(self.list_players,
                                    key=lambda player: player.rank,
                                    reverse=True)
     else:
         self.list_players = sorted(self.list_players,
                                    key=lambda player: player.name)
     for self.player in self.list_players:
         print(("-" * 150).center(width_calculated()))
         print(f'| {str(self.player.id).center(35)} |'
               f'{self.player.name.center(35)} |'
               f'{self.player.first_name.center(35)} |'
               f'{str(self.player.rank).center(35)} |'.center(
                   width_calculated()))
     print(("-" * 150).center(width_calculated()))
 def show_player(self):
     """
     Displays a table of players in the selected tournament
     """
     self.sort_rank = input("1. Trier les Joueurs par Nom\n"
                            "2. Trier les Joueurs par Rang\n")
     if self.sort_rank == "1":
         self.sort_rank = None
     elif self.sort_rank == "2":
         self.sort_rank = True
     print("Liste des Joueurs\n".center(width_calculated()))
     print(("=" * 113).center(width_calculated()))
     print(f'| {"Nom du Joueur".center(35)} |'
           f'{"Prénom du Joueur".center(35)} |'
           f'{"Rang".center(35)} |'.center(width_calculated()))
     self.list_players = self.tournament_choice.list_players
     if self.sort_rank:
         self.list_players = sorted(self.list_players,
                                    key=lambda player: player.rank,
                                    reverse=True)
     else:
         self.list_players = sorted(self.list_players,
                                    key=lambda player: player.name)
     for self.player in self.list_players:
         print(("-" * 113).center(width_calculated()))
         print(f'| {self.player.name.center(35)} |'
               f'{self.player.first_name.center(35)} |'
               f'{str(self.player.rank).center(35)} |'.center(
                   width_calculated()))
     print(("-" * 113).center(width_calculated()))
    def print_table_tournament(self, list_player_object):
        """
        Display the list of players of a selected tournament
        :param list_player_object:
        """
        cls()
        icon()
        print(f'{"Liste des Joueurs pour ce Tournoi".center(width_calculated())}\n')

        print(("=" * 150).center(width_calculated()))
        print(f'| {"Nom".center(35)} |'
              f'{"Prénom".center(35)} |'
              f'{"Point total dans le Tournoi".center(35)} |'
              f'{"Rank".center(35)} |'.center(width_calculated())
              )
        for player in list_player_object:
            print(("-" * 150).center(width_calculated()))
            print(f'| {player.name.center(35)} |'
                  f'{player.first_name.center(35)} |'
                  f'{str(player.point).center(35)} |'
                  f'{str(player.rank).center(35)} |'.center(width_calculated())
                  )
        print(("=" * 150).center(width_calculated()))
    def list_player_in_game(self, list_player_object):
        """
        Generates an array of players in the tournament
        :param list_player_object:
        """
        cls()
        icon()
        print(f'{"Liste des Joueurs pour ce Tournoi".center(width_calculated())}\n')

        print(("=" * 150).center(width_calculated()))
        print(f'| {"Nom".center(35)} |'
              f'{"Prénom".center(35)} |'
              f'{"Date de Naissance".center(35)} |'
              f'{"Genre".center(35)} |'.center(width_calculated())
              )
        for player in list_player_object:
            print(("-" * 150).center(width_calculated()))
            print(f'| {player.name.center(35)} |'
                  f'{player.first_name.center(35)} |'
                  f'{str(player.date_born).center(35)} |'
                  f'{player.genre.center(35)} |'.center(width_calculated())
                  )
        print(("=" * 150).center(width_calculated()))
        input("Appuyer sur une Entrée pour continuer ...")
 def show_tour(self):
     """
     Displays a table of rounds in the selected tournament
     """
     print("Stat des Tours du Tournoi\n".center(width_calculated()))
     print(("=" * 113).center(width_calculated()))
     print(f'| {"Tour".center(54)} |'
           f'{"Date".center(53)} |'.center(width_calculated()))
     self.counter = 0
     for self.round_dict in self.tournament_choice.list_rounds_played:
         for self.round, self.date in self.round_dict.items():
             self.counter += 1
             print(("-" * 113).center(width_calculated()))
             print(f'| {("Tour " + str(self.counter)).center(53)} |'
                   f' {self.date.center(53)} |'.center(width_calculated()))
     print(("-" * 113).center(width_calculated()))
 def show_list_all_tournament(self):
     """
     Displays a table of all the tournaments in the DB
     """
     cls()
     icon()
     print("Liste de tous les Tournois\n".center(width_calculated()))
     print(("=" * 113).center(width_calculated()))
     print(f'| {"Nom du Tournoi".center(35)} |'
           f'{"Ville".center(35)} |'
           f'{"Date".center(35)} |'.center(width_calculated()))
     for self.tournament in self.list_tournaments:
         print(("-" * 113).center(width_calculated()))
         print(f'| {self.tournament.name.center(35)} |'
               f'{self.tournament.location.center(35)} |'
               f'{self.tournament.date.center(35)} |'.center(
                   width_calculated()))
     print(("-" * 113).center(width_calculated()))
 def director_comment(self):
     """
     Request the input of the tournament director's comment at the end of the tournament
     :return: text string
     """
     cls()
     icon()
     print('Espace reservé au Directeur du Tournoi \n'
           'Veuillez écrire un commentaire, une observation\n'
           'si vous ne souhaitez pas inscrire de commentaire, tapez Entrée'.center(width_calculated()))
     self.comment = input('commentaire : ')
     return self.comment
    def print_table_round(self, list_player_object, unique_round):
        """
        Generates a table of the tournament rounds
        :param list_player_object:
        :param unique_round:
        """
        cls()
        icon()
        print(f'{"Tournoi en cours".center(width_calculated())}\n')

        print(f'{"Tour1".center(width_calculated())}\n')
        print(f'{("=" * 96).center(width_calculated())}')
        for self.id1, self.id2 in unique_round:
            self.adverse1, self.adverse2 = "", ""
            for self.player in list_player_object:
                if self.id1 == self.player.id:
                    self.adverse1 = str(self.player.name + " " + self.player.first_name)
                elif self.id2 == self.player.id:
                    self.adverse2 = str(self.player.name + " " + self.player.first_name)
            print(f'|{self.adverse1.center(45)} VS {self.adverse2.center(45)}|'.center(width_calculated()))
        print(f'{("=" * 96).center(width_calculated())}')