From 4cb24e14f8ae180eaca480c99deafd9a5a8dbedb Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 00:00:30 -0600 Subject: [PATCH 1/5] adv.py updated --- src/adv.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..f7c6e8b9a3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -39,11 +39,74 @@ # Make a new player object that is currently in the 'outside' room. +playerone = Playerone(room['outside'], "player one has arrived outside the room.") + +def instructions(): + return """ + Welcome to the labyrinth dear wanderer... + + * use [L] to look around + * [N,S,E,W] [North, South, East, West] [Up, Down, Right, Left] to travel in those directions + * [q] to quit + """ + +def current_dirs(): + currentDirs = directions() + + if currentDirs.__contains__("n"): + currentDirs.extend(["north", "up", "forward", "forwards"]) + if currentDirs.__contains__("s"): + currentDirs.extend(["south", "down", "backward", "backwards"]) + if currentDirs.__contains__("e"): + currentDirs.extend(["east", "right"]) + if currentDirs.__contains__("w"): + currentDirs.extend(["west", "left"]) + + return currentDirs + +def directions(): + directions = [] + + if hasattr(player.current_room, "n_to"): + directions.append("n") + if hasattr(player.current_room, "s_to"): + directions.append("s") + if hasattr(player.current_room, "e_to"): + directions.append("e") + if hasattr(player.current_room, "w_to"): + directions.append("w") + + return directions + # Write a loop that: # # * Prints the current room name # * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. + +def travel(input): + + input = input.lower() + if input in current_dirs(): + if input == "n" or input == "north" or input == "up" or input == "forward" or input == "forwards": + player.current_room = player.current_room.n_to + elif input == "s" or input == "south" or input == "down" or input == "backward" or input == "backwards": + player.current_room = player.current_room.s_to + elif input == "e" or input == "east" or input == "right": + player.current_room = player.current_room.e_to + elif input == "w" or input == "west" or input == "left": + player.current_room = player.current_room.w_to + else: + sys_print("Wrong Way! There's nothing over there.") + +def prompt(s): + # print a quicklist of commands + commands = f"(L to look around | {' | '.join(directions())} to travel | Q to quit | [Help|?] for common commands): " + prompt = f"\nWhat would you like to do, {player.name}?\n{commands}" + + return input(s + prompt) + + # # If the user enters a cardinal direction, attempt to move to the room there. # Print an error message if the movement isn't allowed. From 6c340440a4c893234f6f3ce09ff307e7099e02bd Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 00:25:28 -0600 Subject: [PATCH 2/5] player and room classes created --- src/adv.py | 5 +++-- src/player.py | 6 ++++++ src/room.py | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index f7c6e8b9a3..87c1c3dba7 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,3 +1,4 @@ +from player import Player from room import Room # Declare all the rooms @@ -39,7 +40,7 @@ # Make a new player object that is currently in the 'outside' room. -playerone = Playerone(room['outside'], "player one has arrived outside the room.") +player = Player(room['outside'], "player one has arrived outside the room.") def instructions(): return """ @@ -97,7 +98,7 @@ def travel(input): elif input == "w" or input == "west" or input == "left": player.current_room = player.current_room.w_to else: - sys_print("Wrong Way! There's nothing over there.") + print("Wrong Way! There's nothing over there.") def prompt(s): # print a quicklist of commands diff --git a/src/player.py b/src/player.py index d79a175029..006fbc5acc 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,8 @@ # 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 \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..b172774a9e 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,7 @@ # 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 From 5815e4120201e4074c93d557213f0d9d4d32149c Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 15:38:26 -0600 Subject: [PATCH 3/5] item.py added --- src/item.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/item.py diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..5b782935ee --- /dev/null +++ b/src/item.py @@ -0,0 +1,65 @@ +class Item: + def __init__(self, id, name, description, room_description, vitamins): + self.id = id + self.name = name + self.description = description + self.room_description = room_description + self.vitamins = vitamins + + def __str__(self): + return f"{self.name} is worth {self.vitamins} vitamins" + def to_inventory(self): + print(f"{self.name} was placed into your inventory") + def to_floor(self): + print(f"{self.name} was dropped on the floor.") + +class Container(Item): + def __init__(self, id, name, description, room_description, inventory): + super().__init__(id, name, description, room_description, 0) + self.inventory = inventory + + def letter_to_int(self, letter): + alphabet = list('abcdefghijklmnopqrstuvwxyz') + if letter in alphabet: + return alphabet.index(letter) + + def int_to_letter(self, index): + alphabet = list('abcdefghijklmnopqrstuvwxyz') + if len(alphabet) >= index + 1: + return alphabet[index] + + def list_inventory(self, player): + #turning a letter into bytes + letter_i = self.letter_to_int('a') + + for item in self.inventory: + #decode to string and make uppercase + letter_s = self.int_to_letter(letter_i) + upper_str = letter_s.upper() + #output + print(f"{upper_str}: {item.name}") + #increment to the next byte (this will convert to the next character) + letter_i += 1 + if len(self.inventory) > 0: + treasure = input("select a letter to take an item: ").lower() + index = self.letter_to_int(treasure) + + if isinstance(index, int) and len(self.inventory) >= index + 1: + player.take(self.inventory[index]) + self.inventory.pop(index) + else: + print(f"{treasure} cannot be removed from this chest") + else: + print(f"{self.name} is empty!") + + +class Trinket(Item): + def __init__(self, id, name, description, room_description, sparkle): + super().__init__(id, name, description, room_description) + self.sparkle = sparkle + +class VitaminPack(Item): + def __init__(self, id, room_description): + super().__init__(id, "vitamins", "", room_description) + self.description = f"vitamins - to keep you going in circles longer" + From cc2dc01c386be44ee5a476b4f155e5ca2e5ee394 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 17:02:12 -0600 Subject: [PATCH 4/5] items imported in adv.py and descriptions updated --- src/adv.py | 75 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/src/adv.py b/src/adv.py index 87c1c3dba7..f18005a9a4 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,25 +1,70 @@ from player import Player from room import Room +from item import Item, Trinket, VitaminPack, Container + +#Items List +necklace = Trinket( + -1, + "a priceless necklace is in one of these rooms somewhere", + 1 +) + +notebook = Trinket( + -1, + "no one knows how old this notebook is or who even wrote it... there appears to be strange characters on several pages...and is that.. blood?!?", + 1 +) + +backpack = Container( + 1, + "backpack", + "this backpack can hold everything except maybe your sanity", + [necklace] +) + +items = [necklace.name, notebook.name, backpack.name] # Declare all the rooms - room = { - 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), - - 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), - - 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling + 'outside': Room( + "Outside Cave Entrance", + "North of you, the cave mount beckons. The path is steep and treacherous, but the mystery draws you in."), + + 'foyer': Room( + "Foyer", + """ + Dim light filters in from the south. Dusty + passages run north and east. There is an aging yellow velvet couch on the corner and it that... a backpack?!?""", + [backpack] + +), + + 'overlook': Room( + "Grand Overlook", + """ + A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm."""), - - 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), - - 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure +the distance, but there is no way across the chasm. + """, + [notebook] +), + + 'narrow': Room( + "Narrow Passage", + """ + The narrow passage bends here from west +to north. The smell of gold permeates the air. Or is that just the mold in the corners...? Through cobwebs and patch of dirt in the corner of the floor a small flash catches your eyes. Is that...no it can't be. It is a priceless antinque necklace that you quickly stash into your backpack." + """, + [necklace] +), + + 'treasure': Room( + "Treasure Chamber", + """ + You've found the long-lost rumored treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south."""), +earlier adventurers. There are scribblings on the wall. It looks like nothing at first, but then you realize that it is a map of another complex entirely. You quickly sketch down the map in your notebook. The eery stillness of the chamber creeps you out majorly. Happy with the necklace and the mystery of the notebook's characters, as well as the enigma of the new map, you set off as fast as you can to figure out what it all means. You exit to find out what the next level brings. + """), } From b7bfb2d3da3073114d433136af2c780a4027dae3 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Tue, 6 Apr 2021 19:29:52 -0600 Subject: [PATCH 5/5] added the get and drop commands to the parser --- src/adv.py | 142 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 118 insertions(+), 24 deletions(-) diff --git a/src/adv.py b/src/adv.py index f18005a9a4..942b434959 100644 --- a/src/adv.py +++ b/src/adv.py @@ -25,7 +25,7 @@ items = [necklace.name, notebook.name, backpack.name] # Declare all the rooms -room = { +rooms = { 'outside': Room( "Outside Cave Entrance", "North of you, the cave mount beckons. The path is steep and treacherous, but the mystery draws you in."), @@ -67,26 +67,29 @@ """), } - # Link rooms together -room['outside'].n_to = room['foyer'] -room['foyer'].s_to = room['outside'] -room['foyer'].n_to = room['overlook'] -room['foyer'].e_to = room['narrow'] -room['overlook'].s_to = room['foyer'] -room['narrow'].w_to = room['foyer'] -room['narrow'].n_to = room['treasure'] -room['treasure'].s_to = room['narrow'] +rooms['outside'].n_to = rooms['foyer'] +rooms['foyer'].s_to = rooms['outside'] +rooms['foyer'].n_to = rooms['overlook'] +rooms['foyer'].e_to = rooms['narrow'] +rooms['overlook'].s_to = rooms['foyer'] +rooms['narrow'].w_to = rooms['foyer'] +rooms['narrow'].n_to = rooms['treasure'] +rooms['treasure'].s_to = rooms['narrow'] +#initiate the room sequence +room = rooms['outside'] # # Main -# - -# Make a new player object that is currently in the 'outside' room. player = Player(room['outside'], "player one has arrived outside the room.") +i = input("Welcome to Mystery Volumes I: what should we call you?\n") +player = Player(i, room, 100, 0, 0) + +print(f"Goodnight and goodluck, {player.name}") + def instructions(): return """ Welcome to the labyrinth dear wanderer... @@ -124,12 +127,6 @@ def directions(): return directions -# Write a loop that: -# -# * Prints the current room name -# * Prints the current description (the textwrap module might be useful here). -# * Waits for user input and decides what to do. - def travel(input): input = input.lower() @@ -145,6 +142,27 @@ def travel(input): else: print("Wrong Way! There's nothing over there.") +def look(): + if player.current_room == rooms['outside']: + + print("Looking around the room you spot an object:") + + item_instructions = "take the object" + + #when there isn't anything in the room anyhow + + if len(player.current_room.items) == 0: + print(f"Nothing is there...try another room to {item_instructions}") + item_instructions = "" + + #displaying the descriptions of each room + item_desc = [x.room_description for x in player.current_room.items] + for i, _ in enumerate(item_desc): + print(f"{player.current_room.items[i].name}: {item_desc[i]}") + #empty line + print() + + def prompt(s): # print a quicklist of commands commands = f"(L to look around | {' | '.join(directions())} to travel | Q to quit | [Help|?] for common commands): " @@ -152,9 +170,85 @@ def prompt(s): return input(s + prompt) +def parse(inpt): + commands = [ + "travel", "walk", "run", + "take", "drop", + "look" + ] + commands.extend(current_dirs()) + + #add items available in this room to the command list + commands.extend([item.name for item in player.current_room.items]) + + #add the player's items + commands.extend([item.name for item in player.inventory]) + commands.append(player.leftHandItem.name) + commands.append(player.rightHandItem.name) + + inpt = inpt.lower() + # list of the available command separated by space + inputList = inpt.split() + + #only allow commands to be parsed + commands = [] + for cmd in inputList: + if cmd in commands or cmd in items: + commands.append(cmd) + + if len(commands) >= 1: + cmd1 = commands[0] + + if len(commands) > 1: + cmd2 = commands[1] + if len(commands) >2: + print("only two commands can be used at a time separated by a space") + #win the game and exit + if cmd1 == "take" and cmd2 == "drop": + if player.current_room != rooms['treasure']: + print("Can you decipher anything in here?") + else: + print(""" + Do you see the writing's on the wall somewhere over here? + + "No treasure, but some scratches on the wall...typical. Wait, is that a ... map?" + + You appoach the wall in the dimly lit room and realize that you are in fact staring at a map in front of you. You quickly get out the old notebook and sketch a copy of the map as quickly as you can. + """) + + #parse verb commands + if cmd1 == "travel" or cmd1 == "run" or cmd1 == "walk": + travel(cmd2) + return + + if cmd1 == "take" or cmd1 == "drop": + player.take(cmd2) + return + + elif cmd1 == "drop": + player.dropItem(cmd2) + return + + #singular commands + else: + dirs = ["n", "north", "up", "e", "east", "right", "s", "south", "down", "w", "west", "left"] + + if inpt == "q": + exit(0) + elif inpt == "instructions" or inpt == "?" or inpt == "h": + print(instructions()) + return + elif inpt in dirs: + travel(inpt) + return + elif inpt == "l": + look() + return + elif inpt == "inventory" or inpt == "i": + player.list_inventory() + return + print("invalid command") + + + -# -# If the user enters a cardinal direction, attempt to move to the room there. -# Print an error message if the movement isn't allowed. -# -# If the user enters "q", quit the game.