Esempio n. 1
0
def main():
    score = 0
    computer_score = 0

    while 1:
        play = view.play_prompt().lower()
        if play == 'y':
            break
        else:
            if play == 'n':
                view.print_message('Would you prefer a good game of chess?')
                return ''

    board = model.init_pieces()
    view.refresh(board, model.get_score(board))
    # Main game loop
    while model.red_moves(board)[0] and model.black_moves(board)[0]:
        # Get user inputs
        source = view.get_input(moving=1)
        valid = model.validate_input(board, source, moving=1)
        if not valid[0]:
            view.print_message(valid[1])
            continue

        destination = view.get_input(moving=0)
        valid = model.validate_input(board, destination, moving=0)
        if not valid[0]:
            view.print_message(valid[1])
            continue

        move_from = [int(source[0]), int(source[2])]
        move_to = [int(destination[0]), int(destination[2])]

        # Check first if the player must perform a jump
        if model.player_jump_available(board, move_from, move_to):
            view.print_message("You must perform a jump")
            continue

        # Attempt move on user inputs
        move = model.move_piece(board, score, move_from, move_to)
        if move[0]:
            board = move[1]
            score = move[2]
            # Check if multiple jumps available
            if move[3]:
                view.refresh(board, model.get_score(board))
                view.print_message('Additional move is available')
                continue

            # Computer's move
            board = model.computer_move(board)[0]
            view.refresh(board, model.get_score(board))
        else:
            view.print_message(move[1])

    view.game_over(score, computer_score)
Esempio n. 2
0
def get_items_by_attr(shopping_list):
    view.print_options_of_get_items()
    number = view.get_input()
    if number == 1:
        shopping_list.get_items()
    elif number == 2:
        shopping_list.get_items(True)
Esempio n. 3
0
 def import_players_in_tournament(self):
     """
     Affiche la vue de séléction des joueurs parmis les joueurs en base de données.
     Récupère les joueurs sélectionnés et les affectes au tournoi courant.
     :return: None
     """
     try:
         self.db.check_if_player_table_is_empty()
         os.system('cls')
         view.show_players_choices(self.db.get_players_docs_id(),
                                   self.db.get_players())
         doc_ids = view.get_input(
             "Choisissez un joueur ou des joueur avec le marqueur ','",
             check_choices_players_is_valid,
             (self.db.get_players_docs_id(),
              self.focus_tournament.indices_players),
             view.format_input_choice)
         if doc_ids:
             self.focus_tournament.add_players_from_database(doc_ids)
             self.set_output(
                 view.format_output_players_in_database,
                 (doc_ids,
                  [self.db.get_player_by_id(doc_id) for doc_id in doc_ids]))
         else:
             self.reset_output()
     except (model.TooManyPlayersError, model.PlayerTableIsEmptyError) as e:
         self.set_output(view.format_error, e)
Esempio n. 4
0
def main_menu():
    while True:
        view.show_menu()
        selection = view.get_input()
        if selection == "3":
            return
        elif selection == "1":
            new_user = view.new_account()
            new_account_num = model.create_new_account()
            new_user_full = new_user[0] + " " + new_user[1]
            model.add_name(new_account_num, new_user_full)
            model.add_pin_code(new_account_num, new_user[2])

        elif selection == "2":
            account_num = view.get_account()
            account_details = model.get_account_details(account_num[0])
            if str(account_num[1]) == str(account_details["pin_code"]):
                view.display_user_details(account_details)
                user_menu(account_num[0])
            else:
                view.bad_input
                return

        else:
            view.bad_input()
Esempio n. 5
0
def mainmenu(student):
    while True:
        view.show_menu(student)
        selection = view.get_input()
        # print(selection)
        if selection == '3':
            model.save()
            return
        elif selection == '1':
            newgrade = view.get_input()
            model.add_grade(student, newgrade)
        elif selection == '2':
            gpa = model.get_gpa(student)
            view.show_gpa(gpa)
        else:
            view.bad_input()
