def select_cipher(): helpers.clear_screen() print("Please pick one of the following ciphers:") print() for cipher in ciphers: print(f"- {cipher}") print() while True: try: cipher = input("Which cipher would you like to use? ") if cipher.upper() == "ATBASH": cipher = Atbash() elif cipher.upper() == "CAESAR": cipher = Caesar() elif cipher.upper() == "POLYBIUS": cipher = Polybius() elif cipher.upper() == "KEYWORD": keyword = input( "Which word would you like to use as a keyword? ") cipher = Keyword(keyword) else: raise ValueError("That cipher doesn't exist " + "or has not yet been implemented.") except ValueError as error: print(error) print() else: break return cipher
def render_products(window: tk.Tk): clear_screen(window) with open(os.path.join('db', 'products.txt')) as products_fh: current_row = current_col = 0 for product_idx, line in enumerate(products_fh): product = json.loads(line) if product_idx % ROW_SIZE == 0: current_row += 3 current_col = 0 tk.Label(window, text=product['name']).grid( row=current_row, column=current_col) image = Image.open(os.path.join( 'db', 'img', product['img_path'])) image = image.resize((100, 100)) tk_image = ImageTk.PhotoImage(image) lbl = tk.Label(window, image=tk_image) lbl.image = tk_image lbl.grid(row=current_row+1, column=current_col) tk.Label(window, text=product['count']).grid( row=current_row+2, column=current_col) tk.Button(window, text=f'Buy {product["name"]}').grid( row=current_row+3, column=current_col) current_col += 1
def handle_client(conn, addr): print(f'New connection from: {addr}') map_width = 10 map_height = 10 player_vision = 5 g = create_game_object(map_width, map_height, player_vision) send_initial_data_to_user(conn, g) client_connected = True while client_connected: if not g.restart_game: (message, bb) = receive_message_from_client(conn, g) if bb: break send_message_to_client(conn, message) helpers.clear_screen() g.display_map() print('\n') else: map_width += 5 map_height += 5 g = create_game_object(map_width, map_height, player_vision) send_initial_data_to_user(conn, g) print(f'closing connection with {addr}') conn.close()
def on_click(): error = register(**{user_attribute: widget.get() for (user_attribute, widget) in inputs}) if not error: clear_screen(screen) on_success(screen) else: tk.Label(screen, text="Invalid username or password", foreground="Red").grid(row=len(inputs)+1, column = 2)
def high_scores(): helpers.clear_screen() print("\033[34m" + "-" * 80 + "\n" + "HIGH SCORES".center(80) + "\n" + "-" * 80 + "\033[0m" + "\n") scores = get_table_from_file("high_scores.csv") print_table(scores, ["User", "Points", "Time Spent"]) input("\n/Press enter to continue./")
def start_menu(race): is_running = True FIRST_ELEMENT = 0 SECOND_ELEMENT = 1 num_of_option = 0 while is_running: helpers.clear_screen() # print menu structure //ui.print_menu? # wait for user input print_menu(start_menu_structure(), num_of_option) key = helpers.key_pressed() # call menu handler with user input menu_handler_options = start_menu_handler(key, num_of_option) is_running = menu_handler_options[FIRST_ELEMENT] num_of_option = menu_handler_options[SECOND_ELEMENT] user_name = menu_handler_options[2] if len(user_name) > 1: if num_of_option == 0: hero_class = 'Wizzard' if num_of_option == 1: hero_class = 'Knight' if num_of_option == 2: hero_class = 'Rouge' main.main(user_name, race, hero_class) is_running = False
def start_fight(player): helpers.clear_screen() display_boss() print( 'BOSS: lets play High/Low! You have 10 chances to guess my number from 0 to 20. ' ) play_cold_warm(player)
def render_register(screen: tk.Tk, on_success): clear_screen(screen) inputs = [ ('username', tk.Entry(screen)), ('password', tk.Entry(screen)), ('retype password', tk.Entry(screen)), ('first name', tk.Entry(screen)), ('last name',tk.Entry(screen)) ] for index, (label, input_widgets) in enumerate(inputs): input_widgets.grid(row=index,column=2) labels = [ tk.Label(screen, text='Username'), tk.Label(screen, text='Password'), tk.Label(screen, text='Retype Password'), tk.Label(screen, text='First Name'), tk.Label(screen, text='Last Name') ] for index, input_widgets in enumerate(labels): input_widgets.grid(row=index,column=1) def on_click(): error = register(**{user_attribute: widget.get() for (user_attribute, widget) in inputs}) if not error: clear_screen(screen) on_success(screen) else: tk.Label(screen, text="Invalid username or password", foreground="Red").grid(row=len(inputs)+1, column = 2) tk.Button(screen, text='Submit', command=on_click).grid(row=len(inputs),column=2)
def render_login(window: tk.Tk, on_success): clear_screen(window) inputs = [ ('username', tk.Entry(window)), ('password', tk.Entry(window, show='*')), ] for idx, (user_attr, input) in enumerate(inputs): input.grid(row=idx, column=1) labels: List[tk.Label] = [ tk.Label(window, text='User Name'), tk.Label(window, text='Password'), ] for idx, label in enumerate(labels): label.grid(row=idx, column=0) def on_click(): if login(**{user_attr: widget.get() for user_attr, widget in inputs}): on_success(window) else: tk.Label(window, text='Invalid username or password', background='red', foreground='white').grid(row=0, column=4) tk.Button(window, text='Login', command=on_click).grid(row=3, column=0)
def show_logo_animation(logo, forward="True"): # time delay in seconds animation_delay = 0.2 full_logo_delay = 1.5 time.sleep(full_logo_delay) if forward: for i in range(3, -1, -1): clear_screen() print("\n\n") print(colored(logo[i], 'yellow', attrs=[])) time.sleep(animation_delay) time.sleep(full_logo_delay) else: for i in range(4): clear_screen() print("\n\n") print(colored(logo[i], 'yellow', attrs=[])) time.sleep(animation_delay) #clear_screen() time.sleep(animation_delay)
def start_game(): # clear the screen for a better UI clear_screen() # get the name of the player from input get_player_name() # let the player select the skill tree player_select_skill_tree()
def change_body_part(player, new_body_part_type, id=0): clear_screen() print() if new_body_part_type == "head": part_type = BODY_PARTS["heads"] print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►") print(f"\tBODY: {PLAYER_ICON['body']} ") print(f"\tLEGS: {PLAYER_ICON['legs']} ") elif new_body_part_type == "body": part_type = BODY_PARTS["bodies"] print(f"\tHEAD: {PLAYER_ICON['head']} ") print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►") print(f"\tLEGS: {PLAYER_ICON['legs']} ") elif new_body_part_type == "legs": part_type = BODY_PARTS["legs"] print(f"\tHEAD: {PLAYER_ICON['head']} ") print(f"\tBODY: {PLAYER_ICON['body']} ") print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►") key = key_pressed() if key in KEY_BINDINGS_MOVE["left"] and id > 0: change_body_part(player, new_body_part_type, id - 1) elif key in KEY_BINDINGS_MOVE["right"] and id < len(part_type) - 1: change_body_part(player, new_body_part_type, id + 1) elif key == 10: # test ENTERa input() pass elif key in KEY_BINDINGS["exit"]: PLAYER_ICON[new_body_part_type] = part_type[id] return player else: change_body_part(player, new_body_part_type, id)
def small_taking_dmg(player): # Dmg small monster deal to Player player["HP"] -= small_monster_dmg print("Player took dmg -" + str(small_monster_dmg) + "HP") if player["HP"] <= 0: clear_screen() game_over() input() raise SystemExit
def print_message(cipher, action): helpers.clear_screen() message = input(f"Type the message to {action}: ") helpers.clear_screen() if action == "encrypt": input(f"Encrypted message: {cipher.encrypt(message)}") else: input(f"Decrypted message: {cipher.decrypt(message)}")
def instruction(): with open('instruction.txt', 'r') as instruction: instruction = instruction.readlines() helpers.clear_screen() print_screen(instruction) while True: key = helpers.key_pressed() if key == 'q': break
def init(): player = stats.create_player(PLAYER_START_X, PLAYER_START_Y, PLAYER_ICON) board = engine.create_board(BOARD_WIDTH, BOARD_HEIGHT, "map1") clear_screen(0) #ui.show_logo_animation(LOGO) #ui.show_story() main(player, board)
def print_menu(duel_stracture_items, num_of_option = 1): helpers.clear_screen() TITLE = 0 MONSTERS = 1 EXIT = 2 print(f'{duel_stracture_items[TITLE]}')# print(f'{duel_stracture_items[MONSTERS][num_of_option]}')
def display_board(board): ''' Displays complete game board on the screen Returns: Nothing ''' helpers.clear_screen() for row in board: print(' '.join(row))
def display_intro_screen(board): ''' Displays complete intro screen board on the screen without spaces Returns: Nothing ''' helpers.clear_screen() for row in board: print(''.join(row), end ="") pass
def on_click(): error = register( **{user_attr: widget.get() for user_attr, widget in inputs}) if not error: clear_screen(window) on_success(window) else: tk.Label(window, text='error', background='red', foreground='white').grid(row=0, column=4)
def game_over(): # print(colored(asciiart.game_over, 'red', attrs=[])) empty_space = 5 * "\n" clear_screen() print(empty_space) for pictureLine in asciiart.game_over.splitlines(): print( colored(pictureLine.center(shutil.get_terminal_size().columns), 'red', attrs=["bold"])) print("\n\tDo you want to play again?")
def select_encrypt_or_decrypt(): while True: helpers.clear_screen() try: action = input("Whould you like to encrypt and decrypt? ") if action != "decrypt" and action != "encrypt": raise ValueError("You must pick between" + "encrypt and decrypt") except ValueError as error: print(error) else: break return action
def display_board(board): ''' Displays complete game board on the screen Returns: Nothing ''' helpers.clear_screen() for row in board: #print(''.join(row)) for element in row: print(element, end='') print()
def register_form(screen: tk.Tk): clear_screen(screen) inputs = [ tk.Entry(screen), tk.Entry(screen), tk.Entry(screen), tk.Entry(screen), ] for index, input_widget in enumerate(inputs): input_widget.grid(row=index, column=0) tk.Button(screen, text="Submit", command=lambda: print(inputs[0].get())).grid(row=len(inputs), column=0)
def player_say(board_with_player, player, sentence): # bubble speech relative position speech_Y = player["y"] - 2 if len(sentence) + player["x"] < len(board_with_player[0]): speech_X = player["x"] + 3 else: speech_X = player["x"] - len(sentence) for i in range(len(sentence)): board_with_player[speech_Y][speech_X + i] = sentence[i] clear_screen() display_board(board_with_player, player)
def move_forward(where): output = True if where == 0: helpers.clear_screen() print(human) where = 'Human' # input() elif where == 1: helpers.clear_screen() print(halfling) where = 'Halfling' # input() elif where == 2: helpers.clear_screen() print(dwarf) where = 'Dwarf' # input() elif where == 3: helpers.clear_screen() print(elf) where = 'Elf' # input() elif where == 9: # go to LEAVE output = False class_menu.start_menu(where) output = False return output
def show_character_confirmation(): clear_screen() print_title_fancily(None, "final check") print_text_fancily( "- Now, let's check your character again before we start our journey...") global player input('Press any key to show the avatar of the player ... \n') player.draw_player_avatar() input('Press any key to show the skill tree ... \n') player.draw_player_skill_tree() input('Press any key to show the stats of the character ... \n') player.show_player_stats() time.sleep(1) print_text_fancily(" - Everything seems fine! Let the journey begins!") input('Press any key to begin your yourney ...') begin_journey()
def render_login(screen: tk.Tk, on_success): def on_click(): if login(username.get(), password.get()): on_success(screen) else: tk.Label(screen, text="Invalid username or password", foreground="Red").grid(row=4, column=2) clear_screen(screen) username = tk.Entry(screen) username.grid(row=1,column=2) password = tk.Entry(screen) password.grid(row=2,column=2) tk.Label(screen, text='Username').grid(row=1,column=1) tk.Label(screen, text='Password').grid(row=2,column=1) tk.Button(screen, text='Login', command=on_click).grid(row=3, column=2)
def move_forward(where): output = True if where == 0: race_menu.race_start_menu() pass elif where == 1: helpers.clear_screen() load_highscore.print_highscore( load_highscore.sort_score( load_highscore.read_file('highscore.txt'))) input() pass elif where == 2: # go to LEAVE output = False return output
def race_start_menu(): is_running = True FIRST_ELEMENT = 0 SECOND_ELEMENT = 1 num_of_option = 0 while is_running: helpers.clear_screen() # print menu structure //ui.print_menu? # wait for user input print_menu(start_menu_structure(), num_of_option) key = helpers.key_pressed() # call menu handler with user input menu_handler_options = start_menu_handler(key, num_of_option) is_running = menu_handler_options[FIRST_ELEMENT] num_of_option = menu_handler_options[SECOND_ELEMENT]