def player_movement(movement_name): """ Interface for the player movements choices """ # Clear the console and print the map ma.map_printer() # Print the possible actions print( f"\n1 - {ma.menu_data[movement_name][1]} 2- {ma.menu_data[movement_name][2]} 3 - {ma.menu_data[movement_name][3]} 4- {ma.menu_data[movement_name][4]}\n" ) # Ask the player choice player_choice = mm.menu_choice(movement_name) # Move depending on the player choice if player_choice == "1": # Move North move(variables.game_data["player"]["position"], player_choice) elif player_choice == "2": # Move West move(variables.game_data["player"]["position"], player_choice) elif player_choice == "3": # Move East move(variables.game_data["player"]["position"], player_choice) else: # Move south move(variables.game_data["player"]["position"], player_choice)
def show_stash(key, key_2, item_name): """ Show the stash by extracting the position (key, key_2) of an item stash and the name of the item that populates it (item_name) """ print(" __________") print("/\\_________\\") print("| / /") print("`...........") print("|\\ \\") print(f"| |---------| 1 - {item_name}") print("\\ | | Q - Quit") print(" \\|_________|") choice = input("\t\tChoose what you want to do : ").upper() while choice not in "1Q": # Player choice is not a digit or not in valid choice = input(f"\t\tChoose from 1 or Q : ").upper() if choice == "1": # Player chosed to take the item # Empty the stash variables.game_data["Item stash"][key]["position"] = [] variables.game_data["Item stash"][key]["items"] = [] # Reset symbol position variables.island_map[variables.game_data["player"]["position"][0]][ variables.game_data["player"]["position"][1]] = " " # Take the item take_item(item_name) # Return the player to the map ma.map_printer() pa.player_actions("Actions Menu") elif choice == "Q": # Return the player to the map ma.map_printer() pa.player_actions("Actions Menu")
def adventure(): """ Principal gameflow """ # Show the main menu mm.main_menu() # Print the map after the main menu ma.map_printer() # Let the player move pa.player_actions("Actions Menu")
def move(player_position, directions): """ Check if the player can move there and move him to his next position """ if directions == "1": # The player chose to move NORTH # Save the symbol of the next position next_pos = variables.island_map[player_position[0] - 1][player_position[1]] # Check if player can move there move_check = move_checker(next_pos) if move_check: # Player can move there # Change player position variables.game_data["player"]["position"][0] -= 1 elif directions == "2": # The player chose to move WEST # Save the symbol of the next position next_pos = variables.island_map[player_position[0]][player_position[1] - 1] # Check if player can move there move_check = move_checker(next_pos) if move_check: # Player can move there # Change player position variables.game_data["player"]["position"][1] -= 1 elif directions == "3": # The player chose to move EAST # Save the symbol of the next position next_pos = variables.island_map[player_position[0]][player_position[1] + 1] # Check if player can move there move_check = move_checker(next_pos) if move_check: # Player can move there # Change player position variables.game_data["player"]["position"][1] += 1 elif directions == "4": # The player chose to move SOUTH # Save the symbol of the next position next_pos = variables.island_map[player_position[0] + 1][player_position[1]] # Check if player can move there move_check = move_checker(next_pos) if move_check: # Player can move there # Change player position variables.game_data["player"]["position"][0] += 1 if not move_check: # Clear the console and print the map ma.map_printer() print(ma.map_tiles[next_pos][4]) # Check if the player is on a tile with an event tile_checker() # Clear the console and print the map ma.map_printer() # Print the move print( f"\n\t\t\tYou moved {ma.menu_data['Move Menu'][int(directions)][5::]}") # Check if the player is on a tile with an event tile_checker()
def tile_checker(): """ Check the tile where the player is standing """ # Check if the player as the 3 keys and is on the skull door if variables.game_data["player"]["position"] == ma.map_tiles["∩"][ 4] and all(variables.game_data['inventory']['keychain']): # Save the historic lb.add_historic(True) lb.save_historic() # Save leaderboard lb.add_score() lb.save_leaderboard() # Clear console and ASCII Art tb.clear() print(" .-----.----.-----.") print(" / /-.| |////| |.-\\ \\") print(" / /|_|| |////| ||_|\\ \\") print(" / : : |////| : : \\") print(" / /___: |////| :___\\ \\") print(" / : |_ |////| _| :___\\") print(" / / |_||////||_| \\ \\") print(" / : |_||////||_| : \\") print(" /____/____ |_||////||_| ____\\____\\") print(" / : _ | |////| | _ : \\") print(" / / ( ) | _ |////| _ | ( ) \\ \\") print(" \\ : | || ||////|| || | : /") print(" \\ / .'-\\ ||////|| /-`. \\ /") print("-----'-'---------'-'----'-'---------'-'------\n") print("\nYou open the door using the 3 keys, ") sys.exit() # Check for the mysterious places tiles if variables.game_data["player"]["position"] in ma.map_tiles["φ"][4]: # The player position is on a challenge if variables.game_data["player"]["position"] == ma.map_tiles["φ"][4][ 0] and not variables.game_data["inventory"]["keychain"][0]: # Launch the first challenge tb.clear() first_challenge = guess_number() if first_challenge: # Player won the challenge # Add the key to his inventory variables.game_data["inventory"]["keychain"][0] = True # Add 100 to the score variables.game_data["score"] += 500 # Change the map tile to the validated challenge tile variables.island_map[ma.map_tiles["φ"][4][0][0]][ ma.map_tiles["φ"][4][0][1]] = "√" elif variables.game_data["player"]["position"] == ma.map_tiles["φ"][4][ 1] and not variables.game_data["inventory"]["keychain"][1]: # Launch the second challenge tb.clear() second_challenge = ceasar_sypher() if second_challenge: # Player won the challenge # Add the key to his inventory variables.game_data["inventory"]["keychain"][1] = True # Add 100 to the score variables.game_data["score"] += 500 # Change the map tile to the validated challenge tile variables.island_map[ma.map_tiles["φ"][4][1][0]][ ma.map_tiles["φ"][4][1][1]] = "√" elif variables.game_data["player"]["position"] == ma.map_tiles["φ"][4][ 2] and not variables.game_data["inventory"]["keychain"][2]: # Launch the third challenge tb.clear() third_challenge = fizzbuzz.gameflow() if third_challenge: # Player won the challenge # Add the key to his inventory variables.game_data["inventory"]["keychain"][2] = True # Add 100 to the score variables.game_data["score"] += 500 # Change the map tile to the validated challenge tile variables.island_map[ma.map_tiles["φ"][4][2][0]][ ma.map_tiles["φ"][4][2][1]] = "√" variables.island_map[24][10] = "¤" variables.game_data["Monkey chest"]["position"] = [24, 10] # Add one actions to the counter variables.game_data["player"]["actions counter"] += 1 # Check if the player has the 3 keys and reveal the skull door ma.map_reveal() # Clear console reprint the map tb.clear() ma.map_printer() # Let the player choose again pa.player_actions("Actions Menu") elif variables.game_data["player"]["position"] == variables.game_data[ "Monkey chest"]["position"]: # Check if the player is on the monkey chest inv.monkey_chest() # Check if the player has the 3 keys and reveal the skull door ma.map_reveal() # Clear console reprint the map tb.clear() ma.map_printer() # Let the player choose again pa.player_actions("Actions Menu") else: # The player is on an item stash for key in variables.game_data["Item stash"]: # Check the first key layer for key_2 in variables.game_data["Item stash"][key]: # Iterate second key layer if variables.game_data["Item stash"][key][ key_2] == variables.game_data["player"]["position"]: # Extract the item name if the position is the one item_name = variables.game_data["Item stash"][key]["items"] # Clear console tb.clear() # # Print the stash with the item right item name inv.show_stash(key, key_2, item_name) # Let the player choose again pa.player_actions("Actions Menu")
def inventory_choices(): """ Show the inventory and let the player choose an item """ # # Clean the ivnentory from depleted items inventory_cleaner() # Print the inventory and show save how many items are in the bag inv_show() # Ask for the player choice choice = input("\t\tChoose what you want to do : ").upper() # Choice is a digit and in valid if choice.capitalize() == "Q": # Choice is Q, return to map ma.map_printer() # Ask what the player wants to do pa.player_actions("Actions Menu") try: if variables.game_data['inventory'][f'item_{choice}']['name'] == None: # Player choice is not a digit or not in valid print( f"\t\tChoose from the item list or choose Q to go back to the map." ) sleep(2) inventory_choices() else: # Refresh the screen inv_show() # Print the item chosed by the player print( f"\t\tYou chose the {variables.game_data['inventory'][f'item_{choice}']['name']}" ) # Save the item name item_name = f"{variables.game_data['inventory'][f'item_{choice}']['name']}" # Save the item number item_number = f"item_{choice}" # Ask what he wants to do with that item print( f"\n1 - {ma.menu_data['Item Actions'][1]} 2- {ma.menu_data['Item Actions'][2]} 3 - {ma.menu_data['Item Actions'][3]}\n" ) choice = mm.menu_choice("Item Actions") except KeyError: print( f"\t\tChoose from the item list or choose Q to go back to the map." ) sleep(2) inventory_choices() # Refresh the screen inv_show() # The player choose if choice == "1": # Use the selected item if he can be used use_item(item_name, item_number) elif choice == "2": # Drop the selected item if it can be dropped drop_item(item_name, item_number) elif choice == "3": # Refill the item if it can be refilled refill_item(item_name) inventory_choices() # Player choice is not a digit or not in valid print(f"\t\tChoose from the item list or choose Q to go back to the map") sleep(2) inventory_choices()