diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..c68f22487e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,10 +1,12 @@ from room import Room +from player import Player +from item import Item # Declare all the rooms 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."""), @@ -32,7 +34,7 @@ room['narrow'].w_to = room['foyer'] room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] - +room['overlook'].e_to = room['treasure'] # # Main # @@ -49,3 +51,98 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. +directions = ['n', 's', 'e', 'w'] + +player = Player("Fady", room['outside']) + +print(f"Game Instructions: q is to quit, directions are n, e, s, & w.\nIf you find an item you like in a room, type get (item name).\nIf you want to drop an item from your inventory, type drop (item name)") + +room['outside'].item_list.append(Item("fishing-rod", "used for fishing")) +room['foyer'].item_list.append(Item("binoculars", "used to see afar")) +room['overlook'].item_list.append(Item("sword", "sword resting in a rock, there's something weird about this thing")) +room['narrow'].item_list.append(Item("fire-wood", "sometimes nights get cold, this will keep you warm!")) +room['treasure'].item_list.append(Item("gold", "so dusty, looks like the looters didn't find everything!")) + + + +while True: + + + + print(player.current_room.name) + print(player.current_room.description) + + if len(player.current_room.item_list) > 0: + print("items in the room: ") + for item in player.current_room.item_list: + print(f'Item name: {item.name}\nItem description: {item.description}') + + + + user_input = input(f"{player.name} What would you like to do?? >>>>>") + + if len(user_input.split()) == 1: + + if user_input == 'n': + if player.current_room.n_to: + player.current_room = player.current_room.n_to + else: + print("There's nothing in that direction, try again!") + if user_input == 's': + if player.current_room.s_to: + player.current_room = player.current_room.s_to + else: + print("There's nothing in that direction, try again!") + if user_input == 'e': + if player.current_room.e_to: + player.current_room = player.current_room.e_to + else: + print("There's nothing in that direction, try again!") + if user_input == 'w': + if player.current_room.w_to: + player.current_room = player.current_room.w_to + else: + print("There's nothing in that direction, try again!") + + if user_input == 'q': + exit(0) + + if user_input == 'i' or 'inventory': + if len(player.inventory) > 0: + for item in player.inventory: + print(f"Item name: {item.name}\nItem description: {item.description}") + else: + print(f"No items in you inventory") + + # if user_input == 'inventory': + # if len(player.inventory) > 0: + # for item in player.inventory: + # print(f"Item name: {item.name}\nItem description: {item.description}") + # else: + # print(f"No items in you inventory") + + elif len(user_input.split()) == 2: + + if user_input.split()[0] == 'get': + if len(player.current_room.item_list) > 0: + for item in player.current_room.item_list: + if item.name == user_input.split()[1]: + player.current_room.item_list.remove(item) + player.inventory.append(item) + else: + print(f"{user_input.split()[1]} was not found in the {player.current_room.name}") + else: + print(f"No items are available to take in {player.current_room.name}") + + if user_input.split()[0] == 'drop': + if len(player.inventory) >0: + for item in player.inventory: + if item.name == user_input.split()[1]: + player.inventory.remove(item) + player.current_room.item_list.append(item) + else: + print(f"{user_input.split()[1]} in not in the your inventory") + else: + print(f"There are no items to drop!") + else: + print("Your input is invalid") diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..938936b21f --- /dev/null +++ b/src/item.py @@ -0,0 +1,7 @@ +class Item: + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f"Name: {self.name}, Description: {self.description} " \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..94cfb97530 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,19 @@ # Write a class to hold player information, e.g. what room they are in # currently. +class Player: + def __init__(self, name, current_room): + self.name = name + self.current_room = current_room + self.inventory = [] + + def __str__(self): + player_string = f"Player is in the {self.current_room}" + + def move(self, direction): + next_room = self.current_room.get_direction(direction) + if next_room is not None: + self.current_room = next_room + else: + print("There's no room in that direction!") + + \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..59f812e10f 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,32 @@ # 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, name, description): + self.name = name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + self.item_list = [] + + def __str__(self): + ret = f"{self.name}\n" + for i, c in enumerate(self.item_list): + ret += " " + str(i+1) + ": " + c.name +"\n" + ret += " " + str(1+2) + ": Exit" + + return ret + + def get_direction(self, direction): + if direction == 'n': + return self.n_to + elif direction == 's': + return self.s_to + elif direction == 'e': + return self.e_to + elif direction == 'w': + return self.w_to + else: + return None \ No newline at end of file