Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Room Game by https://pastebin.com/u/TTpocToXaKep
- # Define the Room class
- class Room:
- def __init__(self, name, description):
- self.name = name
- self.description = description
- self.items = []
- # Define the Player class
- class Player:
- def __init__(self, name, current_room):
- self.name = name
- self.current_room = current_room
- self.inventory = []
- def move_to_room(self, room):
- self.current_room = room
- print(f"You have moved to the {room.name}.")
- print(room.description)
- def pick_up_item(self, item):
- self.inventory.append(item)
- print(f"You have picked up the {item}.")
- def drop_item(self, item):
- self.inventory.remove(item)
- print(f"You have dropped the {item}.")
- # Initialize rooms
- kitchen = Room("Kitchen", "A well-lit room with a large table in the center.")
- living_room = Room("Living Room", "A cozy room with a fireplace and a sofa.")
- bedroom = Room("Bedroom", "A comfortable room with a large bed and a dresser.")
- # Initialize player
- player = Player("Player", kitchen)
- # Play the game
- while True:
- print(f"You are in the {player.current_room.name}. What do you want to do?")
- action = input("Move to another room, pick up item, or drop item: ")
- if action.lower() == "move to another room":
- room_name = input("Which room would you like to move to? ")
- if room_name.lower() == "kitchen":
- player.move_to_room(kitchen)
- elif room_name.lower() == "living room":
- player.move_to_room(living_room)
- elif room_name.lower() == "bedroom":
- player.move_to_room(bedroom)
- else:
- print("That room does not exist.")
- elif action.lower() == "pick up item":
- item = input("Which item would you like to pick up? ")
- player.pick_up_item(item)
- player.current_room.items.remove(item)
- elif action.lower() == "drop item":
- item = input("Which item would you like to drop? ")
- player.drop_item(item)
- player.current_room.items.append(item)
- else:
- print("Invalid action.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement