Exemplo n.º 1
0
    def players_menu(self):
        v_menu.View().players_menu()
        self.menu_number = c_input.Input().select_menu_number(5)

        #  Call for create player
        if self.menu_number == 1:
            player = m_players.Player()
            Controller().players_menu()

        # Call search player and call modify player
        elif self.menu_number == 2:
            self.find_player = m_search.Search().player(
                c_input.Input().check_input('text', 'Nom ou Prénom: '))
            if self.find_player == 'None':
                Controller().players_menu()
            else:
                player = m_players.Player(self.find_player)
                player.modify(c_input.Input().check_input(
                    'number', 'Nouveau classement: '))
            Controller().players_menu()

        # Call list player
        elif self.menu_number == 3:
            v_menu.View().list_menu()
            m_list.List().players(c_input.Input().select_menu_number(2))
            Controller().players_menu()

        # Back to main menu
        elif self.menu_number == 4:
            Controller().main_menu()

        # Close app
        elif self.menu_number == 5:
            pass
Exemplo n.º 2
0
    def list_rounds(self):
        if len(self.rounds) < self.stat:

            for i_rounds in range(len(self.rounds)):
                i_rounds_key = str(i_rounds + 1)
                v_menu.View().rounds_nbr(
                    i_rounds_key, self.rounds[i_rounds_key]['time'][0],
                    self.rounds[i_rounds_key]['time'][1]
                )
                for i_matchs in range(len(
                    self.rounds[i_rounds_key]['matchs']
                )):
                    player1 = m_players.Player(
                        self.rounds[i_rounds_key]['matchs'][i_matchs][0][0]
                    )
                    player2 = m_players.Player(
                        self.rounds[i_rounds_key]['matchs'][i_matchs][1][0]
                    )
                    v_menu.View().list_rounds(
                        i_matchs + 1, player1.name,
                        player1.surname, player2.name, player2.surname,
                        self.rounds[i_rounds_key]['matchs'][i_matchs][0][1],
                        self.rounds[i_rounds_key]['matchs'][i_matchs][1][1]
                    )
                input("\nEntrer pour afficher la suite")
Exemplo n.º 3
0
    def create_tournament(self):

        self.tournament_name = c_input.Input().check_input(
            'text', 'Nom du tournois: ')
        self.tournament_place = c_input.Input().check_input(
            'text', 'Lieu du tournois: ')
        self.tournament_start = c_input.Input().check_input(
            'date', 'Date de début: ')
        self.tournament_end = c_input.Input().check_input(
            'date', 'Date de fin: ')
        self.tournament_rounds = c_input.Input().rounds_tournament(
            'Nombre de tours (4 par défaut): ')

        v_menu.View().short('tournament_timing')
        self.menu_number = c_input.Input().select_menu_number(3)
        if self.menu_number == 1:
            self.tournament_timing = 'BULLET'
        elif self.menu_number == 2:
            self.tournament_timing = 'BLITZ'
        elif self.menu_number == 3:
            self.tournament_timing = 'COUP RAPIDE'

        self.tournament_description = c_input.Input().check_input(
            'text', 'Description: ')

        # Add players with creation or search
        self.players = []
        while True:

            v_menu.View().short('add_players')
            self.number = c_input.Input().select_menu_number(2)

            # Search player and add in players list for tournament
            if self.number == 1:
                self.find_player = m_search.Search().player(
                    c_input.Input().check_input('text', 'Nom ou Prénom: '))

                if self.find_player == 'None':
                    pass
                else:
                    self.players.append(self.find_player)
                    v_menu.View().short('player_added')

            # Create player & add in players list for tournament
            elif self.number == 2:
                self.player_created = m_players.Player()
                self.players.append(self.player_created.id)
                v_menu.View().short('player_added')

            if len(self.players) == 8:
                break

        return ([
            self.tournament_name, self.tournament_place, self.tournament_start,
            self.tournament_end, self.tournament_rounds,
            self.tournament_timing, self.tournament_description, self.players
        ])
