From 3985574ec83eb55364fb187b12c358a1334e66b4 Mon Sep 17 00:00:00 2001 From: Dominic Bridgette <54685761+Afrodo1@users.noreply.github.com> Date: Tue, 8 Sep 2020 21:01:07 -0700 Subject: [PATCH 1/2] first commit --- src/adv.py | 2 ++ src/room.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..1adeb3e8ff 100644 --- a/src/adv.py +++ b/src/adv.py @@ -49,3 +49,5 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..f7a664b609 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,3 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. +room = 0 \ No newline at end of file From 1d4d722f216ef459e7a4fd42ddff77ba446280dc Mon Sep 17 00:00:00 2001 From: Dominic Bridgette <54685761+Afrodo1@users.noreply.github.com> Date: Thu, 10 Sep 2020 23:41:00 -0700 Subject: [PATCH 2/2] finished MVP day 2 --- src/adv.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/items.py | 7 ++++++ src/player.py | 21 ++++++++++++++++ src/room.py | 22 ++++++++++++++++- 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 src/items.py diff --git a/src/adv.py b/src/adv.py index 1adeb3e8ff..c4cfda47d3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ -from room import Room - +from room import Room, valid_directions +from player import Player +from items import Item # Declare all the rooms room = { @@ -33,11 +34,28 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] + +#items +item = { + 'coins': Item("Coins: ~~[Money", "--Just a few lose coins to take to the tavern]~~"), + 'tools': Item("Tool: ~~[Grappling hook", "--This might come in handy. It is very heavy]~~"), + 'jewel': Item("Jewel: ~~[Gem", "--Next time you ask that stranger for information. He might be willing to help for this type of payment]~~"), + 'torch': Item("Tool: ~~[Torch", "--Let there be light. Is someone sneaking around? Why is this on the floor?!?]~~"), + 'trap': Item("Misc: ~~[Tripped Trap", "--An abandoned trap that has been tripped. If cleaned up it could be useful.]~~"), + 'medallion': Item("Jewel: ~~[Medallion", "--It reflects light and glows slightly orange it may be magical. There is an inscription in an unknown language. Inscription:Hul werud ezes ulud egembelu owog. Kyul buol engumet ullyetuk.]~~ "), +} + +room['outside'].items = [] +room['foyer'].items = [str(item['coins']), str(item['trap'])] +room['overlook'].items = [str(item['jewel']),str(item['medallion']),str(item['trap'])] +room['narrow'].items = [str(item['jewel']), str(item['coins']), str(item['torch'])] +room['treasure'].items = [str(item['tools'])] # # Main # # Make a new player object that is currently in the 'outside' room. +players = Player('Dom', room['outside']) # Write a loop that: # @@ -50,4 +68,48 @@ # # If the user enters "q", quit the game. +def is_direction(str): + """ + returns true from string if it is a valid + """ + return str in valid_directions + +print(f'Welcome {players.name}, press q at any time to quit') +print(f'You are currently {players.current_room.name}') +print(players.current_room.description) +current_room = players.current_room +items = current_room.items + +def item_check(room_items): + if room_items != []: + return True + else: + return False + +while True: + if current_room != players.current_room: + print(players.current_room) + current_room = players.current_room + items = current_room.items + user_input = input('What would you like to do? Choose direction n, e, s or w? Or "view" Room: ') + if user_input == 'q': + break + elif is_direction(user_input): + players.move(user_input) + elif user_input.lower().strip() == 'view': + if item_check(items) == True: + print('In this room you will find these items: ') + for item in items: + print(item) + choice = str(input('Would you like to pick up these items: y or n ')) + if choice == 'y': + players.pick_up(items) + print('Your inventory now contains ' + str(players.inventory)) + items.clear() + else: + user_input = input('What would you like to do? Choose direction n, e, s or w? Or "view" Room: ') + else: + print('There are no items in this room') + else: + print('Sorry that is not a valid command, please try again!') diff --git a/src/items.py b/src/items.py new file mode 100644 index 0000000000..0a92ddb454 --- /dev/null +++ b/src/items.py @@ -0,0 +1,7 @@ +class Item(): + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f'{self.name}{self.description}' \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..d00228d527 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,23 @@ # 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 + self.inventory = [] + + def move(self, direction): + new_room = getattr(self.current_room, f"{direction}_to") + if (new_room) is not None: + self.current_room = new_room + else: + print("Sorry you can't move in that direction") + + def pick_up(self,*items): + room_items = items + for item in items: + self.inventory.extend(item) + + + def __str__(self): + return '{self.name} {self.room}'.format(self=self) \ No newline at end of file diff --git a/src/room.py b/src/room.py index f7a664b609..5447421337 100644 --- a/src/room.py +++ b/src/room.py @@ -1,3 +1,23 @@ # Implement a class to hold room information. This should have name and # description attributes. -room = 0 \ No newline at end of file +valid_directions = ('n','s','e','w') + +class Room: + def __init__(self, name, description): + self.name = name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + + def __str__(self): + return '{self.name} {self.description}'.format(self=self) + + def show_directions(self): + possible_directions = filter(lambda d: getattr(self, f"{d}_to") is not None, valid_directions) + return ", ".join(list(map(to_upper, possible_directions))) + + def print_welcome(self): + print(f'Welcome to {self.name}!') + print(f'{self.description}') \ No newline at end of file