From 19c87b8bce6b5561dce946118678157ae9e2dafa Mon Sep 17 00:00:00 2001 From: fadygouda Date: Wed, 9 Sep 2020 18:12:52 -0700 Subject: [PATCH 1/2] mvp mod3 --- src/adv.py | 43 +++++++++++++++++++++++++++++++++++++++++-- src/player.py | 14 ++++++++++++++ src/room.py | 23 ++++++++++++++++++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..0cba3c9def 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,10 +1,11 @@ from room import Room +from player import Player # 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 +33,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 +50,41 @@ # 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/") + +while True: + + + + print(player.current_room.name) + print(player.current_room.description) + + user_input = input(f"{player.name} What direction would you like to go? >>>>>") + + 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) \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..fa474cb3d1 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,16 @@ # 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 + + 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..a52fef28bd 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,23 @@ # 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 + + 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 From 690e0d1e40a77abbb14219171f70df4dff17e248 Mon Sep 17 00:00:00 2001 From: fadygouda Date: Thu, 10 Sep 2020 20:34:56 -0700 Subject: [PATCH 2/2] mvp mod4 --- src/adv.py | 110 ++++++++++++++++++++++++++++++++++++++------------ src/item.py | 7 ++++ src/player.py | 5 ++- src/room.py | 9 +++++ 4 files changed, 104 insertions(+), 27 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 0cba3c9def..c68f22487e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ from room import Room from player import Player +from item import Item # Declare all the rooms @@ -54,7 +55,15 @@ player = Player("Fady", room['outside']) -print(f"Game Instructions: q is to quit, directions are n, e, s, & w/") +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: @@ -63,28 +72,77 @@ print(player.current_room.name) print(player.current_room.description) - user_input = input(f"{player.name} What direction would you like to go? >>>>>") - - 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) \ No newline at end of file + 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 fa474cb3d1..94cfb97530 100644 --- a/src/player.py +++ b/src/player.py @@ -4,6 +4,7 @@ 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}" @@ -13,4 +14,6 @@ def move(self, 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 + 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 a52fef28bd..59f812e10f 100644 --- a/src/room.py +++ b/src/room.py @@ -9,6 +9,15 @@ def __init__(self, name, description): 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':