From 4a3b17e0d12e5b01c6c9f2111ce6e27288ddc7f1 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Tue, 9 Jun 2020 14:50:15 -0400 Subject: [PATCH 1/6] Initial Commit --- src/player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player.py b/src/player.py index d79a175029..6dd049de73 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,2 @@ # Write a class to hold player information, e.g. what room they are in -# currently. +# currently. Change From c7e5e19f62eec26c817e9bf63a08375dd428bb58 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Tue, 9 Jun 2020 16:55:50 -0400 Subject: [PATCH 2/6] Built Player class with add_item method. Built Room class --- src/item.py | 1 + src/player.py | 19 +++++++++++++++++++ src/room.py | 19 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/item.py diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..7977b63b3e --- /dev/null +++ b/src/item.py @@ -0,0 +1 @@ +# Item base class should have name & description(single word). diff --git a/src/player.py b/src/player.py index 6dd049de73..0f8d80cc37 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,21 @@ # Write a class to hold player information, e.g. what room they are in # currently. Change + +class Player: + # attributes: name, current_room, items, + def __init__(self, name, current_room='outside'): + self.name = name + self.current_room = current_room + self.items = [] + + def __str__(self): + return f' The players name is {self.name}. \n They are currently in : {self.current_room} room. \n This player is in possesion of the following items {self.items}' + + def pick_up_item(self, item): + self.items.append(item) + + +Sam = Player('Sam') +Sam.pick_up_item('Gold') +Sam.pick_up_item('sword') +print(Sam) diff --git a/src/room.py b/src/room.py index 24c07ad4c8..bc4ce6f312 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,19 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room: + # Room contains: name, description, items_in_room. Methods: add_item + def __init__(self, name, description, items_in_room, n_to, s_to, e_to, w_to): + self.name = name + self.description = description + self.items_in_room = [] + self.n_to = n_to + self.s_to = s_to + self.e_to = e_to + self.w_to = w_to + + def __str__(self): + return f' Current room: {self.room} \n Description: {self.description} \n Items In Room: {self.items_in_room} \n ' + + +# room = Room() From 59c60e896cefaf6d462df856ea8935b04bda5465 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:54:05 -0400 Subject: [PATCH 3/6] Update --- src/adv.py | 51 ++++++++++++++++++++++++++++++++++++++++++--------- src/item.py | 5 +++++ src/player.py | 6 ------ src/room.py | 16 ++++++++-------- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..f652f9221f 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,8 +1,9 @@ from room import Room +from player import Player # Declare all the rooms -room = { +rooms = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -24,20 +25,24 @@ # Link rooms together -room['outside'].n_to = room['foyer'] -room['foyer'].s_to = room['outside'] -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['narrow'].n_to = room['treasure'] -room['treasure'].s_to = room['narrow'] +rooms['outside'].n_to = rooms['foyer'] +rooms['foyer'].s_to = rooms['outside'] +rooms['foyer'].n_to = rooms['overlook'] +rooms['foyer'].e_to = rooms['narrow'] +rooms['overlook'].s_to = rooms['foyer'] +rooms['narrow'].w_to = rooms['foyer'] +rooms['narrow'].n_to = rooms['treasure'] +rooms['treasure'].s_to = rooms['narrow'] + +# functionality for items in room + # # Main # # Make a new player object that is currently in the 'outside' room. +player = Player('Sam', 'outside') # Write a loop that: # @@ -49,3 +54,31 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +while True: + + print('Welcome to X Adventures!') + print('type q to quit') + + print() + print() + print('Current Location:', player.current_room) + + user_Input = input("Make a move: ") + + try: + if (user_Input == 'q'): + break + if (user_Input == 'n'): + pass + if (user_Input == 's'): + pass + if(user_Input == 'e'): + pass + if(user_Input == 'w'): + pass + else: + print("Not in Range") + + except ValueError: + print('TBD') diff --git a/src/item.py b/src/item.py index 7977b63b3e..644c1a8ee4 100644 --- a/src/item.py +++ b/src/item.py @@ -1 +1,6 @@ # Item base class should have name & description(single word). + +class Item: + def __init__(self, name, description): + self.name = name + self.description = description diff --git a/src/player.py b/src/player.py index 0f8d80cc37..6833cc4829 100644 --- a/src/player.py +++ b/src/player.py @@ -13,9 +13,3 @@ def __str__(self): def pick_up_item(self, item): self.items.append(item) - - -Sam = Player('Sam') -Sam.pick_up_item('Gold') -Sam.pick_up_item('sword') -print(Sam) diff --git a/src/room.py b/src/room.py index bc4ce6f312..7d0149578a 100644 --- a/src/room.py +++ b/src/room.py @@ -3,17 +3,17 @@ class Room: # Room contains: name, description, items_in_room. Methods: add_item - def __init__(self, name, description, items_in_room, n_to, s_to, e_to, w_to): + def __init__(self, name, description): self.name = name self.description = description self.items_in_room = [] - self.n_to = n_to - self.s_to = s_to - self.e_to = e_to - self.w_to = w_to + self.n_to = '' + self.s_to = '' + self.e_to = '' + self.w_to = '' def __str__(self): - return f' Current room: {self.room} \n Description: {self.description} \n Items In Room: {self.items_in_room} \n ' + return f' Current room: {self.name:s} \n Description: {self.description} \n Items In Room: {self.items_in_room} \n ' - -# room = Room() + def add_room_item(self, item): + self.items_in_room.append(item) From e1247429870ecb4ac7c2365703560f0a69d8d215 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:03:20 -0400 Subject: [PATCH 4/6] Commit --- src/adv.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index f652f9221f..5735969b77 100644 --- a/src/adv.py +++ b/src/adv.py @@ -34,13 +34,17 @@ rooms['narrow'].n_to = rooms['treasure'] rooms['treasure'].s_to = rooms['narrow'] -# functionality for items in room +def get_room_items(rooms): + for room in rooms: + print(rooms[room]) + # # Main # + # Make a new player object that is currently in the 'outside' room. player = Player('Sam', 'outside') From 586bd096a5141f20a31b00d4b65b5428b0c562c6 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Wed, 10 Jun 2020 13:05:46 -0400 Subject: [PATCH 5/6] Added moving functionality --- src/adv.py | 66 ++++++++++++++++++++------------------------------- src/player.py | 4 ++-- src/room.py | 2 +- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/adv.py b/src/adv.py index 5735969b77..06d6fcefba 100644 --- a/src/adv.py +++ b/src/adv.py @@ -3,7 +3,7 @@ # Declare all the rooms -rooms = { +room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -25,28 +25,22 @@ # Link rooms together -rooms['outside'].n_to = rooms['foyer'] -rooms['foyer'].s_to = rooms['outside'] -rooms['foyer'].n_to = rooms['overlook'] -rooms['foyer'].e_to = rooms['narrow'] -rooms['overlook'].s_to = rooms['foyer'] -rooms['narrow'].w_to = rooms['foyer'] -rooms['narrow'].n_to = rooms['treasure'] -rooms['treasure'].s_to = rooms['narrow'] - - - -def get_room_items(rooms): - for room in rooms: - print(rooms[room]) +room['outside'].n_to = room['foyer'] +room['foyer'].s_to = room['outside'] +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['narrow'].n_to = room['treasure'] +room['treasure'].s_to = room['narrow'] # # Main # - # Make a new player object that is currently in the 'outside' room. -player = Player('Sam', 'outside') +new_player = input('Give your player a name: ') +player = Player(new_player, room['outside']) # Write a loop that: # @@ -59,30 +53,22 @@ def get_room_items(rooms): # # If the user enters "q", quit the game. -while True: +command = '' - print('Welcome to X Adventures!') - print('type q to quit') - - print() - print() - print('Current Location:', player.current_room) - - user_Input = input("Make a move: ") - - try: - if (user_Input == 'q'): +while True: + print(player) + command = input( + ' \n \n Insert q to quit, \n Use n, s, e, w to move through out the map \n Make a move: ').split(" ") + # print('INSERTED COMMAND:', command) + + new_room = getattr(player.current_room, command[0].lower() + "_to", None) + if(len(command) == 1): + if new_room: + player.current_room = new_room + elif (command[0] == 'q'): break - if (user_Input == 'n'): - pass - if (user_Input == 's'): - pass - if(user_Input == 'e'): - pass - if(user_Input == 'w'): - pass else: - print("Not in Range") + print(' \n \n !!!INVALID COMMAND, PLEASE TRY AGAIN!!!') - except ValueError: - print('TBD') + elif(len(command == 2)): + pass diff --git a/src/player.py b/src/player.py index 6833cc4829..3bb5acdf91 100644 --- a/src/player.py +++ b/src/player.py @@ -3,13 +3,13 @@ class Player: # attributes: name, current_room, items, - def __init__(self, name, current_room='outside'): + def __init__(self, name, current_room): self.name = name self.current_room = current_room self.items = [] def __str__(self): - return f' The players name is {self.name}. \n They are currently in : {self.current_room} room. \n This player is in possesion of the following items {self.items}' + return f' \n \n Name: {self.name}. \n {self.current_room} \n Inventorty: {self.items}' def pick_up_item(self, item): self.items.append(item) diff --git a/src/room.py b/src/room.py index 7d0149578a..8a6f28ac5a 100644 --- a/src/room.py +++ b/src/room.py @@ -13,7 +13,7 @@ def __init__(self, name, description): self.w_to = '' def __str__(self): - return f' Current room: {self.name:s} \n Description: {self.description} \n Items In Room: {self.items_in_room} \n ' + return f'Location: {self.name} \n \n Hint: {self.description} \n Items in this locations: {self.items_in_room}.' def add_room_item(self, item): self.items_in_room.append(item) From 71dde2f39e4a5ab6d8c8cc351bc78cdb908652d0 Mon Sep 17 00:00:00 2001 From: Samuel Torres <42902403+Rilladubz@users.noreply.github.com> Date: Sat, 13 Jun 2020 19:39:25 -0400 Subject: [PATCH 6/6] MVP MET --- src/adv.py | 61 ++++++++++++++++++++++++++++++++++++--------------- src/item.py | 3 +++ src/player.py | 3 +++ src/room.py | 7 +++++- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/adv.py b/src/adv.py index 06d6fcefba..bc161de18c 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 @@ -22,6 +23,16 @@ earlier adventurers. The only exit is to the south."""), } +# key = Item('key', "Old Key") +# old_latern = Item( +# 'old latern', "A latern sits on an old table in the foyer, cobb webs hang off it. Doesn't seem like some one has been in here in a while") + +item = { + 'key': Item('key', "Old Key"), + 'latern': Item('latern', 'An old latern covered in dust & cob webs. The room illuminates as the item is picked up!'), + 'random': Item('random', 'iuhklciuyaghdsukfh') +} + # Link rooms together @@ -34,34 +45,28 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -# -# Main -# -# Make a new player object that is currently in the 'outside' room. +# PLAYER DECLARATION new_player = input('Give your player a name: ') player = Player(new_player, room['outside']) -# Write a loop that: -# -# * 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. -# -# 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. + +# Room Item Declarations +room['outside'].add_room_item(item['key']) +room['outside'].add_room_item(item['random']) +room['foyer'].add_room_item(item['latern']) command = '' + while True: print(player) command = input( - ' \n \n Insert q to quit, \n Use n, s, e, w to move through out the map \n Make a move: ').split(" ") - # print('INSERTED COMMAND:', command) + ' \n \n Insert q to quit, \n Use n, s, e, w to move through out the map \n To pick up an item type: grab, followed by the item name in sight! \n \n To drop an item type: drop, followed by the item in your inventory. \n Make a move: ').split(" ") new_room = getattr(player.current_room, command[0].lower() + "_to", None) + player_inventory = [item for item in player.items] + if(len(command) == 1): if new_room: player.current_room = new_room @@ -70,5 +75,25 @@ else: print(' \n \n !!!INVALID COMMAND, PLEASE TRY AGAIN!!!') - elif(len(command == 2)): - pass + elif(len(command) == 2 and command[0].lower() == 'grab'): + item_choice = command[1].lower() + item_name = [item.name + for item in player.current_room.items_in_room] + + if item_choice in item_name: + player.pick_up_item(item[item_choice].name) + player.current_room.remove_room_item(item[item_choice]) + print(f'\n \n You have picked up a {item_choice}!') + # print('ITEMS:', str(command[1].lower())) + else: + print( + f' \n \n Sorry but {item_choice} does not exist in {player.current_room}') + + elif(len(command) == 2 and command[0].lower() == 'drop'): + item_choice = command[1].lower() + if item_choice in player_inventory: + player.drop_item(item[item_choice].name) + player.current_room.add_room_item(item[item_choice]) + else: + print( + f' \n \n SORRY, BUT {item_choice} DOES NOT EXIST IN YOUR INVENTORY \n \n') diff --git a/src/item.py b/src/item.py index 644c1a8ee4..c217bc1c3a 100644 --- a/src/item.py +++ b/src/item.py @@ -4,3 +4,6 @@ class Item: def __init__(self, name, description): self.name = name self.description = description + + def __str__(self): + return f'Name: {self.name}, {self.description}' diff --git a/src/player.py b/src/player.py index 3bb5acdf91..678fdf9eeb 100644 --- a/src/player.py +++ b/src/player.py @@ -13,3 +13,6 @@ def __str__(self): def pick_up_item(self, item): self.items.append(item) + + def drop_item(self, item): + self.items.remove(item) diff --git a/src/room.py b/src/room.py index 8a6f28ac5a..30ce1994d2 100644 --- a/src/room.py +++ b/src/room.py @@ -13,7 +13,12 @@ def __init__(self, name, description): self.w_to = '' def __str__(self): - return f'Location: {self.name} \n \n Hint: {self.description} \n Items in this locations: {self.items_in_room}.' + item_names = [str(item.name) for item in self.items_in_room] + return f'Location: {self.name} \n Hint: {self.description} \n. Items in sight: {item_names}' def add_room_item(self, item): self.items_in_room.append(item) + + def remove_room_item(self, item): + self.items_in_room.remove(item) +