def addProduct(active_customer, superuser, products, active_order, products_added): os.system("clear") print( "\n" "******************************* \n" "** Add products to order ** \n" "******************************* \n" ) for product in products: print("{:<3}{:<20}{:<8}{}".format(product[0], product[1], product[2], product[3])) print("\nChoose an item to add to your order or type 'Done' to finish") item = str(input(">")) if item != 'Done': item = int(item) new_product = products[item-1] added_product = Product(new_product[1], new_product[2], new_product[3]) superuser.add_product_to_order(added_product,active_order,active_customer.get_active_orderId()) products_added += 1 addProduct(active_customer, superuser, products, active_order, products_added) else: if products_added > 0: complete_an_order.completeOrder(active_customer, active_order, active_customer.get_active_customerId()) else: input("Please add some products to your order first. Press enter key to return to main menu.") main.mainMenu(active_customer)
def completeOrder(active_customer, order, customer_id): superuser = Superuser() customer_id = active_customer.get_active_customerId() order_id = active_customer.get_active_orderId() ''' Complete an order interface - If no products have been added to order, return user to main menu - Provides order total and 'ready to purchase?' prompt (Y/N) if user enters N, mainMenu() to return to main interface - Allows superuser to add payment option - Calls mainMenu() to return to main interface @nchemsak ''' os.system("clear") payments = superuser.get_all_customer_payments(customer_id) print("\n" "************************************ \n" "** Complete Your Order ** \n" "************************************ \n") '''Order TOTAL and ready to purchase prompt''' order_total = order.get_total(order_id) ready = input( "\nYour order total is ${}. Ready to purchase (Y/N) > ".format( order_total)) '''Choose Payment Option''' if ready == 'Y' or ready == 'y': print("\nChoose a payment option:\n") for index, payment in enumerate(payments): print("\t{}. {:<3} - acct# {:<20}".format((index + 1), payment[6], payment[3])) try: choice = int(input('>')) except: print("Please Enter a valid choice as a number only") completeOrder(active_customer, order, customer_id) payment_type_id = payments[choice - 1][0] order.set_payment_type_id(payment_type_id, order_id) order.set_status("False", order_id) active_customer.set_active_orderId(None) input("Your order is complete! Press ENTER to return to main menu.") else: main.mainMenu(active_customer) main.mainMenu(active_customer)
def show_product_popularity(active_customer): ''' Show product popularity interface calls mainMenu() to return to main interface @asimonia ''' os.system("clear") # Create a product product = Product("A", 1, 1) product.print_product_popularity() print('\n') input("-> Press any key to return to main menu") main.mainMenu(active_customer)
def createPaymentOption(active_customer): ''' Payment option creation interface provides inputs to enter payment option information passes inputs to superuser method to register a payment option in db calls mainMenu() to return to main interface @mccordgh ''' os.system("clear") id_customer = active_customer.get_active_customerId() print("\n" "******************************* \n" "** Create a Payment Option ** \n" "******************************* \n") print("\nEnter payment option first name") first_name = str(input(">")) print("\nEnter payment option last name") last_name = str(input(">")) print("\nEnter account number") acct_number = str(input(">")) print("\nEnter expiration date") exp_date = str(input(">")) print("\nEnter CCV #") ccv = str(input(">")) print("\nEnter category (VISA, AMEX, MASTERCARD, etc)") category = str(input(">")) new_payment_option = PaymentOption(first_name, last_name, acct_number, exp_date, ccv, category, id_customer) Superuser.register_payment_option(object, new_payment_option) main.mainMenu(active_customer)
def test_main_menu(self): with patch("builtins.input", side_effect=2): self.assertEqual(main.mainMenu(), main.ItemInfo)
def chooseCustomer(active_customer): ''' Choose Customer interface provides list of users from db allows superuser to set active customer @rtwhitfield84 @asimonia ''' os.system("clear") # Fetch the customer id, first name, last name, password # assign it to customers as a list of tuples selected = False customers = Superuser.get_customers() password = '' choice = 0 print("\n""*************************** \n" "** Login to your account ** \n" "*************************** \n") # Select the first and last name for the customer # Test to see if it in customers while not selected: first_name = input("First name: ") last_name = input("Last name: ") for customer in customers: if customer[1] == first_name and customer[2] == last_name: # Once customer is selected, get password choice = customer[0] password = customer[3] selected = True print("Howdy, %s!\n" % (first_name)) if not selected: print("Customer does not exist!\n") # Mask characters for password input # Compare against re-entry while True: password_a = getpass() password_b = getpass(prompt="Re-enter password: "******"\nWelcome back {} {}!".format(first_name, last_name)) print('\n') input("-> Press any key to return to main menu") active_customer.set_active_customer() active_customer.set_active_customerId(choice) main.mainMenu(active_customer) else: print("Ah, ah, ah, you didn't say the magic word!") print('\n') input("-> Press any key to return to main menu") continue else: print("Passwords must match!\n")
def beginCombat(difficulty, curWave, numKilled): pygame.init() player = player_class.Player(numKilled) if difficulty == "EASY": reinforceSpeed = 15000 elif difficulty == "MEDIUM": reinforceSpeed = 11000 elif difficulty == "HARD": reinforceSpeed = 8000 # populate reinforcements array based on wave count # filling in order doesn't matter since they're accessed randomly reinforcements = [] i = 0 while i < (curWave + 1): reinforcements.append("Samurai") reinforcements.append("Oni") reinforcements.append("Ninja") i += 1 lastReinforceTime = pygame.time.get_ticks() # enemyFormation is a list of strings representing the enemy formation beginning the fight # "" represents an empty cell. Ie ("","","","Samurai") indicates one samurai at the bottom right cell of the screen enemyFormation = random.choice(cfg.startingFormations) enemies = createEnemies(enemyFormation) continueFight = True returnVal = True waveComplete = False # selectedCell represents where the player is currently targeting # 0 represents top left, 1 is top right, 2 is bottom left, 3 is bottom right selectedCell = 0 while continueFight: curTime = pygame.time.get_ticks() #seconds = (pygame.time.get_ticks() - start_ticks) / 1000 for event in pygame.event.get(): if event.type == pygame.QUIT: continueFight = False cfg.RUN_GAME = False pygame.quit() exit() # cell targeting selection by the player # if the player moves towards the edge, wrap if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: if selectedCell == 0 or selectedCell == 2: selectedCell += 1 else: selectedCell -= 1 elif event.key == pygame.K_LEFT: if selectedCell == 1 or selectedCell == 3: selectedCell -= 1 else: selectedCell += 1 elif event.key == pygame.K_DOWN: if selectedCell == 0 or selectedCell == 1: selectedCell += 2 else: selectedCell -= 2 elif event.key == pygame.K_UP: if selectedCell == 2 or selectedCell == 3: selectedCell -= 2 else: selectedCell += 2 if event.key == pygame.K_RETURN: if waveComplete: continueFight = False if event.key == pygame.K_ESCAPE: continueFight = False main.mainMenu() elif event.key == pygame.K_SPACE: if player.stamina >= 10: player.takeAction("defend") elif event.key == pygame.K_a: if player.stamina >= 10: player.takeAction("punch") elif event.key == pygame.K_s: if player.stamina >= 10: player.takeAction("chop") elif event.key == pygame.K_d: if player.stamina >= 10: player.takeAction("headbutt") #elif event.key == pygame.K_q: # player.takeAction("meditate") # allows the player to go in and out of defense for parries # player actions if (curTime - player.lastAttacked) > player.speed: if player.damage > 0: player.curAnimating = True player.startAnim = pygame.time.get_ticks() if player.action == "punch": player.sprite = assets.player_punch elif player.action == "chop": player.sprite = assets.player_chop elif player.action == "headbutt": player.sprite = assets.player_headbutt if enemies[selectedCell] is not None: enemies[ selectedCell].lastAttacked = pygame.time.get_ticks( ) if enemies[selectedCell] is not None: enemies[selectedCell].health -= player.damage if enemies[selectedCell].health <= 0: player.killCount += 1 enemies[selectedCell] = None # if the player just killed an enemy and there are no more reinforcements # the player has beaten the wave if len(reinforcements) == 0: enemiesLeft = False for e in enemies: if e is not None: enemiesLeft = True if enemiesLeft == False: waveComplete = True else: print("Whiff!") player.lastAttacked = pygame.time.get_ticks() player.reduceStam(player.stamCost) player.takeAction("idle") # recharge player stamina if (curTime - player.stamLastCharged) > player.stamChargeRate: player.stamLastCharged = curTime if player.action == "meditating": print("Meditating") else: player.increaseStam(7) # each enemy starts with lastAttacked = -1.0 # start their attack cycle once we are in the game loop # afterwards, check if curTime - lastAttacked >= speed; if it is, update lastAttacked with curTime and attack for i, e in enumerate(enemies): if e is not None: if e.lastAttacked == -1.0: e.lastAttacked = curTime elif curTime - e.lastAttacked >= e.speed: e.windUpAnim = False e.lastAttacked = curTime e.attackAnimTime = curTime # if the player is blocking and out of stamina, they take full damage # otherwise they will take stamina damage if player.action == "defend": if player.stamina > 10: player.reduceStam(e.damage) # player hit their parry, give them a second long riposte window if (curTime - player.parryStart) <= player.parryWindow: player.riposteStart = pygame.time.get_ticks() player.bgAlpha = 255 player.bgColor = (255, 0, 0) player.bgAnimating = True player.bgAnimSpeed = 5 else: player.takeDamage(e.damage) else: player.takeDamage(e.damage) elif curTime - e.lastAttacked + 500 >= e.speed: e.windUpAnim = True # if there is an empty cell, check if it is time for reinforcements # if there are no enemies in the field, send in two (if available) #elif len(reinforcements) > 0: if (curTime - lastReinforceTime) > reinforceSpeed: lastReinforceTime = pygame.time.get_ticks() for i, e in enumerate(enemies): if e is None: if (len(reinforcements) > 0): newEnemy = reinforcements[random.randrange( len(reinforcements))] enemies[i] = createEnemy(i, newEnemy) reinforcements.remove(newEnemy) break enemyCount = 0 for e in enemies: if e is not None: enemyCount += 1 if enemyCount == 1: for i, e in enumerate(enemies): if e is None and len(reinforcements) > 0: newEnemy = reinforcements[random.randrange( len(reinforcements))] enemies[i] = createEnemy(i, newEnemy) reinforcements.remove(newEnemy) #t = reinforceSpeed - curTime - lastReinforceTime pygame.time.Clock().tick(cfg.FRAME_RATE) pygame.display.update() drawScreen(player, selectedCell, enemies, len(reinforcements), curWave, waveComplete) if player.action != "die": beginCombat(difficulty, curWave + 1, player.killCount)
def createCustomer(active_customer): ''' Customer creation interface provides inputs to enter customer information passes inputs to superuser method to register customer in db calls mainMenu() to return to main interface @rtwhitfield84 @asimonia ''' os.system("clear") print("\n" "******************************* \n" "** Create a Customer Account ** \n" "******************************* \n") password = '' # Mask characters for password input # Compare against re-entry while True: password_a = getpass() password_b = getpass(prompt="Re-enter password: "******"Passwords must match!\n") print("\nEnter customer first name") first_name = str(input(">")) print("\nEnter customer last name") last_name = str(input(">")) print("\nEnter address 1") address_1 = str(input(">")) print("\nEnter address 2 (optional)") address_2 = str(input(">")) print("\nEnter city") city = str(input(">")) print("\nEnter state") state = str(input(">")) print("\nEnter zip code") zip_code = str(input(">")) print("\nEnter phone number") phone_number = str(input(">")) print("\nEnter email") email = str(input(">")) new_customer = Customer(first_name, last_name, password, address_1, address_2, city, state, zip_code, phone_number, email) Superuser.register_customer(object, new_customer) main.mainMenu(active_customer)