Beispiel #1
0
def ride(player):
    """Allows player to ride bike
    Args:
        player (Player): player in the game
    Returns:
        bool: if the player can successfully ride a bike
    """
    # Check for bike in inventory
    if player.check_inventory("Bike"):
        # Get bike object
        bike = player.get_object("Bike")
        # Check for tire in inventory
        if player.check_inventory("Tire"):
            tire = player.get_object("Tire")
            if tire.used is True:
                print(
                    "You're really movin' now! This is saving you some energy!"
                )
                bike.used = True
                # Bike gives player energy
                player.energy += 2
                data_printer.print_health_levels(player)
                return True
            else:
                print("You have a tire, you just need to put it on!")
                return False
        else:
            print("You need to find a tire and put it on before you can ride!")
            return False
    else:
        print("You need to find a bike before you can ride it!")
        return False
Beispiel #2
0
def turn_on(player, obj, room):
    """Turn on object to give player help.
    Args:
        player (Player): current player
        obj (str): Name of object to turn on
        room (Room): current room of player
    """
    complete = False
    # check to see if player has object
    if player.check_inventory(obj.capitalize()):
        # Get object
        inv_obj = player.get_object(obj.capitalize())
        # Check to see if the verb is an applicable action
        if "turn on" in inv_obj.actions:
            inv_obj.used = True
            print("{} is on! This extra help gave you a boost!".format(
                inv_obj.name))
            player.energy += 5
            data_printer.print_health_levels(player)
            complete = True
    elif not player.check_inventory(obj.capitalize()):
        # check for feature to turn on
        for feature in room.features:
            for action in feature.actions:
                if action == "turn on":
                    print("{} is on! This extra help gave you a boost!".format(
                        feature.feature_name))
                    player.energy += 5
                    complete = True
                    # If hot spring
                    if feature.feature_name == "Faucet":
                        feature.obj_removed = True
    if not complete:
        print("You can't turn on {}".format(obj))
Beispiel #3
0
def paddle(player, obj1, obj2=None):
    """Check to see if player can use raft and oar
    Must use raft to go between river and waterfall
    Must use raft and oar to go from river to cave

    Args:
        obj1 = raft
        obj2 = oar
    Returns:
        If player successfully used objects to move rooms
    """
    # Check players inventory for raft
    if player.check_inventory(obj1):
        # get raft object
        raft_obj = player.get_object(obj1.capitalize())
        # check to see if player used this verb on an applicable object
        if "launch" in raft_obj.actions:
            raft_obj.used = True
            # Check to see if there is a second object associated with this action
            if obj2 is not None:
                # check to see if player has the second object
                if player.check_inventory(obj2):
                    # Get this object
                    oar_obj = player.get_object(obj2)
                    # Check to make sure this verb is applicable on second object
                    if "paddle" in oar_obj.actions:
                        # Successful action
                        oar_obj.used = True
                        print(
                            "The oar helped you get your raft through the rapids and saved you some energy."
                        )
                        # Give player energy
                        player.energy += 2
                        data_printer.print_health_levels(player)
                        return True
                    else:
                        print("You can't paddle with {}".format(obj2))
                else:
                    print(
                        "You have a raft, but an oar will get you down the river!"
                    )
                    return False
            else:
                print(
                    "This raft will help you move a lot faster and save energy!"
                )
                # Give player energy
                player.energy += 10
                data_printer.print_health_levels(player)
                return True
        else:
            print("You can't launch a {}".format(obj1))
    else:
        return False
Beispiel #4
0
    def player_status(self, moved_rooms):
        """Gives the hunger and thirst levels of a player as a list

        Prints
            self.energy (int): Integer representing players hunger levels
            self.hydration (int): Integer representing players thirst levels
        """
        if moved_rooms:
            # Energy levels will change by 3 for every move
            self.energy -= 3

            # Thirst levels will change by 2 for every move
            self.hydration -= 2

        else:
            # Energy levels will change by 1 for non-moving actions
            self.energy -= 2

            # Thirst levels will change by 1 for non-moving actions
            self.hydration -= 1

        if self.energy > 100:
            self.energy = 100

        if self.hydration > 100:
            self.hydration = 100

        # Determine if player is still alive
        if self.energy > 0 and self.hydration > 0:
            self.alive = True
        else:
            self.alive = False

        if self.energy <= 25 or self.hydration <= 25:
            data_printer.print_health_levels(self)
            print(
                "You're starting to get a little lightheaded, better find some water or food."
            )
