Exemple #1
0
    def __call__(self):
        lenght = tournamentmodel.TournamentModel()
        lenght_db = lenght.get_length_db()
        call = view.CallTournamentNumber()
        tournament_number = call.ask_number()

        if tournament_number > lenght_db:
            call.ask_again()
            self.__call__()

        else:
            tournament = TournamentController()
            tournament.round_players(tournament_number)
            action = tournament.round_selection(tournament_number)
            menu = FrontController()

            if action[0] is not None:
                menu.start()
            else:
                tournament.call_final_score()
                ask_rank = view.RankChange()
                change_ranks = ask_rank.ask_ended_tournament()

                if change_ranks == "yes":
                    new_ranks = tournament.ask_rank_modification(action[1])
                    tournament.final_rank_modification(new_ranks,
                                                       tournament_number,
                                                       action[1])

        menu.start()
Exemple #2
0
 def show_players_name(self):
     """
     Call tournamentmodel functions to get all saved players sort by name
     Display them to the user through the view
     """
     self.model = tournamentmodel.TournamentModel()
     informations = self.model.total_players_name()
     info_type = "nom"
     self.level.print_sorted_players(info_type, informations)
     self.__call__()
Exemple #3
0
    def show_tournaments(self):
        """sub menu of the tournament choice in main show menu"""
        answer = self.level.ask_type_tournament()
        self.model = tournamentmodel.TournamentModel()

        if answer == "total":
            all_tournaments = self.model.get_total_tournaments()
            self.level.print_tournaments_list(all_tournaments)
            self.show_specific_informations()
        elif answer == "unfinished":
            unfinished_tournaments = self.model.get_unfinished_tournaments()
            self.level.print_unfinished_tournaments(unfinished_tournaments)
            self.show_specific_informations()
        elif answer == "back":
            self.__call__()
        else:
            print(
                "Merci d'entrer: 'total', 'unfinished' ou 'back'. Veiller à ne pas mettre de majuscules"
            )
            self.show_tournaments()
Exemple #4
0
    def round_selection(self, tournament_number):
        """
        Function to work through rounds
        Recognize if you're on the first round or another
        Create round objects
        Call model functions to decide on the paring
        Call for results through the RoundController
        Ask for rank change through view function
        Save rounds results through model function
        """

        self.tournament = tournamentmodel.TournamentModel()
        self.rank_change = view.RankChange()
        players_and_score = []
        players_and_score_other_round = []
        previous_round_number = self.tournament.get_round_number(
            tournament_number)
        number_of_round = 4 - previous_round_number
        action = None

        for r in range(number_of_round):
            one_round = RoundController()
            round_nb = previous_round_number + 1
            next_round = view.AskContinue().ask_go_next_round()

            if next_round == "yes":
                pass

            else:
                action = "menu"
                break

            if previous_round_number == 0:
                matchs_round_1 = one_round.first_round(self.round_players,
                                                       round_nb)
                start = matchs_round_1[1]
                end = matchs_round_1[2]

                for k in range(4):
                    players_and_score.append(matchs_round_1[0][k][0])
                    players_and_score.append(matchs_round_1[0][k][1])

                scores = sorted(players_and_score,
                                key=lambda x: x[2],
                                reverse=False)
                self.tournament.json_score_opponent_player(
                    scores, matchs_round_1[0], tournament_number, round_nb,
                    start, end)

                ask_rank_change = self.rank_change.ask_ongoing_tournament()
                if ask_rank_change == "yes":
                    pairing_and_rank = self.ask_rank_modification(
                        players_and_score)
                    self.final_rank_modification(pairing_and_rank,
                                                 tournament_number,
                                                 players_and_score)

            else:
                actual_round = self.tournament.get_previous_round_list(
                    tournament_number)
                round_player_list = []
                matchs_other_round = []

                for i in range(8):
                    one_player = playermodel.Player(actual_round[i])
                    round_player = one_player.match_player()
                    round_player_list.append(round_player)

                for j in range(1, 8, 2):
                    j1 = round_player_list[j - 1]
                    j2 = round_player_list[j]
                    match = (j1, j2)
                    matchs_other_round.append(match)

                score_other_round = one_round.other_round(
                    round_player_list, round_nb)
                start = score_other_round[1]
                end = score_other_round[2]
                self.score_other_round = []

                for k in range(4):
                    self.score_other_round.append(score_other_round[0][k][0])
                    self.score_other_round.append(score_other_round[0][k][1])

                ask_rank_change = self.rank_change.ask_ongoing_tournament()
                if ask_rank_change == "yes":
                    to_change = self.ask_rank_modification(
                        self.score_other_round)
                    self.final_rank_modification(to_change, tournament_number,
                                                 self.score_other_round)

                players_and_score_other_round = self.score_other_round
                self.tournament.json_score_opponent_player(
                    self.score_other_round, score_other_round[0],
                    tournament_number, round_nb, start, end)
            previous_round_number += 1

        return action, players_and_score_other_round
Exemple #5
0
 def json_save(self):
     """Call the model funciton to save bases informations about the new tournament"""
     save = tournamentmodel.TournamentModel()
     save.json_save(self.total_tournament)
Exemple #6
0
 def group_tournament_and_players(self):
     """Call a model function to group tournament and players informations"""
     tournament_infos = tournamentmodel.TournamentModel()
     self.total_tournament = tournament_infos.add_tournament_and_players(
         self.tournament_dict, self.players_list)
     return self.total_tournament
Exemple #7
0
 def __init__(self):
     """create object about other modules in the code (model, view and menu controller)"""
     self.tournament_input = menu.TournamentInput()
     self.players_input = menu.PlayersInput()
     self.tournament = tournamentmodel.TournamentModel()