def create_int_menu(title, display_options, back_menu): # Sends default separator messaged text_format.send_separator_message(title) # Loops through all options and prints out. for i in range(len(display_options)): print(str(i + 1) + ") " + display_options[i]) # If back menu is enabled, it adds that option. if back_menu: print(str(len(display_options) + 1) + ") Back to menu") validated = False while not validated: # Validates response response = input("Enter your response: ").lower() # Attempts to change response into integer success, output = validation.validate_to_int(response) if success: if back_menu: # Back menu enabled, checks if number is the added value of the list (+1) if 1 <= output <= len(display_options) + 1: if output == len(display_options) + 1: return None else: return output else: # Checks if number is in default range without menu added. if 1 <= output <= len(display_options): return output validation.validation_err()
def send(): # Prints out instructions. text_format.send_separator_message("INSTRUCTIONS") print("1 - Choose your option (left, centre, right)") print("2 - If the keeper chooses the same option, they win a point.") print("3 - If you choose a different option compared to the keeper, you get a point.") print("4 - If you get more scores than the keeper, you win, if not, you loose.") return
def send(config: configHandler): # Retrieves the current configuration list menu_options = config.retrieve_config_list() text_format.send_separator_message("CURRENT CONFIG") # Prints out each configuration setting. for i in range(len(menu_options)): print(menu_options[i] + " > " + str(config.retrieve_config(menu_options[i]))) return
def create_string_menu(title, display_options, back_menu): # Sends default separator message text_format.send_separator_message(title) normal_display = False # Detect integer range type if not isinstance(display_options[1], str): # Not a bool, TRUE = 1, False = 0 if display_options[1] >= 2: # Asks additional input for a number in a certain range print("- Reply with an integer between " + str(display_options[0]) + " & " + str(display_options[1])) else: normal_display = True else: normal_display = True # Prints out all options if it is a selection menu without numbers if normal_display: display_options = lower_all_arr(display_options) for i in range(len(display_options)): print("- " + str(display_options[i])) # Prints out menu option if enabled. if back_menu: print("- menu") validated = False while not validated: # Validates response response = input("Enter your response: ").lower() if not response == "menu": # Checks to see if response is in valid options/responses if response in display_options: # Retrieves the index and returns the option they chose. index = display_options.index(response) return display_options[index] else: # Attempts to compare value of display_options if integer. try: if display_options[1] >= 2: # Validates to integer from string. success, output = validation.validate_to_int(response) if success: # Compares <=> integer for validity. if display_options[0] <= output <= display_options[ 1]: return output except: validated = False else: # Returns to go back to menu return None # Outputs error validation.validation_err()
def play(config): # Retrieves configuration values rounds = config.retrieve_config("Rounds") save_scores = config.retrieve_config("SaveScores") # Prints out welcome message print("Welcome to the game! Please make sure you've read the instructions so you know what to do.") # Starts points client points_client = Points(config) # Loops through each round. for i in range(int(rounds)): # Display messages response = menu.create_string_menu("GAME - ROUND: " + (str(i + 1)), OPTIONS, False) keeper_option = generate_keeper_option() # Prints out winner response for the certain round and adds score to winner. if response == keeper_option: print("The keeper caught the ball - you failed.") points_client.add_score("keeper") else: print("Well done, you scored!") points_client.add_score("player") # Calculates game impossibility (only sends if enabled notifications) points_client.calculate_impossibility() # Retrieves winner and difference score. winner, difference_score = points_client.get_winner() text_format.send_separator_message("OVERALL RESULTS") # Displays difference and who lost/won. if winner == "keeper": print("Oh no! You've lost by " + str(difference_score) + " point(s)!") elif winner == "player": print("Well done! You've won by " + str(difference_score) + " point(s)!") else: print("Congratulations, it was a draw!") print("FINAL RESULTS: (Player -> Keeper)\n" + (str(points_client.get_score("player")) + " <-> " + str(points_client.get_score("keeper"))).center(18)) # Saves the scores if enabled. if save_scores: points_data.save_score(points_client.get_score('player'), points_client.get_score('keeper')) return