Exemplo n.º 4
0
    def players(self, order):

        self.order = order
        p_tab = TinyDB('app/data/db_player.json').table('players')

        all_players = p_tab.all()
        list_players = []
        for i in range(len(all_players)):
            p_data = ()
            p_data = (
                all_players[i].get("surname"),
                all_players[i].get('name'),
                all_players[i].get('birthday'),
                all_players[i].get('genre'),
                all_players[i].get('rank')
            )
            list_players.append(p_data)

        if self.order == 1:
            list_a = sorted(list_players, key=lambda colonnes: colonnes[0])

        elif self.order == 2:
            list_a = sorted(
                list_players, key=lambda colonnes: colonnes[4], reverse=True
            )

        for i in range(len(list_a)):
            v_menu.View().list_players(
                list_a[i][0], list_a[i][1], list_a[i][2],
                list_a[i][3], list_a[i][4]
            )

        input('\nEntrer pour revenir au menu précédent')
Exemplo n.º 5
0
    def list_players(self, order):
        self.order = order
        list_players = []
        for i in range(len(self.players)):
            player = m_players.Player(self.players[i])
            p_data = ()
            p_data = (
                player.surname,
                player.name,
                player.genre,
                player.rank,
                player.get_score(self.id)
            )
            list_players.append(p_data)

        if self.order == 1:
            list_a = sorted(list_players, key=lambda colonnes: colonnes[0])
        elif self.order == 2:
            list_a = sorted(
                list_players, key=lambda colonnes: colonnes[3], reverse=True
            )
        elif self.order == 3:
            list_a = sorted(
                list_players, key=lambda colonnes: colonnes[4], reverse=True
            )
        for i in range(len(list_a)):
            v_menu.View().list_players_t(
                list_a[i][0], list_a[i][1], list_a[i][2],
                list_a[i][3], list_a[i][4]
            )

        input('\nEntrer pour revenir au menu précédent')
Exemplo n.º 6
0
    def tournaments_menu(self):
        v_menu.View().tournaments_menu()
        self.menu_number = c_input.Input().select_menu_number(5)

        # Call for create tounament
        if self.menu_number == 1:
            m_tournaments.Tournament()
            Controller().tournaments_menu()

        # Search and load tounament
        elif self.menu_number == 2:
            self.find_tournament = m_search.Search().tournament(
                c_input.Input().check_input('text', 'Nom ou Lieu: '))
            if self.find_tournament == 'None':
                Controller().tournaments_menu()
            else:
                Controller().current_tournament_menu(self.find_tournament)

        # Call list tounaments
        elif self.menu_number == 3:
            m_list.List().tournaments()
            Controller().tournaments_menu()

        # Back to main menu
        elif self.menu_number == 4:
            Controller().main_menu()

        # Close app
        elif self.menu_number == 5:
            pass
Exemplo n.º 7
0
    def current_tournament_menu(self, id):
        self.tournament = m_tournaments.Tournament(id)

        self.show_menu = v_menu.View().current_tournament_menu(
            self.tournament.name, self.tournament.stat, self.tournament.start,
            self.tournament.end, self.tournament.rounds_nbr)
        self.menu_number = c_input.Input().select_menu_number(6)

        # Start round
        if self.menu_number == 1:
            if self.tournament.stat > self.tournament.rounds_nbr:
                self.current_tournament_menu(self.tournament.id)
            else:
                self.tournament.start_rounds()
                self.tournament.stat += 1
                self.current_tournament_menu(self.tournament.id)

        # List players
        elif self.menu_number == 2:
            v_menu.View().list_menu_t()
            self.tournament.list_players(c_input.Input().select_menu_number(3))
            self.current_tournament_menu(self.tournament.id)

        # List matchs et rounds
        elif self.menu_number == 3:
            self.tournament.list_rounds()
            self.current_tournament_menu(self.tournament.id)

        # Show tournament infos
        elif self.menu_number == 4:
            v_menu.View().list_tournaments(
                self.tournament.name, self.tournament.place,
                self.tournament.start, self.tournament.end,
                self.tournament.rounds_nbr, self.tournament.timing,
                self.tournament.description)
            input('\nEntrer pour revenir au menu précédent')
            self.current_tournament_menu(self.tournament.id)

        # Back to tournament menu
        elif self.menu_number == 5:
            Controller().tournaments_menu()

        # Close app
        elif self.menu_number == 6:
            pass
