diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000000..a36a2c8975 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "4e61a4ba9e6f02f50f68627253af5ababd9b1b4c1e10294e48158e1f42c0c5a6" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..07569f3e11 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,6 @@ from room import Room +from player import Player +from item import Item # Declare all the rooms @@ -18,6 +20,10 @@ '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."""), + + 'secret': Room("Secret", """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."""), } @@ -32,13 +38,28 @@ room['narrow'].w_to = room['foyer'] room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +room['secret'].n_to = room['outside'] + + +sword = Item("sword", "cutting through flesh") +axe = Item("axe", "battle axe") +torch = Item("torch", "torch") +dagger = Item("dagger", "hunting") +gold = Item("gold", "Yea Buddy") + +room['outside'].items = [] +room['foyer'].items = [torch] +room['overlook'].items = [dagger] +room['narrow'].items = [axe, sword] +room['treasure'].items = [gold] +room['secret'].items =[map] # # Main # # Make a new player object that is currently in the 'outside' room. - +newPlayer =Player('Dave', room['outside']) # Write a loop that: # # * Prints the current room name @@ -49,3 +70,77 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +print("\033[1;31;40m \n") + +while True: + action = input('Enter an action: ⚔🤩').split(" ") + if len(action) == 1 : + action = action[0] + + elif len(action) == 2 : + new_item = action[1] + action = action[0] + + + if action == 'start😎': + if newPlayer.current_room: + print(f'{newPlayer.current_room}') + else: + print('no path in that direction') + if action == 'n': + if newPlayer.current_room.n_to: + newPlayer.current_room=newPlayer.current_room.n_to + print(f'{newPlayer.current_room}') + else: + print('you cannot go north') + if action == 's': + if newPlayer.current_room.s_to: + newPlayer.current_room=newPlayer.current_room.s_to + print(f'{newPlayer.current_room}') + else: + print('no path in that direction') + if action == 'e': + if newPlayer.current_room.e_to: + newPlayer.current_room=newPlayer.current_room.e_to + print(f'{newPlayer.current_room}') + else: + print('no path in that direction') + if action == 'w': + if newPlayer.current_room.w_to: + newPlayer.current_room=newPlayer.current_room.w_to + print(f'{newPlayer.current_room}') + else: + print('no path in that direction') + if action == 'q': + exit() + + if action == 'look': + if newPlayer.current_room.items: + for obj in newPlayer.current_room.items: + print(obj.name) + else: + print('no items in your room') + + if action == 'inv': + newPlayer.print_inventory() + + if action in ["take", "get"]: + for inv in newPlayer.current_room.items: + if inv.name == new_item: + newPlayer.add(inv) + newPlayer.current_room.on_take(inv) + else: + print('item is not in the room') + + if action in ["drop", "d"]: + for inv in newPlayer.inventory: + if inv.name == new_item: + newPlayer.remove(inv) + newPlayer.current_room.on_drop(inv) + else: + print('item is not in inventory') + + + + diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..8d8549500e --- /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'{self.name}, {self.description}' + diff --git a/src/player.py b/src/player.py index d79a175029..50df8b1e57 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,30 @@ # 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 __str__(self): + return f"Your name is {self.name}, and you are {self.current_room}" + + def add(self, item): #method or function + self.inventory.append(item) + print(f"This {item} was added to your inventory ") + + def remove(self, item): + self.inventory.remove(item) + print(f"This {item} has been removed from the inventory ") + + def print_inventory(self): + if len(self.inventory) == 0: + print("Inventory Empty") + for inv in self.inventory: + print(inv) + + + + + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..bfdc62c8fa 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,24 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. +from item import Item +class Room: + def __init__(self, name, description,items=[]): + self.name = name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + self.items = items + + def on_drop(self, item): + self.items.append(item) + print(f'{item} has been dropped into room ') + + def on_take(self, item): + self.items.remove(item) + print(f'{item} has been taken from room ') + + def __str__(self): + return f"you are in the {self.name}, {self.description} " +