コード例 #1
0
def login_menu():
    """ Login Menu - Create Account / Log In / Quit """
    while True:
        view.print_login_menu()
        choice = view.login_menu_prompt().strip()
        if choice not in ("1", "2", "3"):
            """ bad input """
            view.bad_login_input()
            return login_menu()
        elif choice == "3":
            """ 3. Quit """
            view.goodbye()
            return None  # return None for quit

        elif choice == "1":
            """ 1. Create Account """
            create_account()

        elif choice == "2":
            """ 2. Log In """
            account = view.login_account_num()
            pin = view.login_pin()
            account_data = model.login(account, pin)
            if account_data != None:
                return main_menu(account_data)
            else:
                view.bad_account_login()
コード例 #2
0
ファイル: scrabble.py プロジェクト: bt3gl/Scr4bbl3
def main():

    greetings()

    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        create_dict()

    try:
        wordPoints = load_dict()
    except:
        return "Could not load the dictionary."

    try:
        lettersGame = create_list_letters()
    except:
        return "Could not create list of letters."

    """ set game variables """
    piecesLeft = len(lettersGame)
    numberOfPiecesHand = 5
    lettersDict = LETTERS

    lettersPC = ""
    pointsPC = 0
    wordsPC = []

    lettersHuman = ""
    pointsHuman = 0
    wordsHuman = []

    """ Game Loop """
    while piecesLeft >= 2 * numberOfPiecesHand:

        # computer's turn
        print("\n--> Computer's Turn:")
        points, word, lettersPC, lettersDict = computerTurn(
            wordPoints, lettersGame, numberOfPiecesHand, lettersDict, lettersPC
        )

        pointsPC += points
        wordsPC.append(word)
        printStatus(word, str(points), str(pointsPC))

        # human's turn
        print("\n--> Your Turn:")
        points, word, lettersHuman, lettersDict = humanTurn(
            wordPoints, lettersGame, numberOfPiecesHand, lettersDict, lettersHuman
        )

        pointsHuman += points
        wordsHuman.append(word)
        printStatus(word, str(points), str(pointsHuman))

        break

    """ Game Finalization """
    goodbye(str(pointsHuman), str(pointsPC), wordsHuman, wordsPC)
コード例 #3
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
コード例 #4
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
コード例 #5
0
def main():

    greetings()
    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        create_dict()

    try:
        wordPoints = load_dict()
    except:
        return "Could not load the dictionary."

    try:
        lettersGame = create_list_letters()
    except:
        return "Could not create list of letters."
    """ set game variables """
    piecesLeft = len(lettersGame)
    numberOfPiecesHand = 5
    lettersDict = LETTERS

    lettersPC = ""
    pointsPC = 0
    wordsPC = []

    lettersHuman = ""
    pointsHuman = 0
    wordsHuman = []
    """ Game Loop """
    while piecesLeft >= 2 * numberOfPiecesHand:

        # computer's turn
        print("\n--> Computer's Turn:")
        points, word, lettersPC, lettersDict =  computerTurn(wordPoints, lettersGame, \
                            numberOfPiecesHand, lettersDict, lettersPC)

        pointsPC += points
        wordsPC.append(word)
        printStatus(word, str(points), str(pointsPC))

        # human's turn
        print("\n--> Your Turn:")
        points, word, lettersHuman, lettersDict =  humanTurn(wordPoints, lettersGame, \
                            numberOfPiecesHand, lettersDict, lettersHuman)

        pointsHuman += points
        wordsHuman.append(word)
        printStatus(word, str(points), str(pointsHuman))

        break
    """ Game Finalization """
    goodbye(str(pointsHuman), str(pointsPC), wordsHuman, wordsPC)
コード例 #6
0
ファイル: controller.py プロジェクト: Sshetty2/byte
def login_terminal():
    view.input_terminal()
    options_menu = input()
    while options_menu not in ["1", "2", "3", 1, 2, 3]:
        view.invalid_input()
        return login_terminal()
    if options_menu == "1" or options_menu == 1:
        create_account()
        view.create_confirm()
        return login_terminal()
    if options_menu == "2" or options_menu == 2:
        login()
    if options_menu == "3" or options_menu == 3:
        view.goodbye()
        quit()
コード例 #7
0
def welcome_menu():
    while True:
        selection = view.welcome_screen()
        if selection not in ["1", "2", "3"]:
            view.improper_selection()
            continue

        if selection == '1':
            username = view.get_username()
            balance = view.add_balance()
            password = view.get_password()
            confirm_password = view.confirm_password()

            if password != confirm_password:
                view.improper_password()
                continue
            if not balance.isdigit() or int(balance) < 0:
                view.improper_balance()

            account = Accounts(username=username, balance=balance)
            account.set_password(password)
            account.generate_api_key()
            account.save()
            logged_in_homepage(account)
            return

        elif selection == '2':
            username = view.get_username()
            password = view.get_password()
            logged_in_account = Accounts.login(username=username,
                                               password=password)
            if logged_in_account:
                logged_in_homepage(logged_in_account)
                return
            else:
                print("Invalid Credentials")
                continue

        elif selection == '3':
            view.goodbye()
            return
