Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #room class
- class Room():
- def __init__(self, room_name):
- self.name = room_name
- self.description = None
- self.linked_rooms = {}
- def set_description(self,room_description):
- self.description = room_description
- def get_description(self):
- return self.description
- def describe(self):
- print(self.description)
- def set_name(self, room_name):
- self.name = room_name
- def get_name(self):
- return self.name
- def link_room(self, room_to_link, direction):
- self.linked_rooms[direction] = room_to_link
- #print( self.name + " linked rooms :" + repr(self.linked_rooms) )
- def get_details(self):
- print("You are currently in the " + self.name)
- print("====================================")
- print(self.description)
- for direction in self.linked_rooms:
- room = self.linked_rooms[direction]
- print( "The " + room.get_name() + " is " + direction )
- print("\n")
- def move(self, direction):
- if direction in self.linked_rooms:
- return self.linked_rooms[direction]
- else:
- print("You can't go that way")
- return self
- def move(self, direction):
- if direction in self.linked_rooms:
- return self.linked_rooms[direction]
- else:
- print("You can't go that way")
- return self
- #item class
- class Item():
- def __init__(self, item_name, item_color):
- self.name = item_name
- self.color = item_color
- self.carry = {}
- def get_name():
- return self_name
- def describe_item(self):
- print("The item is a " +self.name + ", and it's color is " + self.color)
- def carry_item_room(self, room_its_in , carried):
- self.carry[carried] = room_its_in
- def get_details(self):
- #carried = 0
- if carried == 1:
- print("You are currently carrying " + self.name + " and it's color is " + item_color)
- else:
- print("You aren't carrying any items")
- carried = input("Would you like to take the " + self.name + "\nIf Yes press 'Y' and if No press 'N':")
- if carried.lower() == "y":
- carried = 1
- print("You are now carrying the " + self.name + "\n")
- else:
- carried = 0
- print("OK " + "\n")
- #main.py
- from room import Room
- from item import Item
- kitchen = Room ("Kitchen")
- kitchen.set_description("A dank and dirty room buzzing with flies.")
- dining_hall = Room ("Dining Hall")
- dining_hall.set_description("A well lit room with lots of food")
- ballroom = Room ("Ballroom")
- ballroom.set_description("A high ceiling room with a beautiful chandelier and lots of space")
- kitchen.get_description()
- #kitchen.describe()
- #dining_hall.describe()
- #ballroom.describe()
- kitchen.link_room(dining_hall, "south")
- dining_hall.link_room(kitchen , "north")
- dining_hall.link_room(ballroom , "west")
- ballroom.link_room(dining_hall, "east")
- #dining_hall.get_details()
- #kitchen.get_details()
- #ballroom.get_details()
- current_room = kitchen
- knife = Item ("Knife" , "Red")
- current_item = knife
- carried = 0
- while True:
- print("\n")
- current_item.describe_item()
- current_item.get_details()
- current_room.get_details()
- command = input(">")
- command = command.lower()
- current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement