From d38c3c14d4000ac87f5f3275dbae02341b826273 Mon Sep 17 00:00:00 2001 From: Arash Haji-Hassanzadeh <56742302+arashhaji@users.noreply.github.com> Date: Wed, 6 May 2020 18:25:09 -0400 Subject: [PATCH 1/5] mvp 1 --- src/adv.py | 38 +++++++++++++++++++++++++++++++++++++- src/player.py | 10 ++++++++++ src/room.py | 13 ++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..43991feaa3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,6 @@ from room import Room +from player import Player + # Declare all the rooms @@ -38,7 +40,7 @@ # # 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 +51,37 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +while True: + action = input('Enter an action: ') + 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() diff --git a/src/player.py b/src/player.py index d79a175029..aaaa7741ba 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,12 @@ # 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 f"Your name is {self.name}, and you are {self.current_room}" +player1 = Player("Arash", "outside") +print(player1) + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..7bac4464ae 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,13 @@ # 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 + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + def __str__(self): + return f"you are in the {self.name}, {self.description} " \ No newline at end of file From 67718824f0e7405a6b22631d263c06e73c422e2a Mon Sep 17 00:00:00 2001 From: Arash Haji-Hassanzadeh <56742302+arashhaji@users.noreply.github.com> Date: Wed, 6 May 2020 18:27:31 -0400 Subject: [PATCH 2/5] mvp1 --- Pipfile.lock | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Pipfile.lock 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": {} +} From 373489811e4c21c713aa905f1787788428e1ba30 Mon Sep 17 00:00:00 2001 From: Arash Haji-Hassanzadeh <56742302+arashhaji@users.noreply.github.com> Date: Thu, 7 May 2020 01:52:25 -0400 Subject: [PATCH 3/5] added items into room --- src/adv.py | 22 +++++++++++++++++++++- src/item.py | 8 ++++++++ src/room.py | 19 ++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 43991feaa3..dd427abff6 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,6 +1,6 @@ from room import Room from player import Player - +from item import Item # Declare all the rooms @@ -35,6 +35,19 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] + +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] + # # Main # @@ -85,3 +98,10 @@ 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') 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/room.py b/src/room.py index 7bac4464ae..a70276f0ee 100644 --- a/src/room.py +++ b/src/room.py @@ -1,13 +1,26 @@ # Implement a class to hold room information. This should have name and # description attributes. - +from item import Item class Room: - def __init__(self, name, description,): + 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 add_items(self, item): + self.items.append(item) + def __str__(self): - return f"you are in the {self.name}, {self.description} " \ No newline at end of file + return f"you are in the {self.name}, {self.description} " + + +outside = Room('outside', 'the caves forward the cliff is backward', ['sword', 'dagger', 'axe']) +sword = Item('sword', 'longsilver') + +outside.add_items(sword) + +print(outside.items) \ No newline at end of file From eec326104a3e7fb5b68384774ec4145993384c51 Mon Sep 17 00:00:00 2001 From: Arash Haji-Hassanzadeh <56742302+arashhaji@users.noreply.github.com> Date: Thu, 7 May 2020 19:02:47 -0400 Subject: [PATCH 4/5] mvp 2 + stretch added emojies added more items added rooms --- src/adv.py | 53 ++++++++++++++++++++++++++++++++++++++++++++------- src/player.py | 22 +++++++++++++++++++-- src/room.py | 14 ++++++-------- 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/adv.py b/src/adv.py index dd427abff6..066f7490be 100644 --- a/src/adv.py +++ b/src/adv.py @@ -20,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."""), } @@ -34,19 +38,21 @@ 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") +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 @@ -65,9 +71,19 @@ # # If the user enters "q", quit the game. +print("\033[1;32;40m \n") + while True: - action = input('Enter an action: ') - if action == 'start': + 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: @@ -105,3 +121,26 @@ 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/player.py b/src/player.py index aaaa7741ba..50df8b1e57 100644 --- a/src/player.py +++ b/src/player.py @@ -5,8 +5,26 @@ 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}" -player1 = Player("Arash", "outside") -print(player1) + + 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 a70276f0ee..bfdc62c8fa 100644 --- a/src/room.py +++ b/src/room.py @@ -11,16 +11,14 @@ def __init__(self, name, description,items=[]): self.w_to = None self.items = items - def add_items(self, item): + 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} " - -outside = Room('outside', 'the caves forward the cliff is backward', ['sword', 'dagger', 'axe']) -sword = Item('sword', 'longsilver') - -outside.add_items(sword) - -print(outside.items) \ No newline at end of file From a27d48cf20db200c97403ec43c8c3f160708f162 Mon Sep 17 00:00:00 2001 From: Arash Haji-Hassanzadeh <56742302+arashhaji@users.noreply.github.com> Date: Thu, 7 May 2020 23:43:54 -0400 Subject: [PATCH 5/5] Update adv.py --- src/adv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index 066f7490be..07569f3e11 100644 --- a/src/adv.py +++ b/src/adv.py @@ -71,7 +71,7 @@ # # If the user enters "q", quit the game. -print("\033[1;32;40m \n") +print("\033[1;31;40m \n") while True: action = input('Enter an action: ⚔🤩').split(" ")