Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help with my text based adventure game i currently have this code but i can not make it work. ive been working on it all

help with my text based adventure game

i currently have this code but i can not make it work. ive been working on it all day.

i have it moving between rooms but i need to make it display an inventory with the items i have collected and let me collect the items that are located within the rooms with a yes or no prompt. i should be prompted to fix my input if i write something incorrectly. if i go back to the room the room should be empty. the final boss is in the back yard so if i dont have all items collected its a game over. if anyone can help me it would be greatly appreciated. im trying to keep my code as close to what i already have written

def showInstructions(): print('Escape the House!'), print('Collect all 6 items in order to defeat Coco!'), print('Movement Commands: North, South, East, West'), print('Type "'"y"'" or "'"n"'" when prompted') inventory = ['Pennies', 'Sling Shot', 'Muzzle', 'Tooth Pick', 'Dog Treats', 'Fork'] def showStatus(): print(inventory) def main(): inventory:[] rooms = { 'Living Room': {'name': 'Living Room', 'South': 'Dining Room', 'North': 'Bedroom', 'West': 'Utility Closet', 'East': 'Kitchen'}, 'Bedroom': {'name': 'Bedroom', 'South': 'Living Room', 'East': 'Bedroom Closet', 'item': 'Pennies'}, 'Bedroom Closet': {'name': 'Bedroom Closet', 'West': 'Bedroom', 'item': 'Sling Shot'}, 'Utility Closet': {'name': 'Utility Closet', 'East': 'Living Room', 'item': 'Muzzle' }, 'Kitchen': {'name': 'Kitchen', 'North': 'Pantry', 'West': 'Living Room','item': 'Toothpick'}, 'Pantry': {'name': 'Pantry', 'South': 'Kitchen', 'item': 'Dog Treats'}, 'Dining Room': {'name': 'Dining Room', 'North': 'Living Room', 'East': 'Back Yard', 'item': 'Fork'}, 'Back Yard': {'name': 'Back Yard', 'West': 'Dining Room', 'item': 'Coco'} } directions = ['North', 'South', 'East', 'West'] current_room = rooms['Living Room'] showInstructions() def get_item(current_room): return rooms[current_room]['Item'] while True: print('You are in the {}.'.format(current_room['name'])) print('inventory:', inventory) item = get_item(current_room) command = input('Direction: ') if command in directions: if command in current_room: current_room = rooms[current_room[item]] print("You found:", rooms[current_room]["item"],"Would you like to pick it up? (y/n)") user_input = input().lower() while user_input != "y" and user_input != "n": print(" Invalid response. Try again:", end=" ") user_input = input().lower() if user_input == "y": if "item" in rooms[current_room]: print(" You found: " + rooms[current_room]["item"] + "!") inventory.append(rooms[current_room]["item"]) if rooms[current_room]["item"] == []: print(addedinventory()) else: print(" You find nothing of value...") showStatus() else: print('Invalid direction') elif command.lower() in ('exit','Exit'): print("Thank you for playing!") break else: print('invalid command') main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions