示例#1
0
    def boss_puzzle_selection(self, the_input: str, possible_answers: [str], number_of_tries: int):

        # inputs to be recognized as valid
        list_answers =  possible_answers
        list_exit = ["exit", "quit", "back", "go back"]
        lowered_input = str(the_input).lower()  # to make the input case insensitive

        while True:
            if command_parsing(lowered_input, list_answers):
                selection = 1
                break

            if command_parsing(lowered_input, list_exit):
                selection = 2
                break

            number_of_tries -= 1
            if number_of_tries == 0:
                selection = 2
                break

            write_over("That is incorrect. You have " + str(number_of_tries) + " remaining.")
            go_up_and_clear()
            lowered_input = str(input(">>> ")).lower()

        return int(selection), number_of_tries
示例#2
0
    def puzzle_selection(self, the_input: str, possible_answers: [str],
                         failed_msg: str, ga):

        # inputs to be recognized as valid
        list_answers = possible_answers
        list_exit = ["exit", "quit", "back", "go back"]
        lowered_input = str(
            the_input).lower()  # to make the input case insensitive

        while True:
            if command_parsing(lowered_input, list_answers):
                selection = 1
                break

            if command_parsing(lowered_input, list_exit):
                selection = 2
                break

            if len(the_input) > 99:
                write_over("Your input is too long.")
            write_over(failed_msg)
            go_up_and_clear()
            lowered_input = str(input(">>> ")).lower()

        return int(selection)
def save_selection(the_input: str, slot_tracker: []) -> int:

    # inputs to be recognized as valid
    list_one = [
        1, "1", "1.", "game1", "slot1", "game slot 1", "gameslot 1",
        "gameslot1", "game 1", "slot 1"
    ]
    list_two = [
        2, "2", "2.", "game2", "slot2", "game slot 2", "gameslot 2",
        "gameslot2", "game 2", "slot 2"
    ]
    list_three = [
        3, "3", "3.", "game3", "slot3", "game slot 3", "gameslot 3",
        "gameslot3", "game 3", "slot 3"
    ]
    list_exit = [
        4, "4", "exit", "quit", "q", "exit game", "quit game", "4. exit",
        "bye", "byebye", "back", "go back"
    ]

    selection = 0
    wrong_input = True
    the_input = str(the_input)
    lowered_input = the_input.lower()  # to make the input case insensitive

    while wrong_input:

        if command_parsing(lowered_input, list_one):
            selection = 1
            break

        if command_parsing(lowered_input, list_two):
            selection = 2
            break

        if command_parsing(lowered_input, list_three):
            selection = 3
            break

        if command_parsing(lowered_input, list_exit):
            selection = 4
            break

        if wrong_input:
            if len(the_input) > 99:
                write_over("Your input is too long.")
            write_over("Invalid Input. Try again.")
            go_up_and_clear()
            command_line = "Make your selection >>> "
            the_input = input(command_line)
            the_input = str(the_input)
            lowered_input = the_input.lower()

    return int(selection)