Exemplo n.º 8
0
    def select_menu_number(self, menu_len):
        self.menu_len = menu_len
        self.menu_number = 0
        while self.menu_number < 1:
            try:
                self.menu_number = int(input('Faire un choix : '))

                if self.menu_number < 1:
                    v_menu.View().short("err_choise")

                elif self.menu_number > int(self.menu_len):
                    v_menu.View().short("err_choise")
                    self.menu_number = 0

            except ValueError:
                v_menu.View().short("err_choise")
                self.menu_number = 0
        return self.menu_number
Exemplo n.º 9
0
    def modify(self, new_rank):

        q = Query()
        p_tab = TinyDB('app/data/db_player.json').table('players')

        self.rank = new_rank
        p_tab.update({"rank": self.rank}, q.id == self.id)

        v_menu.View().modify_player(
            self.surname, self.name, self.birthday, self.rank
        )
Exemplo n.º 10
0
    def rounds_tournament(self, desc):
        self.input = input(desc)
        while True:
            self.input = str(self.input)
            if (len(self.input) == 0):
                self.input = 4
                v_menu.View().short('default_rounds')
                break
            else:
                self.input = int(self.input)
                try:
                    if self.input <= 0:
                        v_menu.View().short("err_number")
                        self.input = int(input(desc))
                    else:
                        break
                except ValueError:
                    v_menu.View().short("err_number")
                    self.input = int(input(desc))

        return self.input
Exemplo n.º 11
0
    def player(self, name):
        """ Find player in DB, return player id or None """

        self.name = name
        q = Query()
        data = TinyDB('app/data/db_player.json').table('players')

        self.search_result = data.search(
                (q.name == self.name) |
                (q.surname == self.name)
            )

        if len(self.search_result) == 0:
            v_menu.View().search('player_none')
            return 'None'

        elif len(self.search_result) == 1:
            v_menu.View().search_players(
                'find_player',
                self.search_result[0]['name'],
                self.search_result[0]['surname'],
                self.search_result[0]['birthday'],
                self.search_result[0]['rank']
            )
            return self.search_result[0]['id']

        elif len(self.search_result) >= 2:
            for i in range(len(self.search_result)):
                v_menu.View().search_players(
                    'find_players',
                    self.search_result[i]['name'],
                    self.search_result[i]['surname'],
                    self.search_result[i]['birthday'],
                    self.search_result[i]['rank'], i+1
                )

            self.player_number = c_input.Input().select_menu_number(
                len(self.search_result))

            return self.search_result[self.player_number-1]['id']
Exemplo n.º 12
0
    def check_input(self, type, desc):

        self.type = type

        if self.type == 'text':
            self.input = str(input(desc)).upper()
            while (len(self.input) == 0):
                self.input = str(input(desc)).upper()
            return self.input

        elif self.type == 'genre':
            while True:
                self.input = input(desc).upper()
                if self.input == 'M' or self.input == 'F':
                    break
            return self.input

        elif self.type == 'number':
            self.input = -1
            while self.input < 0:
                try:
                    self.input = int(input(desc))
                    if self.input < 0:
                        v_menu.View().short("err_number")
                except ValueError:
                    v_menu.View().short("err_number")
            return self.input

        elif self.type == 'date':
            while True:
                try:
                    self.input = input(desc)
                    date = datetime.datetime.strptime(self.input, '%d/%m/%Y')
                    date = date.date()
                    break
                except ValueError:
                    v_menu.View().short("err_date")
            return self.input
