diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..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,11 +34,31 @@ 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 # # 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 +70,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/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/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..8865fb5758 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, 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