示例#4
0
def help_menu_screen():
    back_to_game = False
    while back_to_game == False:
        standard_title_display("Help")
        main_menu.print_in_the_middle(main_menu.GAME_WIDTH,
                                      ("1. Game Story   "))
        main_menu.print_in_the_middle(main_menu.GAME_WIDTH,
                                      ("2. Characters   "))
        main_menu.print_in_the_middle(main_menu.GAME_WIDTH,
                                      ("3. Game Commands"))
        main_menu.print_in_the_middle(main_menu.GAME_WIDTH,
                                      ("4. Items        "))
        main_menu.print_in_the_middle(main_menu.GAME_WIDTH,
                                      ("5. Resume Game  "))
        main_menu.empty_line(3)
        main_menu.dotted_line(main_menu.GAME_WIDTH)

        list_game_story = [
            "1", "game story", "story", "about game", "1. game story"
        ]
        list_characters = [
            "2", "character", "characters", "char", "chars", "game characters",
            "2. characters"
        ]
        list_game_commands = [
            "3", "game commands", "game command", "commands", "command",
            "3. game commands"
        ]
        list_items = ["4", "item", "items", "about items", "4. items"]
        list_back = [
            "5", "exit", "return", "back", "resume", "resume game",
            "5. resume game"
        ]

        selection = input(">>> ")

        while True:
            if command_parsing(selection,
                               list_game_story) == 1:  #Help for game story
                gameNarrationHelp(start_narration1(), start_narration2())
                break
            if command_parsing(
                    selection,
                    list_characters) == 1:  #Help for game characters
                mainCharNarration(long_for_agt_dope(), long_for_dr_crime())
                break
            if command_parsing(
                    selection,
                    list_game_commands) == 1:  #Help for game commands
                clear_screen()
                main_menu.dotted_line(main_menu.GAME_WIDTH)
                main_menu.empty_line(2)
                command_help(main_menu.GAME_WIDTH)
                main_menu.empty_line(2)
                main_menu.dotted_line(main_menu.GAME_WIDTH)
                input("Press [Enter] to continue...")
                clear_screen()
                break
            if command_parsing(selection,
                               list_items) == 1:  #Help for game items
                itemHelp()
                break
            if command_parsing(selection, list_back) == 1:  #Back to the game
                clear_screen()
                back_to_game = True
                break
            main_menu.write_over("Invalid Input.  Try again.")
            sys.stdout.write("\033[F")  # go up one line
            sys.stdout.write("\033[K")  # clear line
            selection = str(input(">>> ")).lower()
def cline_print_up_cline(msg: str):
    sys.stdout.write("\033[K")  # clear line
    write_over(msg)
    go_up_and_clear()
