Untitled
unknown
plain_text
4 months ago
10 kB
2
Indexable
import time, random room_items_dictionary = { "1": "key", "2": "candle"} inventory_list = [] items_list = ["key", "candle"] def main(): choice = play_game() while True: if choice == "1": choice = enter_porch() elif choice == "2": choice = enter_entryway() elif choice == "3": choice = enter_kitchen() elif choice == "4": choice = enter_diningroom() elif choice == "5": choice = enter_livingroom() elif choice == "6": choice = enter_hallway() elif choice == "7": choice = enter_bedroom() elif choice == "7a": choice = enter_bathroom() elif choice == "8": choice = enter_dressingroom() elif choice == "9": choice = enter_guestroom() else: break print("Thanks for playing!\nGOODBYE!") def play_game(): print(""" Hello and welcome to the Adventure House! In each room, you will be told which directions you can go. You can move N (north), S (south), E (east), or W (west) by typing the upper or lower case letter. Type 'Q' to end the program. Type 'S' to start the game!""") while True: choice = input("Enter your choice\n>> ").upper() if choice in ["S","Q"]: break else: print("Please enter a valid choice: 'S' or 'Q'\n") if choice == "S": return "1" else: return "Q" def print_room_header(): line = '=' * 25 print(f"\n{line}{room}{line}") def check_inventory(): if set(inventory_list) == set(items_list): print("\n\nCongratulations! You've found all the items!") os._exit(0) def enter_porch(): global room_items_dictionary, items_list, inventory_list print_room_header("Porch") print(""" You are on the porch of a frightening looking house. The windows are broken. It's a dark and stormy night. You can go N into the house. If you dare.\n Your options: Press 'N' to enter the house Press 'Q' to quit the game\n""") option = input('Select "L" to leave or "S" to search the room.\n>> ').upper() if option == 'S': if "l" in room_items_dictionary: print("Searching room...") time.sleep(2) if random.randint(1,2) == 1: item = room_items_dictionary.get("1") print(f"You found a {item}") inventory_list.append(item) del room_items_dictionary["1"] check_inventory() else: print("You didn't find any items") else: print("No items in room") while True: choice = input("Enter your choice\n>> ").upper() if choice in ["N","Q"]: break else: print("Please enter a valid chocie\n") if choice == "N": return "2" else: return "Q" def enter_entryway(): global room_items_dictionary, items_list, inventory_list print_room_header("Entryway") print(""" You are in the entryway of the house. There are cobwebs in the corner. You feel a sense of dread. There is a passageway to the N and another to the E. The porch is behind you to the S.\n""") option = input('Select "L" to leave or "S" to search the room\n>> ').upper() if option == 'S': if "2" in room_items_dictionary: print("Searching room...") time.sleep(2) if random.randint(1,2) == 1: item = room_items_dictionary.get("2") print(f"You found a {item}") inventory_list.append(item) del room_items_dictionary["2"] check_inventory() else: print("You didn't find any items") else: print("No items in room") while True: choice = input("Which direciton?\n>> ").upper() if choice in ["Q", "N", "S", "E"]: if choice == "N": print("The door is locked...") time.sleep(2) if "key" in inventory_list: print("You use the key to unlock the door") time.sleep(2) break else: print("You can't open the door") else: break else: print("You can't go that way.\n") if choice == "N": return "3" elif choice == "S": return "1" elif choice == "E": return "5" else: return "Q" def enter_kitchen(): print_room_header("Kitchen") print(""" You are in the kitchen. All the surfaces are covered with pots, pans, pieces of food, and pools of blood. You think you hear something up the stairs that go up the west side of the room. It's like a scraping noise, like something being dragged along the floor. You can go to the S, to the E, or type U to go upstairs.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q","S","E","U"]: break else: print("You can't go that way.\n") if choice == "S": return "2" elif choice == "E": return "4" elif choice == "U": return "6" else: return "Q" def enter_diningroom(): print_room_header("Dining Room") print(""" You are in the dining room. There are couches, chairs, and small tables. There are remains of a meal on the table. You can't tell what it is and maybe don't want to. Was that a thump to the west? You can go S or W.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q","S","W"]: break else: print("You can't go that way.\n") if choice == "S": return "5" elif choice == "W": return "3" else: return "Q" def enter_livingroom(): print_room_header("Living Room") print(""" You are in a living room. There are couches, chairs, and small tables. Everything is covered in dust and spider webs. You hear a creaking noise in another room. You can go N or W.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q","N","W"]: break else: print("You can't go that way.\n") if choice == "N": return "4" elif choice == "W": return "2" else: return "Q" def enter_hallway(): print_room_header("Hallway") print(""" At the top of the stairs, you enter the upper hallway of the house. As you face the East wall, you see 3 doorways. You can enter the one on the left by typing L. You can enter the one in the middle by typing M. You can enter the one on the right by typing R. Or you can go back downstairs by typing D.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q","L","M","R","D"]: break else: print("You can't go that way.\n") if choice == "L": return "7" elif choice == "M": return "8" elif choice == "R": return "9" elif choice == "D": return "3" else: return "Q" def enter_bedroom(): print_room_header("Bedroom") print(""" You are in the bedroom. There's a rusty bed filled with scratches and claw marks. The lamp is moving and the lights are flickering. A faint smell of incense lingers in the air. You can go back to the hallway (H) or head further inside northeast (NE).\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q","H","NE"]: break else: print("You can't go that way.\n") if choice == "H": return "6" elif choice == "NE": return "7a" else: return "Q" def enter_bathroom(): print_room_header("Bathroom") print(""" You are in the bathroom. There is a window with broken panes. The sink is grimy, filled with blood. There's an eerie painting on the wall. You can go back to the bedroom (L) or go east (E) to the dressing room.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q", "L", "E"]: break else: print("You can't go that way.\n") if choice == "L": return "7" elif choice == "E": return "8" else: return "Q" def enter_dressingroom(): print_room_header("Dressingroom") print(""" You are in the dressing room. There is a tattered drawer filled with old clothes. The air is unsettling, and you feel as if someone is watching you. A long hallway stretches out to the north. You can go back to the hallway (H) or go N to the bathroom.\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q", "H", "N"]: break else: print("You can't go that way.\n") if choice == "H": return "6" elif choice == "N": return "7a" else: return "Q" def enter_guestroom(): print_room_header("Guestroom") print(""" You are in the guestroom. The bed is filled with clutter and glass. There are tapestries on the walls and creepy paintings all around. The air is thick with dust, and you think you see something from the corner of your eye under the bed. You can go back to the hallway (H).\n""") while True: choice = input("Which direction?\n>> ").upper() if choice in ["Q", "H"]: break else: print("You can't go that way.\n") if choice == "H": return "6" else: return "Q" main()
Editor is loading...
Leave a Comment