Esempio n. 6
0
 def show_players(self):
     """
     Prépare l'affichage des joueurs du tournoi courant si il existe ou alors les joueurs de la base de données.
     :return: None
     """
     try:
         self.db.check_if_player_table_is_empty()
         param = view.get_input(
             'Choisissez un paramètre entre tri alphabétique (A) ou Classement (C)',
             check_param_cmd_show_players_is_valid,
             format_view=view.format_input_parameters)
         if self.focus_tournament:
             players = self.focus_tournament.get_players()
             output_function = view.format_output_players_in_tournament
         else:
             players = [
                 self.db.get_player_by_id(doc_id)
                 for doc_id in self.db.get_players_docs_id()
             ]
             output_function = view.format_output_players_in_database
         sort_players(param, players)
         doc_ids = [
             self.db.get_doc_id_by_player(player) for player in players
         ]
         self.set_output(output_function, (doc_ids, players))
     except (model.PlayersInTournamentEmptyError,
             model.PlayerTableIsEmptyError) as e:
         self.set_output(view.format_information, e)
Esempio n. 7
0
def homepage():
    while True:
        view.show_homepage()
        selection = view.get_input()

        if selection != '1' and selection != '2' and selection != '3':
            view.bad_selection()
        elif selection == '1':
            customer = get_user_info()
            if customer[2] != customer[3]:
                view.no_pin_match()
            else:
                new_customer = model.create_account(customer)
                logged_in_homepage(new_customer)
                return
        elif selection == '2':
            name = view.login_name()
            pin = view.login_pin()
            if model.login_user(name, pin):
                customer = model.login_user(name, pin)
                logged_in_homepage(customer)
                return
            else:
                view.invalid_login()
                pass
        elif selection == '3':
            view.goodbye()
            return
Esempio n. 8
0
def mainmenu(account):
    while True:
        view.show_menu(account)
        selection = view.get_input()
        if selection == '4':
            answer = view.quit_input()
            if answer == "y":
                model.save()
                break
            if answer == "n":
                view.show_menu(account)
        elif selection == '1':
            balance = model.check_balance(account)
            view.show_balance(balance)
        elif selection == '2':
            depbalance = float(view.get_amount_input())
            model.deposit(account, depbalance)
            balance = model.check_balance(account)
            view.show_balance(balance)
        elif selection == '3':
            wdbalance = float(view.get_amount_input())
            model.withdraw(account, wdbalance)
            balance = model.check_balance(account)
            view.show_balance(balance)
        else:
            view.bad_input()
Esempio n. 9
0
def logged_in_homepage(primary_key):
    while True:
        customer = model.get_customer(primary_key)
        view.logged_in_homepage(customer)

        selection = view.get_input()

        if selection != '1' and selection != '2' and selection != '3' and selection != '4':
            view.bad_selection()
        elif selection == '1':
            funds_requested = view.withdraw_funds()
            if funds_requested.isdigit() and int(
                    customer[0][3]) >= int(funds_requested):
                model.update_funds(customer, funds_requested, "W")
            else:
                view.insufficient_funds()
        elif selection == '2':
            funds_to_deposit = view.deposit_funds()
            if funds_to_deposit.isdigit():
                model.update_funds(customer, funds_to_deposit, "D")
                continue
            else:
                view.invalid_amount()
        elif selection == '3':
            view.goodbye()
            homepage()
            return
Esempio n. 10
0
def welcomemenu():
    while True:
        view.welcome_menu()
        selection = view.get_input()
        if selection == '1':
            create_account()
        if selection == '2':
            login()
        if selection == '3':
            model.save()
            return
Esempio n. 11
0
def get_inputs_for_tournament_parameters():
    """
    Récupère l'ensemble des inputs pour la création d'un tournoi.
    :return: tuple
    """
    name = view.get_input('Nom du tournois',
                          check_if_input_is_empty,
                          format_view=view.format_input_parameters)
    location = view.get_input('Lieu du tournois',
                              check_if_input_is_empty,
                              format_view=view.format_input_parameters)

    date = view.get_input('Date du tournoi (Ex : 2020-01-01)',
                          check_date_input,
                          format_view=view.format_input_parameters)

    time = view.get_input('Cadence du tournois (bullet, blitz, coup rapide)',
                          check_time_input,
                          format_view=view.format_input_parameters)

    number_round = view.get_input('Nombre de tours du tournois',
                                  check_number_round_input,
                                  format_view=view.format_input_parameters)

    description = view.get_input('Description du tournois',
                                 format_view=view.format_input_parameters)
    return name, location, date, time, description, number_round