def gameplay_selection(ga, the_input: str, nswe_districts: List[str],
                       district_exits: List[str],
                       this_district: city.District) -> str:

    # Change nswe_districts to lower case
    # e.g. ['hawkins', None, 'greenland grove', 'oak square']
    nswe_districts = list(
        map(lambda x: x.lower() if x is not None else x, nswe_districts))

    # Change district_exits to lower case
    # e.g. ['dayton dr', '', 'summer ln', 'shore blvd']
    district_exits = list(
        map(lambda x: x.lower() if x is not None else x, district_exits))

    # 2D general action array
    #   1st element of each 1D action list is the key action noun
    general_action_array = [
        [
            "exit", "quit", "q", "exit game", "quit game", "bye", "byebye",
            "main", "main menu"
        ],
        [
            "inventory", "bag", "open inventory", "open bag", "see inventory",
            "check inventory"
        ], ["help", "help me", "manual", "guide", "q&a", "open help"],
        ["savegame", "save game", "save"], ["loadgame", "load game", "load"],
        [
            "look", "look around", "look around the district",
            "take a look at the district"
        ]
        # ....
    ]

    # 2D NSWE movement array
    #   1st element of each 1D action list is the key action noun
    nswe_actions = [["go up", "go north", "go to north", "north", "up"],
                    ["go down", "go south", "go to south", "south", "down"],
                    ["go left", "go west", "go to west", "west", "left"],
                    ["go right", "go east", "go to east", "east", "right"]]

    # Add additional word parsing for each NSEW movement based on district name
    for i in range(4):
        if nswe_districts[i] is not None:
            arr = nswe_actions[i]
            whole_name = nswe_districts[i]  # ex: 'greenland grove'
            first_word = whole_name.split()[0]  # ex: 'greenland'
            arr.append(whole_name)  # ex: greenland grove
            arr.append(first_word)  # ex: greenland
            arr.append("go " + whole_name)  # ex: go greenland grove
            arr.append("go to " + whole_name)  # ex: go to greenland grove
            arr.append("go " + first_word)  # ex: go greenland
            arr.append("go to " + first_word)  # ex: go to greenland
            arr.append("travel " + whole_name)  # ex: travel greenland grove
            arr.append("travel to " +
                       whole_name)  # ex: travel to greenland grove
            arr.append("travel " + first_word)  # ex: travel greenland
            arr.append("travel to " + first_word)  # ex: travel to greenland

            if district_exits[i] != "":
                whole_exit_name = district_exits[i]  # ex: 'shore blvd'
                first_exit_word = whole_exit_name.split()[0]  # ex: 'shore'
                arr.append(whole_exit_name)  # ex: shore blvd
                arr.append(first_exit_word)  # ex: shore
                arr.append("go " + whole_exit_name)  # ex: go shore blvd
                arr.append("go to " + whole_exit_name)  # ex: go to shore blvd
                arr.append("go " + first_exit_word)  # ex: go shore
                arr.append("go to " + first_exit_word)  # ex: go to shore
                arr.append("travel " +
                           whole_exit_name)  # ex: travel shore blvd
                arr.append("travel on " +
                           whole_exit_name)  # ex: travel on shore blvd
                arr.append("travel " + first_exit_word)  # ex: travel shore
                arr.append("travel on " +
                           first_exit_word)  # ex: travel on shore

            general_action_array.append(arr)

    # Action array for special feature, Lair
    lair_action_array = [["view lair", "look lair"], ["enter lair"],
                         ["take lair", "take up lair"], ["use lair"],
                         ["talk lair"], ["eat lair"], ["hit lair"],
                         ["climb lair"], ["move lair"], ["swim lair"],
                         ["lift lair"], ["feed lair"]]

    selection = None
    the_input = translator.translate(
        str(the_input).lower())  # to make the input case insensitive

    while selection == None:

        # Build action arrays on screen refresh: START ------------------------------------------------------

        # Build district_items_action array for items in district
        district_items_action = []
        for item in this_district._district_items:
            for action in item.action:
                for commands in action.commands:
                    district_items_action.append(commands)

        # Build dropped_items_action array for dropped items in district, exclude item-item interactions
        dropped_items_action = []
        for item in this_district._dropped_items:
            for action in item.action:
                if action.response_type != ActionType.TRIGGER:
                    for commands in action.commands:
                        dropped_items_action.append(commands)

        # Build district_characters_action array for characters in district
        district_characters_action = []
        for character in this_district._characters:
            for action in character._action:
                for commands in action.commands:
                    district_characters_action.append(commands)

        #Build user_items_action array for items in user's inventory
        user_items_action = []
        for item in ga.current_inventory:
            for action in item.action:
                for commands in action.commands:
                    user_items_action.append(commands)

        #Build complete lair action array
        complete_lair_arr = []
        for arr in lair_action_array:
            for elem in arr:
                complete_lair_arr.append(elem)

        # Rebuild action arrays on screen refresh: END -------------------------------------------------------------

        # Check for command in action arrays: START --------------------------------------------------------------

        # Check for valid action in general action array
        for action_list in general_action_array:
            if the_input in action_list:
                return action_list[0]

        # Check for valid action in lair action, if applicable
        if ga.lair_discovered() and (the_input in complete_lair_arr):
            for action_list in lair_action_array:
                if the_input in action_list:

                    if action_list[0] == "enter lair":
                        return ga.final_game_sequence()

                    elif action_list[0] == "view lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "This must be Dr. Crime's Lair. Now is your chance to stop his madness!"
                        )

                    elif action_list[0] == "take lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "You can't possibly fit a giant Lair in your inventory!"
                        )

                    elif action_list[0] == "use lair":
                        sys.stdout.write("\033[K")  # clear line
                        print("Did you mean to enter instead?")

                    elif action_list[0] == "talk lair":
                        sys.stdout.write("\033[K")  # clear line
                        print("You yell, 'I'm coming for you Dr. Crime!'")

                    elif action_list[0] == "eat lair":
                        sys.stdout.write("\033[K")  # clear line
                        print("You can't eat a building!")

                    elif action_list[0] == "hit lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "You try to harm the Lair, but a magic seems to be protecting it."
                        )

                    elif action_list[0] == "climb lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "Better off saving your energy to fit Dr. Crime instead."
                        )

                    elif action_list[0] == "move lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "Pretty sure you won't be able to move the Lair.")

                    elif action_list[0] == "swim lair":
                        sys.stdout.write("\033[K")  # clear line
                        print("That doesn't make sense!")

                    elif action_list[0] == "lift lair":
                        sys.stdout.write("\033[K")  # clear line
                        print(
                            "Pretty sure you won't be able to lift the Lair.")

                    elif action_list[0] == "feed lair":
                        sys.stdout.write("\033[K")  # clear line
                        print("It's a building. Also you don't have any food.")

            sys.stdout.write("\033[F")  # go up one line
            go_up_and_clear()
            the_input = translator.translate(str(input(">>> ")).lower())
            continue

        # Check for valid actions for district items
        status, the_input = district_action_function(
            ga, the_input, district_items_action,
            this_district._district_items, this_district)
        if status == "continue":
            continue
        elif status == "return":
            return ""
        elif status == "brokestone":
            return "brokestone"

        # Check for valid actions for dropped items
        status, the_input = district_action_function(
            ga, the_input, dropped_items_action, this_district._dropped_items,
            this_district)
        if status == "continue":
            continue
        elif status == "return":
            return ""
        elif status == "brokestone":
            return "brokestone"

        # Check for district-specific action, characters
        if the_input in district_characters_action:
            for character in this_district._characters:
                for action in character._action:
                    if the_input in action.commands:
                        if action.response_type == ActionType.DISPLAY:
                            sys.stdout.write("\033[K")  # clear line
                            print(action.response)
                        if action.response_type == ActionType.EVENT:
                            character.play_char_puzzle(ga, this_district)

                            if character._short_description == "Daniel Webster" and character._puzzle.state == PuzzleState.SOLVED:
                                clue_str = "Daniel Webster says not to mess with the Stone."
                                if clue_str not in ga.obtained_clues:
                                    ga.add_to_obtained_clues(clue_str)

                            return ""
            sys.stdout.write("\033[F")  # go up one line
            go_up_and_clear()
            the_input = translator.translate(str(input(">>> ")).lower())
            continue

        # Check for user's item action
        if the_input in user_items_action:
            for item in ga.current_inventory:
                for action in item.action:
                    if the_input in action.commands:

                        # Only respond to userItem-to-districtItem interactions
                        if action.response_type == ActionType.TRIGGER:
                            target_item_to_interact_with = action.response.lower(
                            )

                            # Search for target_item in district
                            itemInDistrict = None
                            for d_item in this_district._district_items:
                                if d_item.name.lower(
                                ) == target_item_to_interact_with:
                                    itemInDistrict = d_item
                                    break

                            # If target_item in district
                            if itemInDistrict:

                                # Green Chest -- Vitality Orb
                                if itemInDistrict.name.lower(
                                ) == "green chest":
                                    informScreen(
                                        "You've opened the Green Chest.")
                                    if ga.game_state._vitality_orb == False:
                                        if ga.space_in_inventory():
                                            informScreen(
                                                "You've gained the Vitality Orb!"
                                            )
                                            ga.game_state._vitality_orb = True
                                            ga.add_to_inventory(
                                                ga.
                                                get_item_from_uncollected_legendary_items(
                                                    "Vitality Orb"))
                                            ga.remove_item_from_uncollected_legendary_items(
                                                "Vitality Orb")
                                            return ""
                                        else:
                                            informScreen(
                                                "You don't have enough space in your inventory to acquire the item in it."
                                            )
                                            return ""
                                    else:
                                        informScreen(
                                            "Looks like there's nothing here.")
                                        return ""

                                # Red Chest -- Strength Orb
                                if itemInDistrict.name.lower() == "red chest":
                                    informScreen(
                                        "You've opened the Red Chest.")
                                    if ga.game_state._strength_orb == False:
                                        if ga.space_in_inventory():
                                            informScreen(
                                                "You've gained the Strength Orb!"
                                            )
                                            ga.game_state._strength_orb = True
                                            ga.add_to_inventory(
                                                ga.
                                                get_item_from_uncollected_legendary_items(
                                                    "Strength Orb"))
                                            ga.remove_item_from_uncollected_legendary_items(
                                                "Strength Orb")
                                            return ""
                                        else:
                                            informScreen(
                                                "You don't have enough space in your inventory to acquire the item in it."
                                            )
                                            return ""
                                    else:
                                        informScreen(
                                            "Looks like there's nothing here.")
                                        return ""

                                # Yellow Chest -- Vision Orb
                                if itemInDistrict.name.lower(
                                ) == "yellow chest":
                                    informScreen(
                                        "You've opened the Yellow Chest.")
                                    if ga.game_state._vision_orb == False:
                                        if ga.space_in_inventory():
                                            informScreen(
                                                "You've gained the Vision Orb!"
                                            )
                                            informScreen(
                                                "A darkness can be seen in the distance. It seems to be coming from "
                                                +
                                                ga.game_state._lair_location +
                                                ".")
                                            ga.add_to_obtained_clues(
                                                "A darkness can be seen in the distance. It seems to be coming from "
                                                +
                                                ga.game_state._lair_location +
                                                ".")
                                            ga.game_state._vision_orb = True
                                            ga.add_to_inventory(
                                                ga.
                                                get_item_from_uncollected_legendary_items(
                                                    "Vision Orb"))
                                            ga.remove_item_from_uncollected_legendary_items(
                                                "Vision Orb")
                                            return ""
                                        else:
                                            informScreen(
                                                "You don't have enough space in your inventory to acquire the item in it."
                                            )
                                            return ""
                                    else:
                                        informScreen(
                                            "Looks like there's nothing here.")
                                        return ""

                                # Crystal Chest -- Magic Sword
                                if itemInDistrict.name.lower(
                                ) == "crystal chest":
                                    informScreen(
                                        "You've opened the Crystal Chest.")
                                    if ga.game_state._magic_sword == False:
                                        if ga.space_in_inventory():
                                            informScreen(
                                                "You've gained the Magic Sword!"
                                            )
                                            ga.game_state._magic_sword = True
                                            ga.add_to_inventory(
                                                ga.
                                                get_item_from_uncollected_legendary_items(
                                                    "Magic Sword"))
                                            ga.remove_item_from_uncollected_legendary_items(
                                                "Magic Sword")
                                            return ""
                                        else:
                                            informScreen(
                                                "You don't have enough space in your inventory to acquire the item in it."
                                            )
                                            return ""
                                    else:
                                        informScreen(
                                            "Looks like there's nothing here.")
                                        return ""

                            else:
                                sys.stdout.write("\033[K")  # clear line
                                print(target_item_to_interact_with.title() +
                                      " cannot be found.")
                        else:
                            sys.stdout.write("\033[K")  # clear line
                            print(
                                "Use inventory menu to directly interact with items in your possession."
                            )
            sys.stdout.write("\033[F")  # go up one line
            go_up_and_clear()
            the_input = translator.translate(str(input(">>> ")).lower())
            continue

        # Check for command in action arrays: END --------------------------------------------------------------

        # Else, bad action: START -----------------------------------------------------------------------------

        if selection == None:
            if len(the_input) > 99:
                sys.stdout.write("\033[K")  # clear line
                write_over("Your input is too long.")
            sys.stdout.write("\033[K")  # clear line
            write_over("Invalid Input.  Try again.")
            go_up_and_clear()
            the_input = translator.translate(str(input(">>> ")).lower())

        # Else, bad action: END -----------------------------------------------------------------------------

    return selection