From fd1dbe1069397cf9e5a62c7f92747d0d71030fe3 Mon Sep 17 00:00:00 2001 From: ameralhomdy Date: Tue, 8 Sep 2020 21:00:54 -0700 Subject: [PATCH 1/4] finished room.py --- src/room.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/room.py b/src/room.py index 24c07ad4c8..80ed164ad6 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: + def __init__(self, name, description): + self.name = name + self.description = description + + def get_direction(self, direction): + if direction == 'n': + return self.n_to + elif direction == 's': + return self.s_to + elif direction == 'e': + return self.e_to + elif direction == 'w': + return self.w_to + else: + return None \ No newline at end of file From 6a3321f0e0a728d9b519a2e2cab569faa53ef752 Mon Sep 17 00:00:00 2001 From: ameralhomdy Date: Tue, 8 Sep 2020 21:19:49 -0700 Subject: [PATCH 2/4] finished player.py --- src/player.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/player.py b/src/player.py index d79a175029..a7221f97a3 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,13 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Player: + def __init__(self, current_room): + self.current_room = current_room + + def move(self, direction): + next_room = self.current_room.get_direction(direction) + if next_room != None: + self.current_room = next_room + else: + print("You can't move that way!!") \ No newline at end of file From 09ca6a46a569d8e811132c06fefb83a755610123 Mon Sep 17 00:00:00 2001 From: ameralhomdy Date: Tue, 8 Sep 2020 21:48:17 -0700 Subject: [PATCH 3/4] working on day1 mvp --- src/adv.py | 17 +++++++++++++++++ src/player.py | 4 ++-- src/room.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..edf8e2d617 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,6 +37,22 @@ # # Main # +directions = ['n', 's', 'e', 'w'] +player = Player(room['outside']) + +while True: + print(player.current_room) + print(player.current_room.description) + + usr_input = input("Where would you like to go? ") + + if usr_input == 'q' or 'quit': + break + elif usr_input in directions: + player.move(usr_input) + + else: + print("Input a valid direction [n, s, e, w]") # Make a new player object that is currently in the 'outside' room. diff --git a/src/player.py b/src/player.py index a7221f97a3..89b7f5d9ee 100644 --- a/src/player.py +++ b/src/player.py @@ -7,7 +7,7 @@ def __init__(self, current_room): def move(self, direction): next_room = self.current_room.get_direction(direction) - if next_room != None: + if next_room is not None: self.current_room = next_room else: - print("You can't move that way!!") \ No newline at end of file + print("You can't move that way!!") diff --git a/src/room.py b/src/room.py index 80ed164ad6..83c94ece11 100644 --- a/src/room.py +++ b/src/room.py @@ -16,4 +16,4 @@ def get_direction(self, direction): elif direction == 'w': return self.w_to else: - return None \ No newline at end of file + return None From 1edb89cd09beeef85732e07a1c0dba88aa3ba509 Mon Sep 17 00:00:00 2001 From: ameralhomdy Date: Thu, 10 Sep 2020 20:35:06 -0700 Subject: [PATCH 4/4] met day 1 mvp & working through day 2 mvp --- src/adv.py | 21 ++++++++++++++------- src/items.py | 4 ++++ src/player.py | 8 +++++++- src/room.py | 10 +++++++--- 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/items.py diff --git a/src/adv.py b/src/adv.py index edf8e2d617..f36d1c17cd 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ from room import Room from player import Player +from items import Item # Declare all the rooms @@ -23,6 +24,7 @@ } + # Link rooms together room['outside'].n_to = room['foyer'] @@ -37,7 +39,7 @@ # # Main # -directions = ['n', 's', 'e', 'w'] +directions = ['n', 's', 'e', 'w', 'q'] player = Player(room['outside']) while True: @@ -46,13 +48,18 @@ usr_input = input("Where would you like to go? ") - if usr_input == 'q' or 'quit': - break - elif usr_input in directions: - player.move(usr_input) + try: + while usr_input not in directions: + print("\nInput a valid direction [n, s, e, w]\n") + usr_input = input("Where would you like to go? ") + + if usr_input == 'q': + break - else: - print("Input a valid direction [n, s, e, w]") + player.move(usr_input) + + except AttributeError as error: + print("\nYou can't move that way!!\n") # Make a new player object that is currently in the 'outside' room. diff --git a/src/items.py b/src/items.py new file mode 100644 index 0000000000..f3a997675f --- /dev/null +++ b/src/items.py @@ -0,0 +1,4 @@ +class Item: + def __init__(self, name, description): + self.name = name + self.description = description \ No newline at end of file diff --git a/src/player.py b/src/player.py index 89b7f5d9ee..01aaede024 100644 --- a/src/player.py +++ b/src/player.py @@ -2,8 +2,9 @@ # currently. class Player: - def __init__(self, current_room): + def __init__(self, current_room, items: List[Item]=None): self.current_room = current_room + self.items: List[Item] = items def move(self, direction): next_room = self.current_room.get_direction(direction) @@ -11,3 +12,8 @@ def move(self, direction): self.current_room = next_room else: print("You can't move that way!!") + + + def __repr__(self): + return f'Room({repr(self.current_room)})' + diff --git a/src/room.py b/src/room.py index 83c94ece11..3ef8daf1b7 100644 --- a/src/room.py +++ b/src/room.py @@ -2,9 +2,10 @@ # description attributes. class Room: - def __init__(self, name, description): + def __init__(self, name, description, items: List[Item]=None): self.name = name self.description = description + self.items: List[Item] = items def get_direction(self, direction): if direction == 'n': @@ -15,5 +16,8 @@ def get_direction(self, direction): return self.e_to elif direction == 'w': return self.w_to - else: - return None + + def add_item(self, item): + + def __repr__(self): + return f'Room({repr(self.name)})'