Exemplo n.º 13
0
    def tournaments(self):

        t_tab = TinyDB('app/data/db_tournaments.json').table('tournaments')
        all_tournaments = t_tab.all()

        for i in range(len(all_tournaments)):
            v_menu.View().list_tournaments(
                all_tournaments[i]['name'],
                all_tournaments[i]['place'], all_tournaments[i]['start'],
                all_tournaments[i]['end'], all_tournaments[i]['rounds_nbr'],
                all_tournaments[i]['timing'], all_tournaments[i]['description']
            )

        input('\nEntrer pour revenir au menu précédent')
Exemplo n.º 14
0
    def tournament(self, name):
        """ Find tournament in DB, return tournament id or None """
        self.name = name
        q = Query()
        data = TinyDB('app/data/db_tournaments.json').table('tournaments')

        self.search_result = data.search(
                (q.name == self.name) |
                (q.place == self.name)
            )

        if len(self.search_result) == 0:
            v_menu.View().search('tournament_none')
            return 'None'

        elif len(self.search_result) == 1:
            v_menu.View().search_tournaments(
                'find_tournament',
                self.search_result[0]['name'],
                self.search_result[0]['place'],
                self.search_result[0]['start']
            )
            return self.search_result[0]['id']

        elif len(self.search_result) >= 2:
            for i in range(len(self.search_result)):
                v_menu.View().search_tournaments(
                    'find_tournaments',
                    self.search_result[i]['name'],
                    self.search_result[i]['place'],
                    self.search_result[i]['start'], i+1
                )

            self.player_number = c_input.Input().select_menu_number(
                len(self.search_result))

            return self.search_result[self.player_number-1]['id']
Exemplo n.º 15
0
    def main_menu(self):
        v_menu.View().main_menu()
        self.menu_number = c_input.Input().select_menu_number(3)

        # Call player menu
        if self.menu_number == 1:
            Controller().players_menu()

        # Call tournaments menu
        elif self.menu_number == 2:
            Controller().tournaments_menu()

        # Close app
        elif self.menu_number == 3:
            pass
Exemplo n.º 16
0
    def start_rounds(self):
        self.players_list = self.gen_match(self.stat)

        self.players_score = []
        self.round_start = datetime.datetime.now().strftime("%H:%M:%S")
        self.match = 1
        self.player_id = 0

        while self.match < 5:

            self.player1 = m_players.Player(self.players_list[self.player_id])
            self.player_id += 1
            self.player2 = m_players.Player(self.players_list[self.player_id])
            self.player_id += 1

            v_menu.View().current_round(
                self.stat, self.match, self.player1, self.player2
            )
            self.winner = c_input.Input().select_menu_number(3)

            if self.winner == 1:
                self.player1.update_score(self.id, 1)
                self.player1_score = 1
                self.player2_score = 0
            elif self.winner == 2:
                self.player2.update_score(self.id, 1)
                self.player1_score = 0
                self.player2_score = 1
            elif self.winner == 3:
                self.player1.update_score(self.id, 0.5)
                self.player2.update_score(self.id, 0.5)
                self.player1_score = 0.5
                self.player2_score = 0.5
            self.match += 1
            self.players_score.append([
                [self.player1.id, self.player1_score],
                [self.player2.id, self.player2_score]
            ])
        self.round_end = datetime.datetime.now().strftime("%H:%M:%S")

        self.rounds[self.stat] = {
            'time': [self.round_start, self.round_end],
            'matchs': self.players_score
        }
        self.stat += 1
        self.save()
Exemplo n.º 17
0
    def set_data_from_input(self):
        """ Create player and insert in DB players """

        p_tab = TinyDB('app/data/db_player.json').table('players')
        call_input = c_players.playersControl().create_players()

        self.name = call_input[0]
        self.surname = call_input[1]
        self.birthday = call_input[2]
        self.genre = call_input[3]
        self.rank = call_input[4]
        self.id = str(datetime.datetime.now())

        p_tab.insert({
            'name': self.name,
            'surname': self.surname,
            'birthday': self.birthday,
            'genre': self.genre,
            'rank': self.rank,
            'scores': {},
            'id': self.id
        })
        v_menu.View().save_player(self.name, self.surname)
        return self.id