Beispiel #5
0
def drink(player):
    """Player drinks from water bottle. Increases hydration health by 10 pts
    Args:
        player (Player): current player of the game
    Returns:
        None
    """
    if player.check_inventory("Water bottle"):
        wb = player.get_object("Water bottle")
        if wb.used is True:
            data_printer.word_wrap(
                "Refreshing! That will help you go the extra mile. Just don't"
                " forget to fill it back up!")
            player.hydration += 10
            data_printer.print_health_levels(player)
            # reset water bottle so player has to fill again
            wb.used = False
        else:
            print(
                "Oh no! You forgot to fill your bottle! Looks like you need to find water."
            )
    else:
        print("Uh Oh! You don't have your water bottle!")
Beispiel #6
0
def look_at(item, player1, room, rooms):
    """Requried verb/action
    Look at feature or object or inventory, gives a interesting explination of the feature or object.
    args:
        item(string): what the user wants to look at
        player1(Player): player used to access inventory
        room(Room): player's current location
    Return:
        bool: if item was succewssfully viewed
    """

    # if player wants to view inventory
    if item.lower() == "inventory":
        # Show player their current inventory
        print("Items in current inventory:")
        for i in player1.inventory:
            print(i.name)
        return True

    elif item.lower() == "map":
        # Check to see if player has map in inventory
        if player1.check_inventory(item.capitalize()):
            data_printer.print_map(rooms)
            return True
        else:
            print("You need to take the map before reading!")
            return False

    # if player wants to view an object or feature
    else:
        # Check if a feature of room
        for feature in room.features:
            if item.capitalize() == feature.feature_name or item.lower(
            ) in feature.aliases:
                if feature.feature_name == "Informational sign":
                    if player1.check_inventory("Flashlight"):
                        flashlight = player1.get_object("Flashlight")
                        if flashlight.used:
                            print(feature.description_no_objects)
                            feature.viewed = True
                        else:
                            print(feature.description_with_objects)
                    else:
                        print(feature.description_with_objects)

                # Check for beaver den - decrease energy
                elif feature.feature_name == "Beaver den":
                    # Check for viewing the sign first
                    info_sign = room.get_feature(1)
                    if info_sign.viewed:
                        # Decrease health
                        player1.energy -= 10
                        data_printer.print_health_levels(player1)
                        feature.viewed = True
                        print(feature.description_no_objects)
                        feature.obj_removed = True
                    else:
                        print(feature.description_with_objects)
                        feature.obj_removed = False

                else:
                    # if feature is part of the current room
                    feature.print_description(rooms)
                    # mark the feature as viewed
                    feature.viewed = True

                    # Check if water rapids - remove_obj
                    if feature.feature_name == "Water rapids":
                        # If player has both oar and raft
                        if player1.check_inventory(
                                "Oar") and player1.check_inventory("Raft"):
                            feature.obj_removed = True
                        else:
                            feature.obj_removed = False
                    # Check if anchor - remove_obj
                    if feature.feature_name == "Anchor":
                        # If player has both oar and raft
                        if player1.check_inventory(
                                "Shoes") and player1.check_inventory("Rope"):
                            feature.obj_removed = True
                        else:
                            feature.obj_removed = False
                    # Check if batteries - remove_obj
                    if feature.feature_name == "Blinking light":
                        # If player has both oar and raft
                        if player1.check_inventory("Batteries"):
                            feature.obj_removed = True
                        else:
                            feature.obj_removed = False
                    # Check if misty pool - remove_obj
                    if feature.feature_name == "Misty pool":
                        # set obj_remove to true
                        feature.obj_removed = True
                    # Check if geyser - remove_obj
                    if feature.feature_name == "Geyser":
                        # set obj_remove to true
                        feature.obj_removed = True
                    # Check if fire - remove_obj
                    if feature.feature_name == "Campfire":
                        # set obj_remove to true
                        feature.obj_removed = True
                    # Check if the sky - remove_obj
                    if feature.feature_name == "The sky":
                        # set obj_remove to true
                        feature.obj_removed = True
                    # Check if the sky - remove_obj
                    if feature.feature_name == "Water feature":
                        # set obj_remove to true
                        feature.obj_removed = True

                # call function to check if room has been completed
                room.check_room_completion()

                return True
        # Check if object in room
        for o in room.objects:
            if item.capitalize() == o.name:
                # if object is in room
                print(o.description)
                return True
        # Check if object in inventory
        for obj in player1.inventory:
            if item.capitalize() == obj.name:
                # if object is in inventory
                print(obj.description)
                return True
        # if item is not in room or inventory
        return False
