From 4c17ed13122ec39aa8ee9f212327aaf985bc51ca Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 10:20:32 -0700 Subject: [PATCH 01/18] create classes with to str methods --- src/adv.py | 7 +++++++ src/player.py | 7 +++++++ src/room.py | 11 ++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..7025b0cfc4 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,9 @@ from room import Room +from player import Player + +def exit(message: str): + print(message) + exit(0) # Declare all the rooms @@ -33,6 +38,8 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +for k,v in room: + print(k, v) # # Main # diff --git a/src/player.py b/src/player.py index d79a175029..9ac8b69290 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,9 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Player: + def __init__(self, location): + self.location = location + + def __str__(self): + return str(self.__dict__) \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..9767789c18 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,11 @@ # 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: str, description: str): + self.name = name + self.description = description + + def __str__(self): + return str(self.__dict__) \ No newline at end of file From 69a8eacd2c2108589b37f818542416a1e796ed32 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 10:38:57 -0700 Subject: [PATCH 02/18] add type annotations --- src/adv.py | 5 +---- src/player.py | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 7025b0cfc4..173d6aaa48 100644 --- a/src/adv.py +++ b/src/adv.py @@ -6,7 +6,6 @@ def exit(message: str): exit(0) # Declare all the rooms - room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -28,7 +27,6 @@ def exit(message: str): # Link rooms together - room['outside'].n_to = room['foyer'] room['foyer'].s_to = room['outside'] room['foyer'].n_to = room['overlook'] @@ -38,8 +36,7 @@ def exit(message: str): room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -for k,v in room: - print(k, v) +player = Player(name="Mike", location=room['outside']) # # Main # diff --git a/src/player.py b/src/player.py index 9ac8b69290..c21ef0d3e4 100644 --- a/src/player.py +++ b/src/player.py @@ -1,8 +1,10 @@ # Write a class to hold player information, e.g. what room they are in # currently. +from room import Room class Player: - def __init__(self, location): + def __init__(self, name: str, location: Room): + self.name = name self.location = location def __str__(self): From 007f536f6ac2817a0eaeed0a130c6e53ff6d6fb4 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 11:30:34 -0700 Subject: [PATCH 03/18] using Sean's code as baseline which is much cleaner, also created item class --- src/adv.py | 70 ++++++++++++++++++++++++++++++++++++++++----------- src/item.py | 0 src/player.py | 20 +++++++++++---- src/room.py | 10 +++++--- 4 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 173d6aaa48..643e010e4c 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,11 +1,9 @@ +import textwrap from room import Room from player import Player -def exit(message: str): - print(message) - exit(0) - # Declare all the rooms + room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -27,6 +25,7 @@ def exit(message: str): # Link rooms together + room['outside'].n_to = room['foyer'] room['foyer'].s_to = room['outside'] room['foyer'].n_to = room['overlook'] @@ -36,20 +35,63 @@ def exit(message: str): room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -player = Player(name="Mike", location=room['outside']) # # Main # # Make a new player object that is currently in the 'outside' room. +player = Player("Sean", room['outside']) + +done = False + +# helper function to skip input we don't understand +def skip_input(): + print("I don't understand that\n") + +def print_help_text(): + print(""" + Valid commands: + -[n]: move north + -[s]: move south + -[e]: move east + -[w]: move west + -[q]: quit + -[help]: help text + """) # 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. +while not done: + # + # * Prints the current room name + print(player.location) + # * Prints the current description (the textwrap module might be useful here). + for line in textwrap.wrap(player.location.print_description()): + print(line) + print("\n") + # * Waits for user input and decides what to do. + + command = input("What do you want to do? ") + + # check that the command is properly formatted + if len(command) > 2 or len(command) < 1: + skip_input() + continue + + if command in ['n', 's', 'e', 'w']: + player.location = player.move_to(command, player.location) + continue + # + # 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. + if command in ['q', 'quit', 'exit']: + done = True + + if command in ['?', 'help']: + print_help_text() + continue + + else: + skip_input() + continue \ No newline at end of file diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/player.py b/src/player.py index c21ef0d3e4..c33e433920 100644 --- a/src/player.py +++ b/src/player.py @@ -1,11 +1,21 @@ # Write a class to hold player information, e.g. what room they are in # currently. -from room import Room class Player: - def __init__(self, name: str, location: Room): - self.name = name + def __init__(self, name, location): + self.name = name self.location = location - def __str__(self): - return str(self.__dict__) \ No newline at end of file + def move_to(self, direction, current_loc): + # try to move in the specified direction + attribute = direction + '_to' + + # if we can move in specified direction from our current location + if hasattr(current_loc, attribute): + # get the room in the specified + return getattr(current_loc, attribute) + + # if we can't go that way + print("You can't go that way\n") + + return current_loc \ No newline at end of file diff --git a/src/room.py b/src/room.py index 9767789c18..87307db2a2 100644 --- a/src/room.py +++ b/src/room.py @@ -2,10 +2,12 @@ # description attributes. class Room: - - def __init__(self, name: str, description: str): + def __init__(self, name, subtext): self.name = name - self.description = description + self.subtext = subtext def __str__(self): - return str(self.__dict__) \ No newline at end of file + return f"{self.name}" + + def print_description(self): + return f"{self.subtext}" \ No newline at end of file From d6b25d9d7704cbba1439c48cc62176ee739335f2 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 11:37:00 -0700 Subject: [PATCH 04/18] include additional resources --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 182debf5ff..2c4f8a6ddf 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ Up to this point, you've gotten your feet wet by working on a bunch of small Pyt ## What We're Building [What's an Adventure Game? ![vid](https://tk-assets.lambdaschool.com/7928cdb4-b8a3-45a6-b231-5b9d1fc1e002_ScreenShot2019-03-22at5.47.28PM.png)](https://youtu.be/WaZccFqJUT8) +## Examples + +* Dunnet, one of the first mass distributed text based games included in every version of the emacs editor +(emacs is no longer included by default with MacOS Catalina+) +[link](https://ifdb.tads.org/viewgame?id=ig3zbeoqfv4v1xl8) +* Links to 5 text based adventure games that can be played in browser ## Goals From 446bba990f89aa1010bbf7342b0f445012f29e4c Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 13:13:07 -0700 Subject: [PATCH 05/18] finish items init --- src/item.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/item.py b/src/item.py index e69de29bb2..6547e92d4d 100644 --- a/src/item.py +++ b/src/item.py @@ -0,0 +1,6 @@ +# this is currently identical to Room, decide if its worth + +class Item: + def __init__(self, name: str, description: str): + self.name = name + self.description = description \ No newline at end of file From c9cb13869df5532ef166e85bed6396b423f97486 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 14:38:58 -0700 Subject: [PATCH 06/18] add inventory to room --- src/.vs/ProjectSettings.json | 3 +++ src/.vs/VSWorkspaceState.json | 6 ++++++ src/.vs/slnx.sqlite | Bin 0 -> 90112 bytes src/.vs/src/v16/.suo | Bin 0 -> 19456 bytes src/adv.py | 2 +- src/room.py | 8 +++++--- 6 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/.vs/ProjectSettings.json create mode 100644 src/.vs/VSWorkspaceState.json create mode 100644 src/.vs/slnx.sqlite create mode 100644 src/.vs/src/v16/.suo diff --git a/src/.vs/ProjectSettings.json b/src/.vs/ProjectSettings.json new file mode 100644 index 0000000000..f8b4888565 --- /dev/null +++ b/src/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/src/.vs/VSWorkspaceState.json b/src/.vs/VSWorkspaceState.json new file mode 100644 index 0000000000..6b6114114f --- /dev/null +++ b/src/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/src/.vs/slnx.sqlite b/src/.vs/slnx.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..3eccc50ba6e41724ee346439e2dfa2e3429ff3e9 GIT binary patch literal 90112 zcmeI5Ym6JmeZY6QB=^XB%sJATJzQ+9Wd}M|+B?1kvDGR19@dF?VEZ1iZ+rDth$P0v~u@WRG^6Z3Vwl8tm6Qtqt60wwwKCr(M(Dwr^}U zTR5-O^5cY1wwTM5b3(qbk$XYdJ60amdA~r8?ZT*hRao7#7h4S;EzR?REK&2)cr^>s zJ|3^!!W8Aqlv7lqf>j~Ay|qQ_TG-BJO1a=`&(84yQDol``%=AyomF>!p4XKrXD)8# z#?*Y?zp8N=ftXjSgl{=_DOVJBiutRV;&tIl?z)hvl(+K*lI_)8p-i+Q|COz+3wka) z-OjD1g1gq#hKwdc8=;un%oTHmY_25i87Xq@ezQNQt_}l87C|!!X}8MG1_ePdWHTE% zThvBwD`!R-%4h%!*D}TI*M_)LT3;~DVV8G!g8x4OVmG$ zotGz9z!1uIT8I1XQMq}4@MwLO57dZX)l|PyHI=1y8+Wskd=uA3RoA@CDL7~MGH3L} zd@MfaOhasMwDfB5PQ|Z!-0M}<2{n?A**49cH_HNV05F8q>5isKa83CGNe!W>Mh5T-1c;zu-brj;LK zBr>rL%)UyWgg!#XQuw)TjBo}9gN83z3ny^X#-_rct|RNJ%%nzF~{u-T!p49~| z9yVKwO{#bHX<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3;+4*|IR&9|)O}a8c^n#^8D7f-uQ}seD$mdrd^Ug3~0lo3KUqZwi~m?W-fD znx0F>BijY@qo$?#nQFeXHbyzqJdcGiZ~B=xY?x_{G5 ztJTlZlvH}hl*tzgWET1ynRkwmppu&z+4Uf&MRM12e7|)-f@kliOdA_(~`Z9v`1RHN_)h~ zdQ3Bqp{nL3R=;4G#&v?r?0wF>jlr_DcE&WvcGWiowQAgJCFNc-Df2QgeH?#+VU2#V zDd%3WFC3Mn?hV`@cNLnjQj_hp>DTKVBL$r}L>?il4pG~xgE~Ac;sz$2fsAXzchnw? zg-6pihS8@dIm=LDd{$%KWtfJv*6_Wi0GTjE7N;q_fe&z7k=p$!N}rmp^w_MXD(y&B z4ZgmD_&_wuzG+!4v6CLdba9fq51EYh`C;s+;~rxcYpkCbZZpom#{0dIV!ES!>?KPl z&rh}|GOKfvCBPwW-9Sy<9_~cMrWYL$R)t~rGNJSM6nmTD%9DLvN?&t=%@1RJz|yri zH!UX4)L`=iHa||Z(s7?dFk@fii?{hfpZ|yZ{~!252NVbdfB+Bx0zd!=00AHX1b_e# z00KbZff9iE{{zJhg#iH|00e*l5C8%|00;m9AOHk_01$X61nB+$u>b#1&_kg>00;m9 zAOHk_01yBIKmZ5;0U!Vb9vA`G|9@bpp&%dt1b_e#00KY&2mk>f00e*l5C8%Xjlll{ DrnGDm literal 0 HcmV?d00001 diff --git a/src/.vs/src/v16/.suo b/src/.vs/src/v16/.suo new file mode 100644 index 0000000000000000000000000000000000000000..4c1b76eadca291f125f145e37a6900c673f2a906 GIT binary patch literal 19456 zcmeI2&vO(-6vul7R0Mw@ii)TaBchTB5fM-@kbs~`fe8f5+Dm>cVabL~?FI}NOZ@{p zc<}DclU1HPdGTmjf>jn?Jm3-k2Z^6=&-Cu>WM_AF5+J)yZ@rzKp4a{Qy?)*O`t`eh zZPU$ff7trB38lkkjk&$J-rOH3&yc^*y+3BmTJkEpy|}oj;xz!-G_{cgMof|4yy-H> z%q5;Bb5%nbJ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QQ1THb7NcD)TblmDv#2j}6ax&pfQ zPU6Yqv@^y@Uh7H5O*@FEd#GNFl(7+PF%TnA+&L!VbJJqk&pJ_gyXjfhZJl8&_>YSjxyN53)`R;af z*D=vwPLk~;@FD@(c)g68eZ-^Hi)W!sf9n*T^|4Rrv=RLERNflrf_0R?`$>M^VYIG* zr1RE>(LJgxnK|D!x(LQ0Vk33x)h%>w(%ps5uU2dc2IJ#vy8TR^?zR2j?)GzX$*+!@ zLBF=kr~d!?{(t9V>7-}a`=e7>oVZt~y=nZ1=l^Ua{vhaoyw~v`jp#dTWYB8FxEu1C zXD|Lo#fT~HOY@@UW5i34|8U%c7iV*xy>yyAR6bW1{ZhX%?%y+tKXY@kK2~k%FstTce-pnHX~^@ilImBPL7@S^@* z{JE@)xb%baU+Vvt#MAr#R`361$HkTZYP$aqkAH&rAAA4PO8mnL$NyC3eq8xC(*HF6 zM`um>+}i8@Pd00k@o#kh)+YCVE$hFIneP6t5&w51{*$gOJ89fqT6SXz8gR7rOi+E< zRhC0v`&I(CL#5BsBh|0AG1p)D7$c+mw`$!O6;>E!C1^WaF4(o@lm**~o7Xu047A&= z+)}@7JKkA^xtKIp*g@r4|E&YYWEOiszV(vjs1wGgjAz`tA#KMwyf2{6!mNfoD5u&R->L`u>(0%r5juZ2uB3!(O l+hg5(8vn6c;`wUFDQtnW>BdTF{6{P?MIxo~AMG9g@gFM4-bw%f literal 0 HcmV?d00001 diff --git a/src/adv.py b/src/adv.py index 643e010e4c..946f10fd2a 100644 --- a/src/adv.py +++ b/src/adv.py @@ -6,7 +6,7 @@ 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."""), diff --git a/src/room.py b/src/room.py index 87307db2a2..8ddb616042 100644 --- a/src/room.py +++ b/src/room.py @@ -1,11 +1,13 @@ # Implement a class to hold room information. This should have name and # description attributes. +from typing import List +from item import Item class Room: - def __init__(self, name, subtext): + def __init__(self, name: str, description: str, inventory: List[Item] = []): self.name = name - self.subtext = subtext - + self.description = description + self.inventory = inventory def __str__(self): return f"{self.name}" From e828c0b3ef423c6776a6ceac390c669f8bdc9658 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 15:17:39 -0700 Subject: [PATCH 07/18] refactor commands into lists instead of hard code --- src/adv.py | 19 ++++++++++++------- src/inventory_holder.py | 1 + src/room.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/inventory_holder.py diff --git a/src/adv.py b/src/adv.py index 946f10fd2a..2446b86238 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,6 +1,7 @@ import textwrap from room import Room from player import Player +import sys # Declare all the rooms @@ -23,7 +24,11 @@ earlier adventurers. The only exit is to the south."""), } +direction_commands = ['n', 's', 'e', 'w'] +exit_commands = ['q', 'quit', 'exit'] +help_commands = ['?', 'help'] +valid_commands = direction_commands + exit_commands + help_commands # Link rooms together room['outside'].n_to = room['foyer'] @@ -61,7 +66,6 @@ def print_help_text(): # Write a loop that: while not done: - # # * Prints the current room name print(player.location) # * Prints the current description (the textwrap module might be useful here). @@ -69,15 +73,14 @@ def print_help_text(): print(line) print("\n") # * Waits for user input and decides what to do. - command = input("What do you want to do? ") # check that the command is properly formatted - if len(command) > 2 or len(command) < 1: + if command not in valid_commands: skip_input() continue - if command in ['n', 's', 'e', 'w']: + if command in direction_commands: player.location = player.move_to(command, player.location) continue # @@ -85,13 +88,15 @@ def print_help_text(): # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. - if command in ['q', 'quit', 'exit']: + if command in exit_commands: done = True + print("Exiting game!") + sys.exit(0) - if command in ['?', 'help']: + if command in help_commands: print_help_text() continue else: skip_input() - continue \ No newline at end of file + continue diff --git a/src/inventory_holder.py b/src/inventory_holder.py new file mode 100644 index 0000000000..2d915bdbe5 --- /dev/null +++ b/src/inventory_holder.py @@ -0,0 +1 @@ +class Inventory_Holder \ No newline at end of file diff --git a/src/room.py b/src/room.py index 8ddb616042..304a1ad113 100644 --- a/src/room.py +++ b/src/room.py @@ -12,4 +12,4 @@ def __str__(self): return f"{self.name}" def print_description(self): - return f"{self.subtext}" \ No newline at end of file + return f"{self.description}" \ No newline at end of file From 65cb080773e7fbe481152f228296b05b0b924241 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 15:19:19 -0700 Subject: [PATCH 08/18] print help text if put in invalid command --- src/adv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index 2446b86238..1cfee52878 100644 --- a/src/adv.py +++ b/src/adv.py @@ -49,7 +49,7 @@ done = False -# helper function to skip input we don't understand +# helper function to skip invalid inputs def skip_input(): print("I don't understand that\n") @@ -78,6 +78,7 @@ def print_help_text(): # check that the command is properly formatted if command not in valid_commands: skip_input() + print_help_text() continue if command in direction_commands: From ec2c90a9c40e3c0d3f7f0b4856247173ff8b46c7 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 15:53:32 -0700 Subject: [PATCH 09/18] add item commands to valid --- src/adv.py | 24 ++++++++++++------------ src/inventory_holder.py | 23 ++++++++++++++++++++++- src/player.py | 6 ++++-- src/room.py | 3 ++- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/adv.py b/src/adv.py index 1cfee52878..5bc202093e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -3,8 +3,14 @@ from player import Player import sys -# Declare all the rooms +# create all valid user inputs +direction_commands = ['n', 's', 'e', 'w'] +exit_commands = ['q', 'quit', 'exit'] +help_commands = ['?', 'help'] +item_commands = ['get', 'drop', 'i'] +valid_commands = direction_commands + exit_commands + help_commands + item_commands +# Declare all the rooms room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -24,11 +30,6 @@ earlier adventurers. The only exit is to the south."""), } -direction_commands = ['n', 's', 'e', 'w'] -exit_commands = ['q', 'quit', 'exit'] -help_commands = ['?', 'help'] - -valid_commands = direction_commands + exit_commands + help_commands # Link rooms together room['outside'].n_to = room['foyer'] @@ -40,18 +41,14 @@ 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("Sean", room['outside']) +player = Player("Mike", room['outside']) done = False # helper function to skip invalid inputs def skip_input(): - print("I don't understand that\n") + print("I don't understand that!\n") def print_help_text(): print(""" @@ -85,6 +82,9 @@ def print_help_text(): player.location = player.move_to(command, player.location) continue # + if command == 'i': + player.show_inventory() + # 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/inventory_holder.py b/src/inventory_holder.py index 2d915bdbe5..a471a25fd2 100644 --- a/src/inventory_holder.py +++ b/src/inventory_holder.py @@ -1 +1,22 @@ -class Inventory_Holder \ No newline at end of file +from typing import List +from item import Item + +class Inventory_Holder: + def __init__(self, name:str, inventory: List[Item] = []): + self.name = name + self.inventory = inventory + + def show_inventory(self): + for item in self.inventory: + print(item) + + def item_transfer(self, item: Item, target: Inventory_Holder): + self.inventory.remove(item) + print("{item.name} has been removed from {self.name}'s inventory") + target.inventory.append(item) + print("{item.name} has been added to {self.name}'s inventory") + + # spawn item in inventory + def item_spawn(self, item: Item): + self.inventory.append(item) + print("{item.name} has been spawned and added to {self.name}'s inventory") \ No newline at end of file diff --git a/src/player.py b/src/player.py index c33e433920..1633f87452 100644 --- a/src/player.py +++ b/src/player.py @@ -1,10 +1,12 @@ # Write a class to hold player information, e.g. what room they are in # currently. +from inventory_holder import Inventory_Holder -class Player: +class Player(Inventory_Holder): def __init__(self, name, location): self.name = name self.location = location + self.inventory = inventory def move_to(self, direction, current_loc): # try to move in the specified direction @@ -18,4 +20,4 @@ def move_to(self, direction, current_loc): # if we can't go that way print("You can't go that way\n") - return current_loc \ No newline at end of file + return current_loc diff --git a/src/room.py b/src/room.py index 304a1ad113..a342aecfbd 100644 --- a/src/room.py +++ b/src/room.py @@ -2,8 +2,9 @@ # description attributes. from typing import List from item import Item +from inventory_holder import Inventory_Holder -class Room: +class Room(Inventory_Holder): def __init__(self, name: str, description: str, inventory: List[Item] = []): self.name = name self.description = description From 3de32c1f19dc780faa7edbf84820d1b876cddefd Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 15:54:53 -0700 Subject: [PATCH 10/18] fixed player not having inventory --- src/player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player.py b/src/player.py index 1633f87452..9112a4f832 100644 --- a/src/player.py +++ b/src/player.py @@ -3,7 +3,7 @@ from inventory_holder import Inventory_Holder class Player(Inventory_Holder): - def __init__(self, name, location): + def __init__(self, name, location, inventory): self.name = name self.location = location self.inventory = inventory From ff1d8c08c9a34d675d4c106098b55a8ac12950ae Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 18:25:52 -0700 Subject: [PATCH 11/18] initialized some items, added an extra room --- src/adv.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/adv.py b/src/adv.py index 5bc202093e..7f2fb647d3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,6 +1,7 @@ import textwrap from room import Room from player import Player +from item import Item import sys # create all valid user inputs @@ -28,6 +29,19 @@ '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."""), + + 'graveyard': Room("Graveyard", """ A dark mist prevents you from seeing more + than a few feet in front of you. The floor is littered with tiny bones."""), +} + +# Declare all items + +item = { + 'ring': Item("Ring", "This old rusty ring has what looks to be a dragon wrestling a lion."), + + 'box': Item("Blossom", "An immaculately preserved flower from another age."), + + 'fang': Item("Fang", "A massive tooth from an unknown predator." ), } # Link rooms together From 7bbb6309d8366f67602218d5b5e78a239dc3e52c Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 18:30:26 -0700 Subject: [PATCH 12/18] link new rooms with attribute --- src/adv.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index 7f2fb647d3..4531b62487 100644 --- a/src/adv.py +++ b/src/adv.py @@ -30,8 +30,11 @@ chamber! Sadly, it has already been completely emptied by earlier adventurers. The only exit is to the south."""), - 'graveyard': Room("Graveyard", """ A dark mist prevents you from seeing more + 'graveyard': Room("Graveyard", """A dark mist prevents you from seeing more than a few feet in front of you. The floor is littered with tiny bones."""), + + 'lava': Room("Lava", """A room filled with lava that will be harmful to + the player when the developers find time to make it so soon(TM)""") } # Declare all items @@ -54,6 +57,11 @@ room['narrow'].w_to = room['foyer'] room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +room['graveyard'].e_to = room['foyer'] +room['foyer'].w_to = room['graveyard'] +room['lava'].e_to = room['graveyard'] +room['graveyard'].w_to = room['lava'] + # Make a new player object that is currently in the 'outside' room. player = Player("Mike", room['outside']) From 47edf3607ada87409a46710df315fd2bda6e6cf9 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 18:40:24 -0700 Subject: [PATCH 13/18] transfer item to use conventions: self, other . . . like normal OOP --- src/inventory_holder.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/inventory_holder.py b/src/inventory_holder.py index a471a25fd2..e5d9dcd712 100644 --- a/src/inventory_holder.py +++ b/src/inventory_holder.py @@ -1,4 +1,8 @@ -from typing import List +# this class be be defined as a generic class +# for doing type annotations + + +from typing import List, Generic from item import Item class Inventory_Holder: @@ -7,13 +11,14 @@ def __init__(self, name:str, inventory: List[Item] = []): self.inventory = inventory def show_inventory(self): + print("This is what's in the inventory: \n") for item in self.inventory: print(item) - def item_transfer(self, item: Item, target: Inventory_Holder): + def item_transfer(self, item: Item, other): self.inventory.remove(item) print("{item.name} has been removed from {self.name}'s inventory") - target.inventory.append(item) + other.inventory.append(item) print("{item.name} has been added to {self.name}'s inventory") # spawn item in inventory From 133382ca68c8297588e7103e760dab0dc0747749 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 21:54:54 -0700 Subject: [PATCH 14/18] initialize Player (replace with call to super later) --- src/player.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/player.py b/src/player.py index 9112a4f832..39b14c25df 100644 --- a/src/player.py +++ b/src/player.py @@ -1,9 +1,12 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +from typing import List, Generic +from item import Item from inventory_holder import Inventory_Holder class Player(Inventory_Holder): - def __init__(self, name, location, inventory): + def __init__(self, name, location, inventory: List[Item]=[]): self.name = name self.location = location self.inventory = inventory From 6c399d0bd58cf603cad29425bd2fb1e5b7b451c7 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Thu, 7 May 2020 22:44:36 -0700 Subject: [PATCH 15/18] temp remove super class, need to redesign --- src/adv.py | 18 +++++++++++++++--- src/inventory_holder.py | 3 ++- src/player.py | 16 ++++++++++++++++ src/room.py | 19 ++++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 4531b62487..3eab8745d6 100644 --- a/src/adv.py +++ b/src/adv.py @@ -3,6 +3,8 @@ from player import Player from item import Item import sys +import random +import os # create all valid user inputs direction_commands = ['n', 's', 'e', 'w'] @@ -83,7 +85,16 @@ def print_help_text(): -[help]: help text """) -# Write a loop that: +# puts one copy of each item into a random room +# re-write later to take arguments if bored +def seed_items(): + for i in item: + random_room = random.sample(room, 1) + room[random_room].spawn_item(i) + + + +# Write a loop that runs the game until quit command while not done: # * Prints the current room name print(player.location) @@ -100,12 +111,13 @@ def print_help_text(): print_help_text() continue - if command in direction_commands: + elif command in direction_commands: player.location = player.move_to(command, player.location) continue # - if command == 'i': + elif command == 'i': player.show_inventory() + continue # 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/inventory_holder.py b/src/inventory_holder.py index e5d9dcd712..9f402bd2af 100644 --- a/src/inventory_holder.py +++ b/src/inventory_holder.py @@ -6,8 +6,9 @@ from item import Item class Inventory_Holder: - def __init__(self, name:str, inventory: List[Item] = []): + def __init__(self, name:str, location, inventory: List[Item] = []): self.name = name + self.location = location self.inventory = inventory def show_inventory(self): diff --git a/src/player.py b/src/player.py index 39b14c25df..eec4381c37 100644 --- a/src/player.py +++ b/src/player.py @@ -11,6 +11,22 @@ def __init__(self, name, location, inventory: List[Item]=[]): self.location = location self.inventory = inventory + def show_inventory(self): + print("This is what's in our inventory: \n") + for item in self.inventory: + print(item) + + def item_transfer(self, item: Item, other): + self.inventory.remove(item) + print("{item.name} has been removed from {self.name}'s inventory") + other.inventory.append(item) + print("{item.name} has been added to {self.name}'s inventory") + + # spawn item in inventory + def item_spawn(self, item: Item): + self.inventory.append(item) + print("{item.name} has been spawned and added to {self.name}'s inventory") + def move_to(self, direction, current_loc): # try to move in the specified direction attribute = direction + '_to' diff --git a/src/room.py b/src/room.py index a342aecfbd..62e19f1623 100644 --- a/src/room.py +++ b/src/room.py @@ -1,14 +1,31 @@ # Implement a class to hold room information. This should have name and # description attributes. + from typing import List from item import Item from inventory_holder import Inventory_Holder -class Room(Inventory_Holder): +class Room: def __init__(self, name: str, description: str, inventory: List[Item] = []): self.name = name self.description = description self.inventory = inventory + + def show_inventory(self): + print("This is what's in our inventory: \n") + for item in self.inventory: + print(item) + + def item_transfer(self, item: Item, other): + self.inventory.remove(item) + print("{item.name} has been removed from {self.name}'s inventory") + other.inventory.append(item) + print("{item.name} has been added to {self.name}'s inventory") + + # spawn item in inventory + def item_spawn(self, item: Item): + self.inventory.append(item) + print("{item.name} has been spawned and added to {self.name}'s inventory") def __str__(self): return f"{self.name}" From cde076d6cb4a4d1b93bb287789fe9965a0c936c0 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Fri, 8 May 2020 02:56:02 -0700 Subject: [PATCH 16/18] get all and drop all kind of work but are buggy, not sure why --- src/adv.py | 44 ++++++++++++++++++++++++++++++-------------- src/item.py | 5 ++++- src/player.py | 8 ++++---- src/room.py | 13 +++++++------ 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/adv.py b/src/adv.py index 3eab8745d6..5c22058a20 100644 --- a/src/adv.py +++ b/src/adv.py @@ -10,7 +10,7 @@ direction_commands = ['n', 's', 'e', 'w'] exit_commands = ['q', 'quit', 'exit'] help_commands = ['?', 'help'] -item_commands = ['get', 'drop', 'i'] +item_commands = ['get', 'drop', 'inv'] valid_commands = direction_commands + exit_commands + help_commands + item_commands # Declare all the rooms @@ -64,9 +64,10 @@ room['lava'].e_to = room['graveyard'] room['graveyard'].w_to = room['lava'] - # Make a new player object that is currently in the 'outside' room. player = Player("Mike", room['outside']) +test_item = Item("Talisman", "A worn silver pendant believed to guard travelers on dangerous journeys.") +player.item_spawn(test_item) done = False @@ -88,20 +89,24 @@ def print_help_text(): # puts one copy of each item into a random room # re-write later to take arguments if bored def seed_items(): - for i in item: - random_room = random.sample(room, 1) - room[random_room].spawn_item(i) - - + print("SEEDING ITEMS IN WORLD \n") + for key in room: + # print(key) + #import ipdb; ipdb.set_trace() + room[key].item_spawn(random.choice(list(item.values()))) + print("\n") +print("STARTING GAME \n") +seed_items() # Write a loop that runs the game until quit command while not done: # * Prints the current room name - print(player.location) + print("You are currently at", player.location.name) # * Prints the current description (the textwrap module might be useful here). for line in textwrap.wrap(player.location.print_description()): print(line) print("\n") + # print(player.location.show_inventory()) # * Waits for user input and decides what to do. command = input("What do you want to do? ") @@ -115,20 +120,31 @@ def seed_items(): player.location = player.move_to(command, player.location) continue # - elif command == 'i': - player.show_inventory() - continue - + elif command in ['inv']: + print("SHOWING INVENTORY") + player.show_inventory() + continue + # these are hacky and the entire thing should be done with arg parse :( + # this just loots all + elif command in ['get']: + for item in player.location.inventory: + player.location.item_transfer(item, player) + continue + # and this just drops all + elif command in ['drop']: + for item in player.inventory: + player.item_transfer(item, player.location) + continue # 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. - if command in exit_commands: + elif command in exit_commands: done = True print("Exiting game!") sys.exit(0) - if command in help_commands: + elif command in help_commands: print_help_text() continue diff --git a/src/item.py b/src/item.py index 6547e92d4d..5a1f95c637 100644 --- a/src/item.py +++ b/src/item.py @@ -3,4 +3,7 @@ class Item: def __init__(self, name: str, description: str): self.name = name - self.description = description \ No newline at end of file + self.description = description + # variables are public so don't need getters + # def get_name(self): + # return self.name \ No newline at end of file diff --git a/src/player.py b/src/player.py index eec4381c37..758710282e 100644 --- a/src/player.py +++ b/src/player.py @@ -5,7 +5,7 @@ from item import Item from inventory_holder import Inventory_Holder -class Player(Inventory_Holder): +class Player: def __init__(self, name, location, inventory: List[Item]=[]): self.name = name self.location = location @@ -14,13 +14,13 @@ def __init__(self, name, location, inventory: List[Item]=[]): def show_inventory(self): print("This is what's in our inventory: \n") for item in self.inventory: - print(item) + print(item.name) def item_transfer(self, item: Item, other): self.inventory.remove(item) - print("{item.name} has been removed from {self.name}'s inventory") + print(f"{item.name} has been removed from {self.name}'s inventory") other.inventory.append(item) - print("{item.name} has been added to {self.name}'s inventory") + print(f"{item.name} has been added to {other.name}'s inventory") # spawn item in inventory def item_spawn(self, item: Item): diff --git a/src/room.py b/src/room.py index 62e19f1623..cfb191ed2d 100644 --- a/src/room.py +++ b/src/room.py @@ -13,21 +13,22 @@ def __init__(self, name: str, description: str, inventory: List[Item] = []): def show_inventory(self): print("This is what's in our inventory: \n") + # this is how to check for empty list in Python + for item in self.inventory: print(item) def item_transfer(self, item: Item, other): self.inventory.remove(item) - print("{item.name} has been removed from {self.name}'s inventory") + print(f"{item.name} has been removed from {self.name}'s inventory") other.inventory.append(item) - print("{item.name} has been added to {self.name}'s inventory") + print(f"{item.name} has been added to {other.name}'s inventory") # spawn item in inventory def item_spawn(self, item: Item): self.inventory.append(item) - print("{item.name} has been spawned and added to {self.name}'s inventory") - def __str__(self): - return f"{self.name}" - + # print(f"{item.name} has been spawned and added to {self.name}'s inventory") + print(item.name, "has been spawned to", self.name, "and added to their inventory") + def print_description(self): return f"{self.description}" \ No newline at end of file From 8b5ce8c17386384250b02bd32aca6dd0e1243462 Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Mon, 11 May 2020 09:50:51 -0700 Subject: [PATCH 17/18] fixed double printing bug --- src/adv.py | 4 ++-- src/item.py | 3 ++- src/player.py | 15 ++++++++++++--- src/room.py | 9 ++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/adv.py b/src/adv.py index 5c22058a20..cd2f2cf90c 100644 --- a/src/adv.py +++ b/src/adv.py @@ -128,12 +128,12 @@ def seed_items(): # this just loots all elif command in ['get']: for item in player.location.inventory: - player.location.item_transfer(item, player) + player.item_take(item) continue # and this just drops all elif command in ['drop']: for item in player.inventory: - player.item_transfer(item, player.location) + player.item_give(item) continue # 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 index 5a1f95c637..6d87c6bd20 100644 --- a/src/item.py +++ b/src/item.py @@ -6,4 +6,5 @@ def __init__(self, name: str, description: str): self.description = description # variables are public so don't need getters # def get_name(self): - # return self.name \ No newline at end of file + # return self.name + # import ipdb; ipdb.set_trace() \ No newline at end of file diff --git a/src/player.py b/src/player.py index 758710282e..bc034f9bca 100644 --- a/src/player.py +++ b/src/player.py @@ -3,6 +3,7 @@ from typing import List, Generic from item import Item +from room import Room from inventory_holder import Inventory_Holder class Player: @@ -16,11 +17,19 @@ def show_inventory(self): for item in self.inventory: print(item.name) - def item_transfer(self, item: Item, other): + def item_take(self, item: Item): + self.inventory.append(item) + print(f"{item.name} has been removed from {self.location.name}'s inventory") + self.location.remove_item(item) + print(f"{item.name} has been added to {self.name}'s inventory") + + def item_give(self, item: Item): self.inventory.remove(item) print(f"{item.name} has been removed from {self.name}'s inventory") - other.inventory.append(item) - print(f"{item.name} has been added to {other.name}'s inventory") + self.location.inventory.append(item) + print(f"{item.name} has been added to {self.location.name}'s inventory") + + # spawn item in inventory def item_spawn(self, item: Item): diff --git a/src/room.py b/src/room.py index cfb191ed2d..a397e98e38 100644 --- a/src/room.py +++ b/src/room.py @@ -18,11 +18,10 @@ def show_inventory(self): for item in self.inventory: print(item) - def item_transfer(self, item: Item, other): - self.inventory.remove(item) - print(f"{item.name} has been removed from {self.name}'s inventory") - other.inventory.append(item) - print(f"{item.name} has been added to {other.name}'s inventory") + def remove_item(self, inventory): + for i in self.inventory: + if inventory.name == i.name: + self.inventory.remove(i) # spawn item in inventory def item_spawn(self, item: Item): From 5f0061afea932f3f98e16fc6a38017af53269b3d Mon Sep 17 00:00:00 2001 From: Mike-Xie Date: Tue, 12 May 2020 11:07:11 -0700 Subject: [PATCH 18/18] self.inventory = [] fixes extra item spawns for some reason --- src/adv.py | 15 +++++++++------ src/inventory_holder.py | 28 ---------------------------- src/player.py | 2 +- src/room.py | 4 ++-- 4 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 src/inventory_holder.py diff --git a/src/adv.py b/src/adv.py index cd2f2cf90c..282d40f880 100644 --- a/src/adv.py +++ b/src/adv.py @@ -86,17 +86,20 @@ def print_help_text(): -[help]: help text """) -# puts one copy of each item into a random room -# re-write later to take arguments if bored +# for each room, adds a random item from item list to its inventory + +# instead, there's a bug where each subsequent room has 1 more item than the previous room def seed_items(): print("SEEDING ITEMS IN WORLD \n") for key in room: # print(key) - #import ipdb; ipdb.set_trace() - room[key].item_spawn(random.choice(list(item.values()))) - print("\n") -print("STARTING GAME \n") + # import ipdb; ipdb.set_trace() + room[key].item_spawn(test_item) + # room[key].show_inventory() + print(room[key].name, room[key].inventory) + seed_items() +import ipdb; ipdb.set_trace() # Write a loop that runs the game until quit command while not done: diff --git a/src/inventory_holder.py b/src/inventory_holder.py deleted file mode 100644 index 9f402bd2af..0000000000 --- a/src/inventory_holder.py +++ /dev/null @@ -1,28 +0,0 @@ -# this class be be defined as a generic class -# for doing type annotations - - -from typing import List, Generic -from item import Item - -class Inventory_Holder: - def __init__(self, name:str, location, inventory: List[Item] = []): - self.name = name - self.location = location - self.inventory = inventory - - def show_inventory(self): - print("This is what's in the inventory: \n") - for item in self.inventory: - print(item) - - def item_transfer(self, item: Item, other): - self.inventory.remove(item) - print("{item.name} has been removed from {self.name}'s inventory") - other.inventory.append(item) - print("{item.name} has been added to {self.name}'s inventory") - - # spawn item in inventory - def item_spawn(self, item: Item): - self.inventory.append(item) - print("{item.name} has been spawned and added to {self.name}'s inventory") \ No newline at end of file diff --git a/src/player.py b/src/player.py index bc034f9bca..235ab15a06 100644 --- a/src/player.py +++ b/src/player.py @@ -34,7 +34,7 @@ def item_give(self, item: Item): # spawn item in inventory def item_spawn(self, item: Item): self.inventory.append(item) - print("{item.name} has been spawned and added to {self.name}'s inventory") + print("{item.name} has been spawned and added to Player {self.name}'s inventory") def move_to(self, direction, current_loc): # try to move in the specified direction diff --git a/src/room.py b/src/room.py index a397e98e38..0a654a2261 100644 --- a/src/room.py +++ b/src/room.py @@ -3,13 +3,13 @@ from typing import List from item import Item -from inventory_holder import Inventory_Holder +# from inventory_holder import Inventory_Holder class Room: def __init__(self, name: str, description: str, inventory: List[Item] = []): self.name = name self.description = description - self.inventory = inventory + self.inventory = [] def show_inventory(self): print("This is what's in our inventory: \n")