IT140Proj2Bluey

.py

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

140

Subject

Industrial Engineering

Date

Apr 30, 2024

Type

py

Pages

3

Uploaded by BarristerArmadilloPerson1005 on coursehero.com

IT-140 # Define the game map and items game_map = { 'Backyard': {'North': 'Living Room', 'East': 'Kitchen', 'West': 'Patio', 'South': 'Closet', 'Item': None}, 'Patio': {'East': 'Backyard', 'Item': 'Hot Rod'}, 'Living Room': {'South': 'Backyard', 'East': "Bluey and Bingo's Bedroom", 'Item': 'Xylophone'}, "Bluey and Bingo's Bedroom": {'West': 'Living Room', 'Item': 'Feather Wand'}, 'Closet': {'North': 'Backyard', 'East': 'Garage', 'Item': 'Ballerina outfit'}, 'Garage': {'West': 'Closet', 'Item': "Tina's tooth"}, 'Kitchen': {'West': 'Backyard', 'North': "Bandit and Chili's Bedroom", 'Item': 'Magic Asparagus'}, "Bandit and Chili's Bedroom": {'South': 'Kitchen', 'Item': None, 'Villain': 'the evil witch, Muffin'}, } # Player's initial status player_status = { 'Current Room': 'Backyard', 'Inventory': [], } def display_intro(): print("The evil witch, Muffin, has captured the Chattermax idol for her summoning spell.") print( "You find yourself alone in the backyard, and you need to defeat the evil witch before she can complete her " "spell.") print("She cannot be defeated without the aid of six items:") print("1. Magic Asparagus from the fridge in the kitchen to change the witch into any animal.") print("2. The xylophone from the living room to freeze the evil witch.") print("3. Muffin’s Hot Rod from the patio for a quick getaway.") print("4. A ballerina outfit from the closet to get by the guards.") print("5. A fallen tooth from Tina the Giant in the garage to summon the giant.") print("6. A feather wand from the bedroom to lift obstacles out of the way.") def display_status(): current_room = player_status['Current Room'] inventory = player_status['Inventory'] print(f"\nYou are currently in {current_room}.") print(f"Your inventory: {', '.join(inventory)}") if game_map[current_room]['Item']: print(f"You see a {game_map[current_room]['Item']} in this room.") directions = [d for d in game_map[current_room] if d != 'Item' and d != 'Villain'] print(f"Available directions: {', '.join(directions)}") def get_item():
current_room = player_status['Current Room'] item = game_map[current_room]['Item'] if item: print(f"You obtained the {item}!") player_status['Inventory'].append(item) game_map[current_room]['Item'] = None else: print("There is no item in this room.") def move(direction): current_room = player_status['Current Room'] if direction in game_map[current_room]: next_room = game_map[current_room][direction] # Check for the villain in the next room if 'Villain' in game_map[next_room]: print(f"Oh no! You encountered {game_map[next_room]['Villain']} and lost the game.") return False player_status['Current Room'] = next_room return True else: print("Invalid move. Please choose a valid direction.") return True def get_new_state(): return all(item in player_status['Inventory'] for item in ['Magic Asparagus', 'Xylophone', 'Hot Rod', 'Ballerina outfit', "Tina's tooth", 'Feather Wand']) \ and player_status['Current Room'] == "Bandit and Chili's Bedroom" def play_game(): display_intro() while True: display_status() command = input("Enter your command (Type 'help' for available commands): ").lower() if command == 'help': print("Available commands: move [direction], get item, quit") elif command.startswith('move'): direction = command.split(' ')[1].capitalize() if move(direction): print(f"You moved {direction}.") elif command == 'get item': get_item() elif command == 'quit': print("Thanks for playing! Goodbye.") break else: print("Invalid command. Type 'help' for available commands.") # Check for winning condition
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help