From fd9e03fc66a8e8680856e43fe4b241c3d8643521 Mon Sep 17 00:00:00 2001 From: Sean McDonnell Date: Fri, 6 Dec 2019 09:44:59 -0500 Subject: [PATCH] Add item drop functionality and inventory check to meet MVP --- src/adv.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index ff19531340..e38022b8ee 100644 --- a/src/adv.py +++ b/src/adv.py @@ -191,13 +191,20 @@ def print_items_message(room): print( 'Path does not exists. Try another direction.\n' ) + elif player_input == 'i' or player_input == 'inventory': + if len(current_player.items): + print( + f'You currently have:{nl}{nl.join(str(x.name) for x in current_player.items)}{nl}' + ) + else: + print('You don\'t have anything!') elif player_input == 'q': print( f'Goodbye {current_player.get_name()}, we hope you\'ll play again!') break else: print( - 'Invalid command: Navigate using "n", "s", "e", or "w", or press "q" to quit' + 'Invalid command: Navigate using "n", "s", "e", or "w", or check your inventory with "i", or press "q" to quit' ) else: split_input = player_input.split() @@ -205,14 +212,24 @@ def print_items_message(room): if split_input[0] == 'take' or split_input[0] == 'drop': if split_input[0] == 'take': if room_has_items(current_player.get_location()): - current_player.items.append(item[split_input[1]]) + current_player.items.append( + item[split_input[1].lower()]) current_player.location.items.remove( - item[split_input[1]] + item[split_input[1].lower()] ) - print(f'You got: {current_player.items[0].name}!{nl}') + print( + f'You got: {current_player.items[len(current_player.items) - 1].name}!{nl}' + ) else: - print('Item does not exist!') + current_player.items.remove(item[split_input[1]]) + current_player.location.items.append( + item[split_input[1]] + ) + + print( + f'You dropped: {current_player.location.items[len(current_player.items) - 1].name}!{nl}' + ) else: print( 'Invalid command: use either "take" or "drop" to interact with items'