Esempio n. 12
0
def shopping_menu(shopping_list):
    user_choice = ''
    while user_choice != 0:
        view.print_shopping_menu()
        user_choice = view.get_input()

        if user_choice == 1:
            get_items_by_attr(shopping_list)

        elif user_choice == 2:
            print(shopping_list.get_total_price())

        elif user_choice == 3:
            add_new_item(shopping_list)
Esempio n. 13
0
def get_inputs_for_player_parameters():
    """
    Récupère l'ensemble des inputs pour la création d'un joueur.
    :return: tuple
    """
    last_name = view.get_input('Nom du joueur',
                               check_if_input_is_empty,
                               format_view=view.format_input_parameters)
    first_name = view.get_input('Prénom du joueur',
                                check_if_input_is_empty,
                                format_view=view.format_input_parameters)

    birthdate = view.get_input('Date de naissance du joueur (Ex: 2000-01-01)',
                               check_date_input,
                               format_view=view.format_input_parameters)

    gender = view.get_input('Sexe (H/F)',
                            check_gender_input,
                            format_view=view.format_input_parameters)
    ranking = view.get_input('Classement',
                             check_ranking_input,
                             format_view=view.format_input_parameters)
    return last_name, first_name, birthdate, gender, ranking
Esempio n. 14
0
 def create_round(self):
     """
     Ajoute un round au tournoi courant.
     :return: None
     """
     try:
         name = view.get_input('Nom du round',
                               check_if_input_is_empty,
                               format_view=view.format_input_parameters)
         self.focus_tournament.create_round(name)
         self.set_output(view.format_output_round,
                         self.focus_tournament.get_last_round())
     except model.TournamentError as e:
         self.set_output(view.format_error, e)
Esempio n. 15
0
def mainmenu(student):
    while True:
        view.show_menu(student)
        selection = view.get_input()
        if selection == '3':
            model.save()
            return
        elif selection == '1':
            newgrade = view.get_grade()
            model.add_grade(student, newgrade)
        elif selection == '2':
            view.show_gpa(model.get_gpa(student))
        elif selection == '3':
            student = view.get_student()
        elif 
Esempio n. 16
0
def main_menu():
    user_choice = ''
    while user_choice != 0:
        view.print_main_menu()
        user_choice = view.get_input()

        if user_choice == 1:
            shopping_list = open_shopping_list_from_file()
            if shopping_list:
                shopping_menu(shopping_list)

        elif user_choice == 2:
            create_shopping_list()

        view.print_exit_message()
Esempio n. 17
0
def mainmenu(student):  #basically a while loop
    while True:  #This loop doesnt terminate on its own. The break keyword stops the loop
        view.show_menu(student)  #Print students name @ top of menu
        selection = view.get_input()
        print(selection)
        if selection == '4':
            model.save()  #save before exiting
            return  #exits the function. could also use /br
        elif selection == '1':
            new_grade = view.get_grade()
            model.add_grade(student, new_grade)
        elif selection == '2':
            pass
        elif selection == '3':
            pass
        else:
            view.bad_input()
Esempio n. 18
0
def mainmenu(clientname, accountcheck):
    while True:
        view.show_mainmenu(clientname, accountcheck)
        selection = view.get_input()
        print(selection)
        if selection == '1':
            view.show_balance(model.get_balance(clientname))
        elif selection == '3':
            model.add_fund(clientname, view.get_deposit())

        elif selection == '2':
            model.withdraw(clientname, view.get_withdraw())
            pass
        elif selection == '4':
            view.goodby()
            initialmenu()
        else:
            view.bad_input()
Esempio n. 19
0
 def start(self):
     """
     Affiche les vues, récupère les commandes, exécute les commandes et boucle
     tant que l'utilisateur n'a pas quitté.
     :return: None
     """
     while not self.stop:
         os.system('cls')
         view.show_output(self.last_cmd_key, self.last_cmd_name,
                          self.output_function, self.output_params)
         view.show_transition()
         view.show_menu(self.get_menu())
         cmd_key = view.get_input('Choisissez une commande',
                                  check_command_is_valid,
                                  self.get_keys_commands_available(),
                                  view.format_input_command)
         self.last_cmd_key = cmd_key
         self.last_cmd_name = self.get_menu()[cmd_key][0]
         self.apply_command(cmd_key)