def play_game(game1, player1):
    """Implement the game workflow and checks for game ending.
        1. Gets the players current room status
        2. Displays the health of the player
        3. Prints either long or short into
        4. Prints exits
        5. Sets the room to visited
        6. While the user has not moved rooms, enter while loop
            a. prompt the user and get input
            b. split input
            c. determine if action effects game or player and call appropriate function
            d. calculate players health
        7. Check the game status
    """
    prompt = ">>>"

    while game1.game_over is False:
        # Get current room
        current_room = player1.location

        #print current room
        print("****************************************************")
        print("You are in the {}".format(current_room.name))
        print("****************************************************")

        # Display health
        data_printer.print_health_levels(player1)

        # Determine Into to display (short or long)
        # Display the intro
        data_printer.print_room_intro(current_room)

        # Display exit info so user knows how to exit
        data_printer.print_room_exit(current_room)

        # Set room to visited
        current_room.visited = True

        # variable to loop back if invalid input or if player has not moved rooms
        moved_rooms = False

        while moved_rooms is False:
            # Get user input
            user_input = input(prompt)
            # Split user input into command , preposition, object/feature/room
            split_input = user_input.split()
            # First is the command
            if split_input:
                command = split_input[0]
            else:
                command = "INVALID"
            # If second word part of location
            if len(split_input) >= 2 and split_input[1] in [
                    "trail", "habitat", "spring", "field", "station", "light",
                    "noises", "building", "springs", "space", "waters"
            ]:
                command = ' '.join(split_input[0:])
                preposition = ""
                use_on = ""
            elif len(split_input) >= 2:
                # If there is prepostion
                if split_input[1] in ["at", "in", "on", "up"]:
                    preposition = split_input[1]
                    use_on = ' '.join(split_input[2:])
                else:
                    use_on = ' '.join(split_input[1:])
                    preposition = ""

            # If there is a one word command, others are empty
            else:
                use_on = ""
                preposition = ""

            ############################################################################
            #
            # DETERMINE ACTION
            #
            ############################################################################

            ############################################################################
            # Commands related to the game and not player action
            ############################################################################

            # If action is help
            if command.lower() == "help":
                data_printer.print_help()
                moved_rooms = False

            # If action is savegame
            elif command.lower() == "savegame":
                game1.save_game(player1)
                moved_rooms = False

            # If action is loadgame
            elif command.lower() == "loadgame":
                game1 = data_import.load_game()
                player1 = data_import.load_player()

                if not game1 or not player1:
                    print("Error: Unable to load game!")
                else:
                    print("Game resumed!")

            # If action is health
            elif command.lower() == "health":
                game1.health_status(player1)
                moved_rooms = False

            # If action is exit
            elif command.lower() == "exit":
                game1.list_exit(player1.location)
                moved_rooms = False

            elif command.lower() == "features":
                data_printer.print_room_features(current_room)
                moved_rooms = False

            # If action is quit
            elif command.lower() == "quit":
                user_input = input("Would you like to save before quitting?")
                if user_input in ["yes", "Yes", "YES", "Y", "y"]:
                    game1.save_game(player1)

                game1.quit_game()
                break

            ############################################################################
            # Commands related to player action and not game state
            ############################################################################
            else:
                valid_action = False
                # Determine if the action is possible given the objects/features
                specific_verbs = game1.get_useable_verbs(current_room, player1)
                if preposition == "":
                    if command.lower() in specific_verbs:
                        moved_rooms = determine_action(game1.rooms, player1,
                                                       current_room, command,
                                                       preposition, use_on)
                        valid_action = True
                    else:
                        # Check command was not an exit name
                        for room in game1.rooms:
                            if command.lower() in room.east_exits or command.lower() in room.west_exits or \
                                    command.lower() in room.north_exits or command.lower() in room.south_exits:
                                # change command to use_on
                                use_on = command
                                # change command to go
                                command = "go"
                                # call move_room function in actions to get next room
                                next_room = move_room(command, use_on,
                                                      current_room,
                                                      game1.rooms, player1)
                                # call moved_locations to try to move to that room
                                moved_rooms = moved_locations(
                                    next_room, player1)
                                valid_action = True

                elif preposition != "":
                    full_command = command.lower() + " " + preposition
                    if full_command in specific_verbs:
                        moved_rooms = determine_action(game1.rooms, player1,
                                                       current_room, command,
                                                       preposition, use_on)
                        valid_action = True
                    else:
                        # Check command was not an exit name
                        for room in game1.rooms:
                            if command.lower() in room.east_exits or command.lower() in room.west_exits or \
                                    command.lower() in room.north_exits or command.lower() in room.south_exits:
                                # change command to use_on
                                use_on = command
                                # change command to go
                                command = "go"
                                # call move_room function in actions to get next room
                                next_room = move_room(command, use_on,
                                                      current_room,
                                                      game1.rooms, player1)
                                # call moved_locations to try to move to that room
                                moved_rooms = moved_locations(
                                    next_room, player1)
                                valid_action = True

                # If action is not in list of verbs or an exit name, print error message
                if valid_action is False:
                    print(
                        "Error: not a valid action. Type <help> to see valid verbs"
                    )

                # Calculate players new health
                player1.player_status(moved_rooms)

            # Check for game status
            game1.check_game_status(player1)
            if game1.game_over is True:
                break