コード例 #8
0
def run():
    if len(sys.argv) > 1 and sys.argv[1] == "--cheat":
        cheat = True
    else:
        cheat = False
    # generate computer's board
    size = view.ask_boardsize()
    board = ComputerBoard(size, size)
    while board.count_symbol('S') < NUMSHIPS:
        board.random_ship()

    while not board.no_ships():
        if cheat:
            print(board)
        else:
            view.show_board(board)
        x, y = view.get_attack_coords(board)
        if board.attack(x, y):
            view.hit()
        else:
            view.miss()

    view.goodbye()
コード例 #9
0
def login_menu():
    while True:
        view.print_login_menu()
        choice = view.login_menu_prompt().strip()
        if choice not in ("1", "2", "3"):
            view.bad_login_input()
            return login_menu()
        elif choice == "3":
            view.goodbye()
            return None  # return None for quit

        elif choice == "1":
            create_account()
            """ TODO: prompt for firstname, lastname, and pin, and confirm pin
            create the account and then tell the user what their new account number is """

        elif choice == "2":
            """ TODO: prompt functions to ask for account and PIN, use try, except
            to check for bad login """
            account = view.login_account_num()
            pin = view.login_pin()
            account_data = model.login(account, pin)
            return main_menu(account_data)
コード例 #10
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
コード例 #11
0
ファイル: controller.py プロジェクト: Sshetty2/byte
def login_menu(user_login):
    if user_login.type == "ADMIN":
        view.login_menu_admin(user_login)
        login_input = input()
        while login_input not in [
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"
        ]:
            view.invalid_input()
            login_input = input()
        if login_input == "1":
            view.check_balance(user_login)
            return login_menu(user_login)
        if login_input == "2":
            all_positions = user_login.getpositions()
            view.check_all_positions(user_login)
            model.print_gettrades(all_positions)
            return login_menu(user_login)
        if login_input == "3":
            view.ticker_query()
            ticker = input().upper()
            price = model.apiget(ticker)
            while price == None:
                print("Not a valid ticker!")
                view.ticker_query()
                ticker = input().upper()
                price = model.apiget(ticker)
            view.ticker_check_price(ticker, price)
            return login_menu(user_login)
        if login_input == "4":
            buy(user_login)
        if login_input == "5":
            sell(user_login)
        if login_input == "6":
            all_trades = user_login.gettrades()
            view.see_all_trades(user_login)
            model.print_gettrades(all_trades)
            return login_menu(user_login)
        if login_input == "7":
            view.goodbye()
            return login_terminal()
        if login_input == "8":
            view.goodbye()
            quit()
        if login_input == "9":
            view.set_funds_amount()
            amt_of_funds = input()
            user_login.set_balance(amt_of_funds)
            return login_menu(user_login)
        if login_input == "10":
            view.see_all_accounts_one()
            all_accounts = user_login.get_all_accounts()
            model.print_all_accounts(all_accounts)
            return login_menu(user_login)
        if login_input == "11":
            print(model.return_top_headlines_content("author"))
            return login_menu(user_login)

    else:
        view.login_menu_user(user_login)
        login_input = input()
        while login_input not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
            view.invalid_input()
            login_input = input()
        if login_input == "1":
            view.check_balance(user_login)
            return login_menu(user_login)
        if login_input == "2":
            all_positions = user_login.getpositions()
            print(all_positions)
            view.check_all_positions(user_login)
            model.print_gettrades(all_positions)
            return login_menu(user_login)
        if login_input == "3":
            view.ticker_query()
            ticker = input().upper()
            price = model.apiget(ticker)
            while price == None:
                print("Not a valid ticker!")
                view.ticker_query()
                ticker = input().upper()
                price = model.apiget(ticker)
            view.ticker_check_price(ticker, price)
            return login_menu(user_login)
        if login_input == "4":
            buy(user_login)
        if login_input == "5":
            sell(user_login)
        if login_input == "6":
            all_trades = user_login.gettrades()
            view.see_all_trades(user_login)
            model.print_gettrades(all_trades)
            return login_menu(user_login)
        if login_input == "7":
            view.goodbye()
            return login_terminal()
        if login_input == "8":
            view.goodbye()
            quit()
        if login_input == "9":
            view.deposit_amount()
        try:
            deposit_amount = int(input())
        except ValueError:
            view.invalid_input()
            return login_menu(user_login)
        while deposit_amount < 0:
            view.invalid_input
            deposit_amount = input()
        user_login.deposit_funds(deposit_amount)
        view.depsosit_successful()
        return login_menu(user_login)
コード例 #12
0
ファイル: controller.py プロジェクト: Sshetty2/byte
def run():
    """ Main flow of the program. """
    view.welcome_message()
    login_terminal()
    view.goodbye()
    quit()