From ac6df7dfe12496c46f8077ffd361dc39cd1f73b4 Mon Sep 17 00:00:00 2001 From: Julio Escalera <27julioescalera27@gmail.com> Date: Tue, 8 Sep 2020 20:22:16 -0700 Subject: [PATCH 1/3] Day 1 MVP --- .idea/.gitignore | 3 ++ .idea/Intro-Python-II.iml | 11 +++++ .idea/inspectionProfiles/Project_Default.xml | 30 +++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ src/adv.py | 44 ++++++++++++++++--- src/player.py | 6 +++ src/room.py | 10 ++++- 10 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Intro-Python-II.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Intro-Python-II.iml b/.idea/Intro-Python-II.iml new file mode 100644 index 0000000000..8dc09e5476 --- /dev/null +++ b/.idea/Intro-Python-II.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000..d9edd77e40 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,30 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..105ce2da2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..a2e120dcc8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..b5c5fcd85b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..94a25f7f4c --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..9311d38167 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,5 @@ from room import Room +from player import Player # Declare all the rooms @@ -36,16 +37,45 @@ # # Main # - +username = input("Please put in your name: ") # Make a new player object that is currently in the 'outside' room. - +player = Player(username, room['outside']) # Write a loop that: -# -# * Prints the current room name + +while player.current_room: + # * Prints the current room name + print(f"Current room: {player.current_room.name}") # * Prints the current description (the textwrap module might be useful here). + print(f"{player.current_room.description}") + print("-------------------------------------------------------------------------") # * Waits for user input and decides what to do. -# + selection = input("Please pick a direction to go in (North = n, South = s, West = w, East = e): ") + print('-------------------------------------------------------------------------') # If the user enters a cardinal direction, attempt to move to the room there. + if selection == 'n': + if player.current_room.n_to is None: + print(f"There is nothing north of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.n_to + elif selection == 's': + if player.current_room.s_to is None: + print(f"There is nothing south of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.s_to + elif selection == 'w': + if player.current_room.w_to is None: + print(f"There is nothing west of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.w_to + elif selection == 'e': + if player.current_room.e_to is None: + print(f"\nThere is nothing east of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.e_to + elif selection == 'q': + print("Thank you for playing!") + player.current_room = False # Get out of game # Print an error message if the movement isn't allowed. -# -# If the user enters "q", quit the game. + else: + print(selection + " wasn't allowed. Please pick another valid direction.") +# If the user enters "q", quit the game. \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..868f7bbbfa 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,8 @@ # 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 + +7 \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..476b93ec4b 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, n_to=None, w_to=None, e_to=None, s_to=None): + self.n_to = n_to + self.w_to = w_to + self.e_to = e_to + self.s_to = s_to + self.name = name + self.description = description \ No newline at end of file From 6730b5e895e8c03542cc5cbb140d9710bb01731e Mon Sep 17 00:00:00 2001 From: Julio Escalera <27julioescalera27@gmail.com> Date: Tue, 8 Sep 2020 20:42:42 -0700 Subject: [PATCH 2/3] Updated MVP Day 1 --- src/player.py | 8 +++++++- src/room.py | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/player.py b/src/player.py index 868f7bbbfa..71c6a91fc8 100644 --- a/src/player.py +++ b/src/player.py @@ -5,4 +5,10 @@ def __init__(self, name, current_room): self.name = name self.current_room = current_room -7 \ No newline at end of file + def __str__(self): + return f"Name: {self.name}\nCurrent room: {self.current_room}" + + +if __name__ == "__main__": + a = Player("Bob", "Bob's Room") # __repr__ works + print(a) diff --git a/src/room.py b/src/room.py index 476b93ec4b..32bdb66bd1 100644 --- a/src/room.py +++ b/src/room.py @@ -7,4 +7,12 @@ def __init__(self, name, description, n_to=None, w_to=None, e_to=None, s_to=None self.e_to = e_to self.s_to = s_to self.name = name - self.description = description \ No newline at end of file + self.description = description + + def __str__(self): + return f"Name of room: {self.name}\nDescription: {self.description}\nNorth: {self.n_to}\nWest: {self.w_to}\n" \ + f"East: {self.e_to}\nSouth: {self.s_to}" + +if __name__ == "__main__": + a = Room("asdf", "asjd;kl;") # __str__ works + print(a) \ No newline at end of file From bef5cbe656c452f25ce46bbc88ee321444e5c838 Mon Sep 17 00:00:00 2001 From: Julio Escalera <27julioescalera27@gmail.com> Date: Thu, 10 Sep 2020 20:37:54 -0700 Subject: [PATCH 3/3] Incomplete MVP for Day 2 - Need to Add verb and item commands to parser --- src/adv.py | 51 +++++++++++++++++++++++++++++++++++---------------- src/item.py | 8 ++++++++ src/player.py | 11 ++++++++--- src/room.py | 28 +++++++++++++++++++++++++--- 4 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 9311d38167..b0dcf3cf7a 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,28 +1,31 @@ from room import Room from player import Player +from item import Item # Declare all the rooms +sword = Item("Sword", "Sharp and dangerous!") +gold = Item("Gold", "Shiny!") + room = { - 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + 'outside': Room("Outside Cave Entrance", + "North of you, the cave mount beckons", [sword]), - 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), + 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty +passages run north and east.""", []), '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.""", []), - 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), + 'narrow': Room("Narrow Passage", """The narrow passage bends here from west +to north. The smell of gold permeates the air.""", [gold]), '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.""", [sword, gold]), } - # Link rooms together room['outside'].n_to = room['foyer'] @@ -39,19 +42,29 @@ # username = input("Please put in your name: ") # Make a new player object that is currently in the 'outside' room. -player = Player(username, room['outside']) +player = Player(username, room['outside'], []) # Write a loop that: while player.current_room: # * Prints the current room name print(f"Current room: {player.current_room.name}") -# * Prints the current description (the textwrap module might be useful here). + # * Prints the current description (the textwrap module might be useful here). print(f"{player.current_room.description}") + ret = f"What's in the room? \n" + for i in player.current_room.storage: + ret += f"{i.name}\n" + names = i.name + if len(player.current_room.storage) == 0: + print("There's nothing in the room!\n") + else: + print(ret) print("-------------------------------------------------------------------------") -# * Waits for user input and decides what to do. + # * Waits for user input and decides what to do. + if len(player.current_room.storage) != 0: + print("There's something in the room. Why not try to pick it up or drop whatever if you want to.") selection = input("Please pick a direction to go in (North = n, South = s, West = w, East = e): ") print('-------------------------------------------------------------------------') -# If the user enters a cardinal direction, attempt to move to the room there. + # If the user enters a cardinal direction, attempt to move to the room there. if selection == 'n': if player.current_room.n_to is None: print(f"There is nothing north of {player.current_room.name}. Please pick another direction.") @@ -72,10 +85,16 @@ print(f"\nThere is nothing east of {player.current_room.name}. Please pick another direction.") else: player.current_room = player.current_room.e_to + # elif len(selection) == 2: + # verb = selection[0] + # item_name = selection[1] + # if (verb == 'get' or verb == 'take') and (item_name == names): + # player.current_room.pick_item(item_name) + elif selection == 'q': print("Thank you for playing!") - player.current_room = False # Get out of game -# Print an error message if the movement isn't allowed. + player.current_room = False # Get out of game + # Print an error message if the movement isn't allowed. else: print(selection + " wasn't allowed. Please pick another valid direction.") -# If the user enters "q", quit the game. \ No newline at end of file +# If the user enters "q", quit the game. diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..a798f63458 --- /dev/null +++ b/src/item.py @@ -0,0 +1,8 @@ +class Item: + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f"Name of item: {self.name}\n" \ + f"Description of item: {self.description}" \ No newline at end of file diff --git a/src/player.py b/src/player.py index 71c6a91fc8..a7050029a4 100644 --- a/src/player.py +++ b/src/player.py @@ -1,14 +1,19 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + class Player: - def __init__(self, name, current_room): + def __init__(self, name, current_room, storage): self.name = name self.current_room = current_room + self.storage = storage def __str__(self): - return f"Name: {self.name}\nCurrent room: {self.current_room}" + return f"Name: {self.name}\n" \ + f"Current room: {self.current_room}\n" \ + f"Stuff on player: {self.storage}" if __name__ == "__main__": - a = Player("Bob", "Bob's Room") # __repr__ works + a = Player("Bob", "Bob's Room") # __repr__ works print(a) diff --git a/src/room.py b/src/room.py index 32bdb66bd1..75111f2f54 100644 --- a/src/room.py +++ b/src/room.py @@ -1,17 +1,39 @@ # Implement a class to hold room information. This should have name and # description attributes. +from player import Player + class Room: - def __init__(self, name, description, n_to=None, w_to=None, e_to=None, s_to=None): + def __init__(self, name, description, storage=[], n_to=None, w_to=None, e_to=None, s_to=None): self.n_to = n_to self.w_to = w_to self.e_to = e_to self.s_to = s_to self.name = name self.description = description + self.storage = storage + + def + + + # def pick_item(self, item): + # for i in self.storage: + # if item == i: + # self.storage.remove(i) + # print(f"You picked up {item}") + # return self.storage + # else: + # print(f"There's no such thing as {item}.") + + def __str__(self): - return f"Name of room: {self.name}\nDescription: {self.description}\nNorth: {self.n_to}\nWest: {self.w_to}\n" \ - f"East: {self.e_to}\nSouth: {self.s_to}" + return f"Name of room: {self.name}\n" \ + f"Description: {self.description}\n" \ + f"Stuff that room has: {self.storage}\n" \ + f"North: {self.n_to}\n" \ + f"West: {self.w_to}\n" \ + f"East: {self.e_to}\n" \ + f"South: {self.s_to}" if __name__ == "__main__": a = Room("asdf", "asjd;kl;") # __str__ works