Esempio n. 20
0
 def close_round(self):
     """
     Entre les résultats des matches du dernier round du tournoi courant et clos le round.
     :return: None
     """
     try:
         round = self.focus_tournament.get_last_round()
         while round.get_index_match_to_set_result() is not None:
             index_match = round.get_index_match_to_set_result()
             p1, p2 = round.get_players_in_match(index_match)
             name_p1 = p1.last_name + ' ' + p1.first_name
             score_1 = view.get_input(
                 f'Entrez le résultat de {name_p1}',
                 check_if_result_is_valid,
                 format_view=view.format_input_parameters)
             round.set_result(p1, p2, score_1, index_match)
         self.focus_tournament.close_round()
         self.show_matches()
     except (model.RoundError, model.TournamentError) as e:
         self.set_output(view.format_error, e)
Esempio n. 21
0
 def select_tournament(self):
     """
     Affiche la vue de séléction d'un tournoi parmis les tournois de la base de données.
     Récupère un tournoi et l'affecte à l'attribut qui definit le tournoi courant.
     :return: None
     """
     try:
         self.db.check_if_tournament_table_is_empty()
         os.system('cls')
         view.show_tournaments_choices(self.db.get_tournaments_docs_id(),
                                       self.db.get_tournaments())
         doc_id = view.get_input('Choisissez un tournoi',
                                 check_choice_tournament_is_valid,
                                 self.db.get_tournaments_docs_id(),
                                 view.format_input_choice)
         self.focus_tournament = self.db.get_tournament_by_id(doc_id)
         self.focus_tournament_doc_id = doc_id
         self.set_output(view.format_output_tournament,
                         self.focus_tournament)
     except model.TournamentTableIsEmptyError as e:
         self.set_output(view.format_error, e)
Esempio n. 22
0
def user_menu(user_account):
    while True:
        view.show_user_menu()
        selection = view.get_input()
        if selection == "4":
            return
        elif selection == "1":
            view.show_balance(model.get_balance(user_account))
        elif selection == "2":
            print("wit")
            withdraw_amount = int(view.subtract_funds())
            current_balance = int(model.get_balance(user_account))
            if withdraw_amount > current_balance:
                print("insufficient funds")
            else:
                model.withdraw_funds(user_account, withdraw_amount)

        elif selection == "3":
            add_amount = view.add_funds()
            model.add_funds(user_account, add_amount)
        else:
            view.bad_input()
Esempio n. 23
0
def initialmenu():
    while True:
        view.show_initalmenu()
        selection = view.get_input()
        print(selection)
        if selection == '1':
            new_Firstname = view.get_FirstName()
            new_LastName = view.get_LastName()
            new_pin = view.get_pin()
            newaccount = model.create_account(new_Firstname, new_LastName,
                                              new_pin)
            model.save(newaccount)

        elif selection == '2':
            clientcheck = view.clientcheck()
            accountcheck = int(view.accountcheck())
            pin = int(view.pincheck())
            model.login(clientcheck, accountcheck, pin)
            mainmenu(clientcheck, accountcheck)

        elif selection == '3':
            pass
        else:
            view.bad_input()
Esempio n. 24
0
def logged_in_homepage(customer):
    while True:
        view.logged_in_homepage(customer)
        selection = view.get_input()

        if selection != '1' and selection != '2' and selection != '3' and selection != '4':
            view.bad_selection()
        elif selection == '1':
            funds_requested = view.withdraw_funds()
            if funds_requested.isdigit() and int(
                    customer["Balance"]) >= int(funds_requested):
                model.withdraw_funds(customer, funds_requested)
            else:
                view.insufficient_funds()
        elif selection == '2':
            funds_to_deposit = view.deposit_funds()
            if funds_to_deposit.isdigit():
                model.deposit_funds(customer, funds_to_deposit)
            else:
                view.invalid_amount()
        elif selection == '3':
            view.goodbye()
            homepage()
            return
