From 4bf773bb03d836b71f550c7bf42ab154cc779bbb Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 02:28:15 -0500 Subject: [PATCH 1/7] first day done --- src/adv.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/player.py | 8 ++++++ src/room.py | 10 ++++++- 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..12444de06c 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,3 +1,4 @@ +from player import Player from room import Room # Declare all the rooms @@ -21,6 +22,8 @@ earlier adventurers. The only exit is to the south."""), } +print(room['outside']) + # Link rooms together @@ -39,6 +42,83 @@ # Make a new player object that is currently in the 'outside' room. + +print('welcome to gay adventureland 3.0!') + +player_name = input("what is your name?: ") + +location = room['outside'] + +player = Player(player_name, location) + + +print(f"you are {player_name}, the gay barbarian {location}") + +print("where would you like to go next?") + + +def choose_action(): + return int(input("[1] north [2] south [3] east [4] west [9] Quit\n")) + + +action = choose_action() + + +def next_step(): + print(location) + print('where would you like to go next?') + global action + action = choose_action() + + +def wrong_way(): + print('that direction is blocked, try again') + global action + action = choose_action() + + +while not action == 9: + if location == room['outside']: + if action == 1: + location = room['outside'].n_to + next_step() + + elif location == room['foyer']: + + if action == 2: + location = room['foyer'].s_to + next_step() + + elif action == 3: + location = room['foyer'].e_to + next_step() + + elif action == 1: + location = room['foyer'].n_to + next_step() + + elif location == room['overlook']: + if action == 2: + location = room['overlook'].s_to + next_step() + + elif location == room['narrow']: + if action == 4: + location = room['narrow'].w_to + next_step() + elif action == 1: + location = room['narrow'].n_to + next_step() + + elif location == room['treasure']: + if action == 2: + location = room['treasure'].s_to + next_step() + + else: + wrong_way() + + # Write a loop that: # # * Prints the current room name diff --git a/src/player.py b/src/player.py index d79a175029..82f67ab5e3 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,10 @@ # 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): + return f"{self.name} is at {self.current_room}" diff --git a/src/room.py b/src/room.py index 24c07ad4c8..3422d98d4f 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,10 @@ # 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 + + def __str__(self): + return f"you find yourself at {self.name}, {self.description}" From 0defaa0372c0347c98ecd300461b92f05e67677a Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 02:28:15 -0500 Subject: [PATCH 2/7] first day done --- src/adv.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/player.py | 8 ++++++ src/room.py | 10 ++++++- 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..12444de06c 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,3 +1,4 @@ +from player import Player from room import Room # Declare all the rooms @@ -21,6 +22,8 @@ earlier adventurers. The only exit is to the south."""), } +print(room['outside']) + # Link rooms together @@ -39,6 +42,83 @@ # Make a new player object that is currently in the 'outside' room. + +print('welcome to gay adventureland 3.0!') + +player_name = input("what is your name?: ") + +location = room['outside'] + +player = Player(player_name, location) + + +print(f"you are {player_name}, the gay barbarian {location}") + +print("where would you like to go next?") + + +def choose_action(): + return int(input("[1] north [2] south [3] east [4] west [9] Quit\n")) + + +action = choose_action() + + +def next_step(): + print(location) + print('where would you like to go next?') + global action + action = choose_action() + + +def wrong_way(): + print('that direction is blocked, try again') + global action + action = choose_action() + + +while not action == 9: + if location == room['outside']: + if action == 1: + location = room['outside'].n_to + next_step() + + elif location == room['foyer']: + + if action == 2: + location = room['foyer'].s_to + next_step() + + elif action == 3: + location = room['foyer'].e_to + next_step() + + elif action == 1: + location = room['foyer'].n_to + next_step() + + elif location == room['overlook']: + if action == 2: + location = room['overlook'].s_to + next_step() + + elif location == room['narrow']: + if action == 4: + location = room['narrow'].w_to + next_step() + elif action == 1: + location = room['narrow'].n_to + next_step() + + elif location == room['treasure']: + if action == 2: + location = room['treasure'].s_to + next_step() + + else: + wrong_way() + + # Write a loop that: # # * Prints the current room name diff --git a/src/player.py b/src/player.py index d79a175029..82f67ab5e3 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,10 @@ # 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): + return f"{self.name} is at {self.current_room}" diff --git a/src/room.py b/src/room.py index 24c07ad4c8..3422d98d4f 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,10 @@ # 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 + + def __str__(self): + return f"you find yourself at {self.name}, {self.description}" From 06c81b2310da272ae35000c2dd09f0f4f5d0a791 Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 03:33:14 -0500 Subject: [PATCH 3/7] progress --- src/adv.py | 36 ++++++++++++++++++++++++++++-------- src/item.py | 7 +++++++ src/room.py | 6 +++++- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 12444de06c..8b924bb1aa 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,25 +1,40 @@ +import random from player import Player from room import Room +from item import Item # Declare all the rooms +item = { + 'sword': Item('sword', 'a worn down blade'), + + 'ruby': Item('ruby', 'a gem that inspires greed and fortune, worth gold'), + + 'dung': Item('dung', 'a pile of dung, not sure why you would want to pick it up'), + + 'empty': Item('nothing', 'there are no items here') +} + +print(random.choice(list(item.values()))) + + room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + "North of you, the cave mount beckons", item['empty']), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), +passages run north and east.""", item['dung']), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm."""), +the distance, but there is no way across the chasm.""", item['sword']), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), +to north. The smell of gold permeates the air.""", item['dung']), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south."""), +earlier adventurers. The only exit is to the south.""", item['dung']), } print(room['outside']) @@ -82,6 +97,8 @@ def wrong_way(): if action == 1: location = room['outside'].n_to next_step() + else: + wrong_way() elif location == room['foyer']: @@ -96,11 +113,15 @@ def wrong_way(): elif action == 1: location = room['foyer'].n_to next_step() + else: + wrong_way() elif location == room['overlook']: if action == 2: location = room['overlook'].s_to next_step() + else: + wrong_way() elif location == room['narrow']: if action == 4: @@ -109,15 +130,14 @@ def wrong_way(): elif action == 1: location = room['narrow'].n_to next_step() + else: + wrong_way() elif location == room['treasure']: if action == 2: location = room['treasure'].s_to next_step() - else: - wrong_way() - # Write a loop that: # diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..341d488880 --- /dev/null +++ b/src/item.py @@ -0,0 +1,7 @@ +class Item: + def __init__(self, item_name, description): + self.item_name = item_name + self.description = description + + def __str__(self): + return f'{self.item_name}, {self.description}' diff --git a/src/room.py b/src/room.py index 3422d98d4f..e2c4c840e7 100644 --- a/src/room.py +++ b/src/room.py @@ -1,10 +1,14 @@ # Implement a class to hold room information. This should have name and # description attributes. +from item import Item + + class Room: - def __init__(self, name, description): + def __init__(self, name, description, items): self.name = name self.description = description + self.items = items def __str__(self): return f"you find yourself at {self.name}, {self.description}" From 73ab16496ba9e551ad28ce20ed45ef2dd183871a Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 03:33:14 -0500 Subject: [PATCH 4/7] progress --- src/adv.py | 36 ++++++++++++++++++++++++++++-------- src/item.py | 7 +++++++ src/room.py | 6 +++++- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 12444de06c..8b924bb1aa 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,25 +1,40 @@ +import random from player import Player from room import Room +from item import Item # Declare all the rooms +item = { + 'sword': Item('sword', 'a worn down blade'), + + 'ruby': Item('ruby', 'a gem that inspires greed and fortune, worth gold'), + + 'dung': Item('dung', 'a pile of dung, not sure why you would want to pick it up'), + + 'empty': Item('nothing', 'there are no items here') +} + +print(random.choice(list(item.values()))) + + room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + "North of you, the cave mount beckons", item['empty']), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), +passages run north and east.""", item['dung']), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm."""), +the distance, but there is no way across the chasm.""", item['sword']), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), +to north. The smell of gold permeates the air.""", item['dung']), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south."""), +earlier adventurers. The only exit is to the south.""", item['dung']), } print(room['outside']) @@ -82,6 +97,8 @@ def wrong_way(): if action == 1: location = room['outside'].n_to next_step() + else: + wrong_way() elif location == room['foyer']: @@ -96,11 +113,15 @@ def wrong_way(): elif action == 1: location = room['foyer'].n_to next_step() + else: + wrong_way() elif location == room['overlook']: if action == 2: location = room['overlook'].s_to next_step() + else: + wrong_way() elif location == room['narrow']: if action == 4: @@ -109,15 +130,14 @@ def wrong_way(): elif action == 1: location = room['narrow'].n_to next_step() + else: + wrong_way() elif location == room['treasure']: if action == 2: location = room['treasure'].s_to next_step() - else: - wrong_way() - # Write a loop that: # diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..341d488880 --- /dev/null +++ b/src/item.py @@ -0,0 +1,7 @@ +class Item: + def __init__(self, item_name, description): + self.item_name = item_name + self.description = description + + def __str__(self): + return f'{self.item_name}, {self.description}' diff --git a/src/room.py b/src/room.py index 3422d98d4f..e2c4c840e7 100644 --- a/src/room.py +++ b/src/room.py @@ -1,10 +1,14 @@ # Implement a class to hold room information. This should have name and # description attributes. +from item import Item + + class Room: - def __init__(self, name, description): + def __init__(self, name, description, items): self.name = name self.description = description + self.items = items def __str__(self): return f"you find yourself at {self.name}, {self.description}" From 8e66960635f7a021fd2ee50d4446293f8c7453ab Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 03:44:15 -0500 Subject: [PATCH 5/7] test --- src/adv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 8b924bb1aa..b56b734ce8 100644 --- a/src/adv.py +++ b/src/adv.py @@ -15,26 +15,26 @@ 'empty': Item('nothing', 'there are no items here') } -print(random.choice(list(item.values()))) +random_item = random.choice(list(item.values())) room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", item['empty']), + "North of you, the cave mount beckons", random_item), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty passages run north and east.""", item['dung']), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm.""", item['sword']), +the distance, but there is no way across the chasm.""", random_item), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air.""", item['dung']), +to north. The smell of gold permeates the air.""", random_item), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south.""", item['dung']), +earlier adventurers. The only exit is to the south.""", random_item), } print(room['outside']) From 7e86d04bc73335d6c6ca3b632ee80e8e90761f2a Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Sun, 5 Jul 2020 22:47:52 -0500 Subject: [PATCH 6/7] mvp --- src/adv.py | 129 ++++++++++++++++++++++++++++++++++++++++++++------ src/item.py | 2 +- src/player.py | 15 +++++- src/room.py | 7 +-- 4 files changed, 134 insertions(+), 19 deletions(-) diff --git a/src/adv.py b/src/adv.py index b56b734ce8..5699188fc9 100644 --- a/src/adv.py +++ b/src/adv.py @@ -6,35 +6,37 @@ # Declare all the rooms item = { - 'sword': Item('sword', 'a worn down blade'), + 'sword': Item('sword', 'a used sword, a worn down blade that has seen many battles'), - 'ruby': Item('ruby', 'a gem that inspires greed and fortune, worth gold'), + 'ruby': Item('ruby', 'a ruby that inspires greed and fortune, looks to be worth plenty of gold'), - 'dung': Item('dung', 'a pile of dung, not sure why you would want to pick it up'), + 'dung': Item('dung', 'a pile of dung, not sure why you would want to pick this up yet your curiosity beckons'), - 'empty': Item('nothing', 'there are no items here') + 'torch': Item('torch', 'a torch, looks to still have some life left in it') } -random_item = random.choice(list(item.values())) + +def generate_item(): + return random.choice(list(item.values())) room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", random_item), + "North of you, the cave mount beckons", generate_item()), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east.""", item['dung']), +passages run north and east""", generate_item()), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm.""", random_item), +the distance, but there is no way across the chasm""", generate_item()), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air.""", random_item), +to north. The smell of gold permeates the air""", generate_item()), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south.""", random_item), +earlier adventurers. The only exit is to the south""", generate_item()), } print(room['outside']) @@ -64,24 +66,43 @@ location = room['outside'] -player = Player(player_name, location) +inventory = [] + +player = Player(player_name, location, inventory) print(f"you are {player_name}, the gay barbarian {location}") -print("where would you like to go next?") +print("what would you like to do next?") def choose_action(): - return int(input("[1] north [2] south [3] east [4] west [9] Quit\n")) + return int(input("[1] go north [2] go south [3] go east [4] go west [5] pick up item [6] open inventory [9] Quit\n")) action = choose_action() +inventory_action = 0 + + +def open_inventory(): + print('inventory: ') + player.open_inventory() + global action + action = int( + input("[1] go north [2] go south [3] go east [4] go west [7] drop item [9] Quit\n")) + + +def drop(item, current_room): + for i in range(0, len(player.items)): + if item == player.items[i].item_name: + global room + room[current_room].items = player.items[i] + def next_step(): print(location) - print('where would you like to go next?') + print('what would you like to do next?') global action action = choose_action() @@ -97,6 +118,23 @@ def wrong_way(): if action == 1: location = room['outside'].n_to next_step() + elif action == 5: + print('you picked up a {x}'.format( + x=room['outside'].items.item_name)) + + player.pickup_item(room['outside'].items) + room['outside'].items = 'nothing of interest' + action = choose_action() + elif action == 6: + open_inventory() + + elif action == 7: + discard = input('what item would you like to drop?') + drop(discard, 'outside') + player.drop_item(discard) + print(f'you dropped a {discard} into the room') + action = choose_action() + else: wrong_way() @@ -113,6 +151,22 @@ def wrong_way(): elif action == 1: location = room['foyer'].n_to next_step() + + elif action == 5: + print('you picked up a {x}'.format( + x=room['foyer'].items.item_name)) + player.pickup_item(room['foyer'].items) + room['foyer'].items = 'nothing of interest' + action = choose_action() + + elif action == 6: + open_inventory() + + elif action == 7: + discard = input('what item would you like to drop?') + player.drop_item(discard) + action = choose_action() + else: wrong_way() @@ -120,6 +174,22 @@ def wrong_way(): if action == 2: location = room['overlook'].s_to next_step() + + elif action == 5: + print('you picked up a {x}'.format( + x=room['overlook'].items.item_name)) + player.pickup_item(room['overlook'].items) + room['overlook'].items = 'nothing of interest' + action = choose_action() + + elif action == 6: + open_inventory() + + elif action == 7: + discard = input('what item would you like to drop?') + player.drop_item(discard) + action = choose_action() + else: wrong_way() @@ -130,6 +200,22 @@ def wrong_way(): elif action == 1: location = room['narrow'].n_to next_step() + + elif action == 5: + print('you picked up a {x}'.format( + x=room['foyer'].items.item_name)) + player.pickup_item(room['narrow'].items) + room['narrow'].items = 'nothing of interest' + action = choose_action() + + elif action == 6: + open_inventory() + + elif action == 7: + discard = input('what item would you like to drop?') + player.drop_item(discard) + action = choose_action() + else: wrong_way() @@ -137,6 +223,21 @@ def wrong_way(): if action == 2: location = room['treasure'].s_to next_step() + elif action == 7: + discard = input('what item would you like to drop?') + player.drop_item(discard) + action = choose_action() + elif action == 5: + print('you picked up a {x}'.format( + x=room['treasure'].items.item_name)) + player.pickup_item(room['treasure'].items) + room['treasure'].items = 'nothing of interest' + action = choose_action() + + elif action == 6: + open_inventory() + else: + wrong_way() # Write a loop that: diff --git a/src/item.py b/src/item.py index 341d488880..3eb35bef8a 100644 --- a/src/item.py +++ b/src/item.py @@ -4,4 +4,4 @@ def __init__(self, item_name, description): self.description = description def __str__(self): - return f'{self.item_name}, {self.description}' + return f'{self.item_name},{self.description}' diff --git a/src/player.py b/src/player.py index 82f67ab5e3..d11cf2fd6f 100644 --- a/src/player.py +++ b/src/player.py @@ -2,9 +2,22 @@ # currently. class Player: - def __init__(self, name, current_room): + def __init__(self, name, current_room, items): self.name = name self.current_room = current_room + self.items = items + + def pickup_item(self, item): + self.items.append(item) + + def drop_item(self, item): + for i in range(0, len(self.items)): + if self.items[i].item_name == item: + self.items.remove(self.items[i]) + + def open_inventory(self): + for i in self.items: + print(i) def __str__(self): return f"{self.name} is at {self.current_room}" diff --git a/src/room.py b/src/room.py index e2c4c840e7..450b590aa7 100644 --- a/src/room.py +++ b/src/room.py @@ -1,8 +1,6 @@ # Implement a class to hold room information. This should have name and # description attributes. -from item import Item - class Room: def __init__(self, name, description, items): @@ -10,5 +8,8 @@ def __init__(self, name, description, items): self.description = description self.items = items + def addItem(self, i): + self.items.append(i) + def __str__(self): - return f"you find yourself at {self.name}, {self.description}" + return f"you find yourself at the {self.name}, {self.description}, in it lies {self.items}" From d2619497684f16d094ac92bfde83a3624cf80d71 Mon Sep 17 00:00:00 2001 From: Shun Chiang Date: Mon, 6 Jul 2020 22:47:37 -0500 Subject: [PATCH 7/7] finished --- src/adv.py | 66 ++++++++++++++++++++++++++------------------------- src/player.py | 12 ++++++---- src/room.py | 25 ++++++++++++++++--- 3 files changed, 63 insertions(+), 40 deletions(-) diff --git a/src/adv.py b/src/adv.py index 5699188fc9..5dc85e28d5 100644 --- a/src/adv.py +++ b/src/adv.py @@ -22,25 +22,23 @@ def generate_item(): room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", generate_item()), + "North of you, the cave mount beckons", [generate_item(), generate_item()]), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east""", generate_item()), +passages run north and east""", [generate_item()]), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm""", generate_item()), +the distance, but there is no way across the chasm""", [generate_item()]), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air""", generate_item()), +to north. The smell of gold permeates the air""", [generate_item()]), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south""", generate_item()), +earlier adventurers. The only exit is to the south""", [generate_item()]), } -print(room['outside']) - # Link rooms together @@ -60,7 +58,7 @@ def generate_item(): # Make a new player object that is currently in the 'outside' room. -print('welcome to gay adventureland 3.0!') +print('welcome to adventureland 3.0!') player_name = input("what is your name?: ") @@ -71,7 +69,7 @@ def generate_item(): player = Player(player_name, location, inventory) -print(f"you are {player_name}, the gay barbarian {location}") +print(f"you are {player_name}, the barbarian {location}") print("what would you like to do next?") @@ -97,7 +95,7 @@ def drop(item, current_room): for i in range(0, len(player.items)): if item == player.items[i].item_name: global room - room[current_room].items = player.items[i] + room[current_room].items.append(player.items[i]) def next_step(): @@ -119,11 +117,12 @@ def wrong_way(): location = room['outside'].n_to next_step() elif action == 5: - print('you picked up a {x}'.format( - x=room['outside'].items.item_name)) + pickup = input('what item would you like to pick up?') + + player.pickup_item(room['outside'].items, pickup) + print(f'picked up {pickup}') + room['outside'].remove_item(pickup) - player.pickup_item(room['outside'].items) - room['outside'].items = 'nothing of interest' action = choose_action() elif action == 6: open_inventory() @@ -153,10 +152,11 @@ def wrong_way(): next_step() elif action == 5: - print('you picked up a {x}'.format( - x=room['foyer'].items.item_name)) - player.pickup_item(room['foyer'].items) - room['foyer'].items = 'nothing of interest' + pickup = input('what item would you like to pick up?') + + player.pickup_item(room['foyer'].items, pickup) + print(f'picked up {pickup}') + room['foyer'].remove_item(pickup) action = choose_action() elif action == 6: @@ -176,10 +176,12 @@ def wrong_way(): next_step() elif action == 5: - print('you picked up a {x}'.format( - x=room['overlook'].items.item_name)) - player.pickup_item(room['overlook'].items) - room['overlook'].items = 'nothing of interest' + pickup = input('what item would you like to pick up?') + + player.pickup_item(room['overlook'].items, pickup) + print(f'picked up {pickup}') + room['overlook'].remove_item(pickup) + action = choose_action() elif action == 6: @@ -202,11 +204,11 @@ def wrong_way(): next_step() elif action == 5: - print('you picked up a {x}'.format( - x=room['foyer'].items.item_name)) - player.pickup_item(room['narrow'].items) - room['narrow'].items = 'nothing of interest' - action = choose_action() + pickup = input('what item would you like to pick up?') + + player.pickup_item(room['narrow'].items, pickup) + print(f'picked up {pickup}') + room['narrow'].remove_item(pickup) elif action == 6: open_inventory() @@ -228,11 +230,11 @@ def wrong_way(): player.drop_item(discard) action = choose_action() elif action == 5: - print('you picked up a {x}'.format( - x=room['treasure'].items.item_name)) - player.pickup_item(room['treasure'].items) - room['treasure'].items = 'nothing of interest' - action = choose_action() + pickup = input('what item would you like to pick up?') + + player.pickup_item(room['treasure'].items, pickup) + print(f'picked up {pickup}') + room['treasure'].remove_item(pickup) elif action == 6: open_inventory() diff --git a/src/player.py b/src/player.py index d11cf2fd6f..7e43fbf20f 100644 --- a/src/player.py +++ b/src/player.py @@ -7,13 +7,15 @@ def __init__(self, name, current_room, items): self.current_room = current_room self.items = items - def pickup_item(self, item): - self.items.append(item) + def pickup_item(self, item_list, item): + for i in range(0, len(item_list)): + if item_list[i].item_name == item: + self.items.append(item_list[i]) def drop_item(self, item): - for i in range(0, len(self.items)): - if self.items[i].item_name == item: - self.items.remove(self.items[i]) + for i in self.items: + if i.item_name == item: + self.items.remove(i) def open_inventory(self): for i in self.items: diff --git a/src/room.py b/src/room.py index 450b590aa7..922721ea70 100644 --- a/src/room.py +++ b/src/room.py @@ -8,8 +8,27 @@ def __init__(self, name, description, items): self.description = description self.items = items - def addItem(self, i): + def add_item(self, i): self.items.append(i) - def __str__(self): - return f"you find yourself at the {self.name}, {self.description}, in it lies {self.items}" + def remove_item(self, item): + if len(self.items) > 1: + for i in range(0, len(self.items)): + if self.items[i].item_name == item: + self.items.remove(self.items[i]) + break + else: + for i in range(0, len(self.items)): + if self.items[i].item_name == item: + self.items.remove(self.items[i]) + + def __repr__(self): + def all_items(): + new_list = [] + if len(self.items) > 0: + for i in range(len(self.items)): + new_list.append(self.items[i].description) + return ', and also '.join(new_list) + else: + return 'nothing of interest' + return f"you find yourself at the {self.name}, {self.description}, in it lies {all_items()}"