From b09872e26af620268d37313b7307435e5f441e87 Mon Sep 17 00:00:00 2001 From: kmk028 Date: Wed, 9 Sep 2020 02:03:37 -0700 Subject: [PATCH 1/2] Day1 MVP completed --- src/adv.py | 30 +++++++++++++++++++++++++++++- src/player.py | 9 +++++++++ src/room.py | 12 +++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..9a67fcd35c 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,5 @@ from room import Room - +from player import Player # Declare all the rooms room = { @@ -38,6 +38,8 @@ # # Make a new player object that is currently in the 'outside' room. +name = input ('State thy name adventurer! : ') +player = Player(name,room['outside']) # Write a loop that: # @@ -49,3 +51,29 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +# Create a dict of possible directions +directions = {'N':'n_to', 'S':'s_to', 'E':'e_to', 'W':'w_to'} +#Print the current position of player. +print(f"###### {player.name}, you are at {player.current_room.name}######") + +while True: + + choice = input('Where do you want to go? (Press N for North, E for east , W for West , S for South. Q for quit game') + # if user choice is valid move player to new location and print it, + # if Choice is to quit then break out of loop + # if choice is invalid then ask for valid input. + if choice in directions.keys(): + direction = directions[choice] + previous_room = player.current_room + try: + player.current_room = getattr(player.current_room,direction) + print(f"###### {player.name}, you are at {player.current_room.name}######") + except AttributeError: + player.current_room = previous_room + print('Cannot go that way! Choose again. ') + elif choice is 'Q': + print ('Good bye adventurer! Thanks for Playing :)') + break + else: + print('Invalid choice! Choose again.') diff --git a/src/player.py b/src/player.py index d79a175029..df2b2ac287 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,11 @@ # 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 + + def __str__(self): + return '{0} is at {1}'.format(self.name,self.current_room) + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..8f01e69b67 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,12 @@ # 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, s_to=None, e_to=None, w_to=None): + self.name = name + self.description = description + self.n_to = n_to + self.s_to = s_to + self.e_to = e_to + self.w_to = w_to + \ No newline at end of file From b4ff12c16c4ac7b94463b407602d809b93a1c0e3 Mon Sep 17 00:00:00 2001 From: kmk028 Date: Sun, 13 Sep 2020 17:29:07 -0700 Subject: [PATCH 2/2] Day2 MVP completed --- src/adv.py | 19 +++++++++++++++++++ src/item.py | 6 ++++++ src/room.py | 9 ++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 9a67fcd35c..c04c493d60 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ from room import Room from player import Player +from item import Item # Declare all the rooms room = { @@ -33,6 +34,24 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +#list of items + +items = {'greatsword': Item("greatsword","Ancient sword of Elves"), + 'warhammer': Item("warhammer","Dwarven WarHammer"), + 'Armor': Item("Armor","Dragonscale armor"), + 'Potion': Item("Potion","Potion of resist Poison"), + 'Banner': Item("Banner","House Banner"), + 'Ring': Item("Ring","Pearl Ring")} + +#Put items in Rooms + +room['foyer'].items = [items['greatsword'],items['Potion']] +room['treasure'].items = [items['Ring']] +room['overlook'].items = [items['Banner']] +room['narrow'].items = [items['Armor'],] + +print (room['foyer'].items) + # # Main # diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..9058b3dcf5 --- /dev/null +++ b/src/item.py @@ -0,0 +1,6 @@ +#item Base Class + +class Item(): + def __init__(self,item,description): + self.item=item + self.description=description \ No newline at end of file diff --git a/src/room.py b/src/room.py index 8f01e69b67..8865fb5758 100644 --- a/src/room.py +++ b/src/room.py @@ -2,11 +2,18 @@ # description attributes. class Room(): - def __init__(self, name, description, n_to=None, s_to=None, e_to=None, w_to=None): + def __init__(self, name, description, n_to=None, s_to=None, e_to=None, w_to=None,items=[]): self.name = name self.description = description self.n_to = n_to self.s_to = s_to self.e_to = e_to self.w_to = w_to + self.items=items + +def put_item(self,item_name): + self.items = self.items.append(Item[item_name]) + +def take_item(self,item_name): + self.items = self.items.remove(item_name) \ No newline at end of file