From 76ac6dc186504bdea3e61c2fe59c63ec54b638cf Mon Sep 17 00:00:00 2001 From: MurphDirt879 Date: Wed, 6 May 2020 19:55:45 -0400 Subject: [PATCH 1/4] Finished with day one. --- src/adv.py | 23 ++++++++++++++++++++--- src/player.py | 13 +++++++++++++ src/room.py | 14 +++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..f66e6633b8 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."""), @@ -38,14 +39,30 @@ # # Make a new player object that is currently in the 'outside' room. +new_player = Player(player_name = "Ryan", current_room = room["outside"]) + + +print("\nWelcome player! You may enter a direction in which to travel with n, s, e, w, and q to quit the game.\n") +print(f"{new_player.player_name} is {new_player.current_room} \n") # Write a loop that: -# +while True: # * 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. -# + selection = input("Enter a direction or Q to escape: ") + if selection == "q": + print("Have a good day. Thanks for playing.") + break + elif selection == "n" or selection == "s" or selection == "e" or selection == "w": + new_player.move(selection) + print(f"\n{new_player.player_name} is {new_player.current_room.room_name} \n{new_player.current_room.description}\n\n") + else: + print("That is not a proper command.") # 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. diff --git a/src/player.py b/src/player.py index d79a175029..995762fe3e 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,15 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + +class Player(): + def __init__(self, player_name, current_room): + self.player_name = player_name + self.current_room = current_room + + + def move(self, direction): + if getattr(self.current_room, f"{direction}_to") is not None: + self.current_room = getattr(self.current_room, f"{direction}_to") + else: + print("There is no room in that Direction!") diff --git a/src/room.py b/src/room.py index 24c07ad4c8..a995d53860 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,14 @@ # 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, room_name, description): + self.room_name = room_name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + + def __str__(self): + return f' {self.room_name}, {self.description}' \ No newline at end of file From 559dd1509a5f2dafd9b572818765024a62e42d8a Mon Sep 17 00:00:00 2001 From: MurphDirt879 Date: Thu, 7 May 2020 16:40:53 -0400 Subject: [PATCH 2/4] MVP --- .DS_Store | Bin 0 -> 6148 bytes src/adv.py | 68 +++++++++++++++++++++++++++++++++++++++----------- src/item.py | 10 ++++++++ src/player.py | 25 +++++++++++++++++++ src/room.py | 12 ++++++++- 5 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 .DS_Store create mode 100644 src/item.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2a605f938d2ce560a46e49976f9e3a16d09af485 GIT binary patch literal 6148 zcmeHKO>Wab6n@i$)(Jvnfz-mv8zdG1#R6I+RLO)CsSBin5i9_ub{rZb*N$w503pa5 z?tlar;4B<~gKz-&-pqjV#||M{&6D1I&+~pf^JP4fAtKQpg$_}Jh%6{$wT@C~e@QYF2_Oqw_bl?|*K--VfH2!V- z!Q-eu?lvymO_Rcpl71$Wqp**VXHTLeOvmkXl!Upg<0*$_)vQ{#acMHS>fCairtRF^ zo;K~t&Q7ao-?+X#oz|?)%g*lp;qjZdlXuhipX6jnVC#}{UgIzL3}cC!S6-IHX>tS~ z=dIH{x8psQI+nb^73;eURU8Ix(dI_?7R8W^PSTCTA3Htiz8&CwhpnO$DvAIxj zgANcsM3sm)-ud^74-3&XdPsX1ZHMjySBzMEU&yFn92xcI>&oTuab`K_sMEU$^aK}v zdT@2ZMK65o>vgaBd-9!D!Qe>=D!S_V{3FZmI~p4 z2$c#{sX|{dgi1%ht>avcr9zcXLSH_FezVXw6d~V^`nC)w;VLw(VZbmj&p<^zHu(JC z`}6&OKFK^81`GqIiUCpWc%3$;q|er+$?;ihLl2=W99JroDQNU@EDb)2x1dtsv)KT; V8cT)fftWu6k_OWl2L34nKLNq!=HdVV literal 0 HcmV?d00001 diff --git a/src/adv.py b/src/adv.py index f66e6633b8..7c08592856 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,6 +1,6 @@ from room import Room from player import Player - +from item import Item # Declare all the rooms room = { @@ -30,20 +30,30 @@ 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['overlook'].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. -new_player = Player(player_name = "Ryan", current_room = room["outside"]) +items = { + "sword": Item("Sword", "This is used to stab things."), + "lantern": Item("Lantern", "This would be helpful in the dark."), + "shovel": Item("Shovel", "This could be used to bludgen or dig.") + -print("\nWelcome player! You may enter a direction in which to travel with n, s, e, w, and q to quit the game.\n") +} + +room['outside'].items.append(items["lantern"]) +room['overlook'].items.append(items["sword"]) +room['narrow'].items.append(items["shovel"]) + +# Make a new player object that is currently in the 'outside' room. +new_player = Player(player_name = "Ryan", current_room = room["outside"]) +print("\nWelcome player! You may enter a direction in which to travel with n, s, e, w, and q to quit the game.\n\nYou may get, take, pickup items, or drop them.\n\n") print(f"{new_player.player_name} is {new_player.current_room} \n") +print(new_player.current_room.list_items()) # Write a loop that: while True: @@ -52,15 +62,43 @@ # * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. - selection = input("Enter a direction or Q to escape: ") - if selection == "q": - print("Have a good day. Thanks for playing.") - break - elif selection == "n" or selection == "s" or selection == "e" or selection == "w": - new_player.move(selection) - print(f"\n{new_player.player_name} is {new_player.current_room.room_name} \n{new_player.current_room.description}\n\n") - else: + selection = input("Enter a direction, command or Q to escape: ") + user_selection = selection.lower().split(" ") + if len(user_selection) == 1: + if selection == "q": + print("Have a good day. Thanks for playing.") + break + elif selection == "n" or selection == "s" or selection == "e" or selection == "w": + new_player.move(selection) + print(f"\n{new_player.player_name} is {new_player.current_room.room_name} \n{new_player.current_room.description}\n\n {new_player.current_room.list_items()}") + elif selection == "i": + new_player.print_items() + else: + print("That is not a proper command.") + elif len(user_selection) == 2: + if user_selection[0] in ["take", "get", "pickup"]: + if items[user_selection[1]]: + new_player.pickup_item(items[user_selection[1]]) + print("\n\nYou have added a new item to inventory!\n") + print(new_player.print_items()) + print(f"{new_player.player_name} is {new_player.current_room} \n") + print(new_player.current_room.list_items()) + else: + print("That isn't an item.") + elif user_selection[0] == "drop": + if items[user_selection[1]]: + new_player.drop_item(items[user_selection[1]]) + print("You dropped an item!") + print(new_player.print_items()) + print(f"{new_player.player_name} is {new_player.current_room} \n") + print(new_player.current_room.list_items()) + else: + print("That isn't an item.") + else: + print("That is not a proper command.") + else: print("That is not a proper command.") + # If the user enters a cardinal direction, attempt to move to the room there. # Print an error message if the movement isn't allowed. diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..e9ae702467 --- /dev/null +++ b/src/item.py @@ -0,0 +1,10 @@ +class Item(): + def __init__(self, name, description): + self.name = name + self.description = description + + def pick_up(self): + print(f"{self.name} was picked up.") + + def drop(self): + print(f"{self.name} was dropped.") \ No newline at end of file diff --git a/src/player.py b/src/player.py index 995762fe3e..34ae9f208b 100644 --- a/src/player.py +++ b/src/player.py @@ -6,6 +6,7 @@ class Player(): def __init__(self, player_name, current_room): self.player_name = player_name self.current_room = current_room + self.items = [] def move(self, direction): @@ -13,3 +14,27 @@ def move(self, direction): self.current_room = getattr(self.current_room, f"{direction}_to") else: print("There is no room in that Direction!") + + def pickup_item(self, item): + if self.current_room.items.count(item) > 0: + self.items.append(item) + self.current_room.items.remove(item) + item.pick_up + else: + print(f"A {item.name} is not in this room.") + + def drop_item(self, item): + if self.items.count(item) > 0: + self.current_room.items.append(item) + self.items.remove(item) + item.drop + else: + print(f"You do not have a {item.name} to drop.") + + def print_items(self): + if not self.items: + print("You have no items.") + else: + print("You have the following items: ") + for x in self.items: + print(x.name) \ No newline at end of file diff --git a/src/room.py b/src/room.py index a995d53860..d0ccd98b52 100644 --- a/src/room.py +++ b/src/room.py @@ -9,6 +9,16 @@ def __init__(self, room_name, description): self.s_to = None self.e_to = None self.w_to = None + self.items = [] def __str__(self): - return f' {self.room_name}, {self.description}' \ No newline at end of file + return f' {self.room_name}, {self.description}' + + + def list_items(self): + if not self.items: + print("This room has no items.") + else: + print("This room has: ") + for item in self.items: + print(item.name) \ No newline at end of file From c8e3e8e81dce3c93770f6fb1a358087eeba7504e Mon Sep 17 00:00:00 2001 From: MurphDirt879 Date: Thu, 7 May 2020 17:04:37 -0400 Subject: [PATCH 3/4] bug fixed --- src/adv.py | 2 +- src/player.py | 4 ++-- src/room.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/adv.py b/src/adv.py index 7c08592856..dbeac532dd 100644 --- a/src/adv.py +++ b/src/adv.py @@ -79,8 +79,8 @@ if user_selection[0] in ["take", "get", "pickup"]: if items[user_selection[1]]: new_player.pickup_item(items[user_selection[1]]) + print("\n\nYou have added a new item to inventory!\n") - print(new_player.print_items()) print(f"{new_player.player_name} is {new_player.current_room} \n") print(new_player.current_room.list_items()) else: diff --git a/src/player.py b/src/player.py index 34ae9f208b..07ed880e35 100644 --- a/src/player.py +++ b/src/player.py @@ -19,7 +19,7 @@ def pickup_item(self, item): if self.current_room.items.count(item) > 0: self.items.append(item) self.current_room.items.remove(item) - item.pick_up + item.pick_up() else: print(f"A {item.name} is not in this room.") @@ -27,7 +27,7 @@ def drop_item(self, item): if self.items.count(item) > 0: self.current_room.items.append(item) self.items.remove(item) - item.drop + item.drop() else: print(f"You do not have a {item.name} to drop.") diff --git a/src/room.py b/src/room.py index d0ccd98b52..a188c83969 100644 --- a/src/room.py +++ b/src/room.py @@ -21,4 +21,5 @@ def list_items(self): else: print("This room has: ") for item in self.items: - print(item.name) \ No newline at end of file + print(item.name) + print(item.description) \ No newline at end of file From 2546cecc10d86533130c9fc1ca452cca1c84681d Mon Sep 17 00:00:00 2001 From: MurphDirt879 Date: Thu, 7 May 2020 19:40:25 -0400 Subject: [PATCH 4/4] fix --- src/adv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index dbeac532dd..6633b88227 100644 --- a/src/adv.py +++ b/src/adv.py @@ -2,7 +2,7 @@ from player import Player from item import Item # Declare all the rooms - +#Update for Branch room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons ..."),