Esempio n. 25
0
    if filename == '':
        view.error('Nome de arquivo vazio')

    if not os.path.isfile(filename):
        col1_name = view.get_file_creation(
            'Insira o nome da primeira coluna: ')
        col2_name = view.get_file_creation('Insira o nome da segunda coluna: ')

        sep = view.get_file_creation_nc(
            ('Insira o(s) caractere(s) separador(es) desejado (ex: virgula, '
             'ponto e virgula, dois pontos, etc): '))

        print()
        col_1 = [
            float(x) for x in view.get_input((
                'Insira os valores numericos da coluna "' + col1_name + '", '
                'separados pelo(s) caractere(s) escolhido(s): ')).split(sep)
        ]
        col_2 = [
            float(x) for x in view.get_input((
                'Insira os valores numericos da coluna "' + col2_name + '", '
                'separados pelo(s) caractere(s) escolhido(s): ')).split(sep)
        ]

        if (len(col_1) != len(col_2)):
            view.error('As duas colunas devem ter o mesmo comprimento')
        else:
            with open(filename, 'w+') as f:
                f.write(col1_name + sep + col2_name + '\n')
                for i in range(len(col_1)):
                    f.write(str(col_1[i]) + sep + str(col_2[i]) + '\n')
Esempio n. 26
0
def atm():

    #Main menu loop
    while True:
        view.show_main_menu()
        selection = view.get_input("Your choice: ")

        #Account creation
        if selection == "1":
            view.display_text("Account creation")
            first_name = view.get_input("    First name: ")
            last_name = view.get_input("    Last name: ")
            pin = view.get_input("    PIN: ")
            confirm_pin = view.get_input("    Confirm PIN: ")
            if pin != confirm_pin:
                view.display_text("PINs do not match, please try again")
            else:
                #account_number = model.new_account(first_name, last_name, pin)
                while True:
                    account_number = randint(100000, 999999)
                    if Account.account_in_data(account_number) == False:
                        new_account = Account(account_number, pin, 0,
                                              first_name, last_name)
                        new_account.save()
                        view.display_text(
                            f"account created, your account number is {new_account.account_num}."
                        )
                        break

        #Login
        elif selection == "2":
            account_number = view.get_input("    Account number: ")
            pin = view.get_input("    PIN: ")
            #valid, name = model.login(account_number, pin)
            user_account = Account(account_number, pin)
            if user_account.validate() == False:
                raise AuthenticationError
                view.display_text(
                    "No account exists with such a PIN, please try again")
            else:
                user_account.load()
                #Loop for user display after login
                while True:
                    view.show_login_menu(
                        f"Hello, {user_account.first_name.title()} {user_account.last_name.title()} ({user_account.account_num})"
                    )
                    new_selection = view.get_input("Your choice: ")

                    #Check balance
                    if new_selection == "1":
                        balance = user_account.balance
                        balance = '${:,.2f}'.format(balance)
                        view.display_text(f"    Your balance is {balance}")

                    #Withdrawal
                    elif new_selection == "2":
                        amount_to_withdraw = view.get_input(
                            "How much to withdraw: ")
                        #insufficient = model.withdraw(account_number, amount_to_withdraw)
                        if user_account.withdraw(amount_to_withdraw) == False:
                            view.display_text("!! INSUFFICIENT FUNDS !!")

                    #Deposit
                    elif new_selection == "3":
                        amount_to_deposit = view.get_input(
                            "How much to deposit: ")
                        #model.deposit(account_number, amount_to_deposit)
                        user_account.deposit(amount_to_deposit)

                    #Sign out
                    elif new_selection == "4":
                        user_account.save()
                        break
        #Quit
        elif selection == "3":
            break
Esempio n. 27
0
def run():
    model.load()
    view.main_menu()
    selection = view.get_input()
    mainmenu(selection)
Esempio n. 28
0
import model, view

model.quantity = view.get_input()
view.output(model.quantity)
Esempio n. 29
0
import model, view

# python controller.py [parâmetro numérico]
model.r = view.get_input()
view.present_output(model.r)
Esempio n. 30
0
import model, view

model.r = view.get_input()
view.present_output(model.r)