diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..2a605f938d Binary files /dev/null and b/.DS_Store differ diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..6633b88227 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,10 +1,11 @@ from room import Room - +from player import Player +from item import Item # Declare all the rooms - +#Update for Branch room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + "North of you, the cave mount beckons ..."), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty passages run north and east."""), @@ -29,23 +30,77 @@ room['foyer'].n_to = room['overlook'] room['foyer'].e_to = room['narrow'] room['overlook'].s_to = room['foyer'] -room['narrow'].w_to = room['foyer'] +room['overlook'].w_to = room['foyer'] room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -# # Main -# + +items = { + "sword": Item("Sword", "This is used to stab things."), + "lantern": Item("Lantern", "This would be helpful in the dark."), + "shovel": Item("Shovel", "This could be used to bludgen or dig.") + + + +} + +room['outside'].items.append(items["lantern"]) +room['overlook'].items.append(items["sword"]) +room['narrow'].items.append(items["shovel"]) # Make a new player object that is currently in the 'outside' room. +new_player = Player(player_name = "Ryan", current_room = room["outside"]) +print("\nWelcome player! You may enter a direction in which to travel with n, s, e, w, and q to quit the game.\n\nYou may get, take, pickup items, or drop them.\n\n") +print(f"{new_player.player_name} is {new_player.current_room} \n") +print(new_player.current_room.list_items()) # Write a loop that: -# +while True: # * Prints the current room name + # * Prints the current description (the textwrap module might be useful here). + # * Waits for user input and decides what to do. -# + selection = input("Enter a direction, command or Q to escape: ") + user_selection = selection.lower().split(" ") + if len(user_selection) == 1: + if selection == "q": + print("Have a good day. Thanks for playing.") + break + elif selection == "n" or selection == "s" or selection == "e" or selection == "w": + new_player.move(selection) + print(f"\n{new_player.player_name} is {new_player.current_room.room_name} \n{new_player.current_room.description}\n\n {new_player.current_room.list_items()}") + elif selection == "i": + new_player.print_items() + else: + print("That is not a proper command.") + elif len(user_selection) == 2: + if user_selection[0] in ["take", "get", "pickup"]: + if items[user_selection[1]]: + new_player.pickup_item(items[user_selection[1]]) + + print("\n\nYou have added a new item to inventory!\n") + print(f"{new_player.player_name} is {new_player.current_room} \n") + print(new_player.current_room.list_items()) + else: + print("That isn't an item.") + elif user_selection[0] == "drop": + if items[user_selection[1]]: + new_player.drop_item(items[user_selection[1]]) + print("You dropped an item!") + print(new_player.print_items()) + print(f"{new_player.player_name} is {new_player.current_room} \n") + print(new_player.current_room.list_items()) + else: + print("That isn't an item.") + else: + print("That is not a proper command.") + else: + print("That is not a proper command.") + # If the user enters a cardinal direction, attempt to move to the room there. + # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..e9ae702467 --- /dev/null +++ b/src/item.py @@ -0,0 +1,10 @@ +class Item(): + def __init__(self, name, description): + self.name = name + self.description = description + + def pick_up(self): + print(f"{self.name} was picked up.") + + def drop(self): + print(f"{self.name} was dropped.") \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..07ed880e35 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,40 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + +class Player(): + def __init__(self, player_name, current_room): + self.player_name = player_name + self.current_room = current_room + self.items = [] + + + def move(self, direction): + if getattr(self.current_room, f"{direction}_to") is not None: + self.current_room = getattr(self.current_room, f"{direction}_to") + else: + print("There is no room in that Direction!") + + def pickup_item(self, item): + if self.current_room.items.count(item) > 0: + self.items.append(item) + self.current_room.items.remove(item) + item.pick_up() + else: + print(f"A {item.name} is not in this room.") + + def drop_item(self, item): + if self.items.count(item) > 0: + self.current_room.items.append(item) + self.items.remove(item) + item.drop() + else: + print(f"You do not have a {item.name} to drop.") + + def print_items(self): + if not self.items: + print("You have no items.") + else: + print("You have the following items: ") + for x in self.items: + print(x.name) \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..a188c83969 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,25 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room(): + def __init__(self, room_name, description): + self.room_name = room_name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + self.items = [] + + def __str__(self): + return f' {self.room_name}, {self.description}' + + + def list_items(self): + if not self.items: + print("This room has no items.") + else: + print("This room has: ") + for item in self.items: + print(item.name) + print(item.description) \ No newline at end of file