Advertisement
kaly1

Room_game V1.1

Feb 27th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #room class
  2. class Room():
  3. def __init__(self, room_name):
  4. self.name = room_name
  5. self.description = None
  6. self.linked_rooms = {}
  7.  
  8. def set_description(self,room_description):
  9. self.description = room_description
  10.  
  11. def get_description(self):
  12. return self.description
  13.  
  14. def describe(self):
  15. print(self.description)
  16.  
  17. def set_name(self, room_name):
  18. self.name = room_name
  19.  
  20. def get_name(self):
  21. return self.name
  22.  
  23.  
  24. def link_room(self, room_to_link, direction):
  25. self.linked_rooms[direction] = room_to_link
  26. #print( self.name + " linked rooms :" + repr(self.linked_rooms) )
  27.  
  28. def get_details(self):
  29. print("You are currently in the " + self.name)
  30. print("====================================")
  31. print(self.description)
  32. for direction in self.linked_rooms:
  33. room = self.linked_rooms[direction]
  34. print( "The " + room.get_name() + " is " + direction )
  35. print("\n")
  36.  
  37. def move(self, direction):
  38. if direction in self.linked_rooms:
  39. return self.linked_rooms[direction]
  40. else:
  41. print("You can't go that way")
  42. return self
  43.  
  44.  
  45. def move(self, direction):
  46. if direction in self.linked_rooms:
  47. return self.linked_rooms[direction]
  48. else:
  49. print("You can't go that way")
  50. return self
  51.  
  52.  
  53. #item class
  54. class Item():
  55. def __init__(self, item_name, item_color):
  56. self.name = item_name
  57. self.color = item_color
  58. self.carry = {}
  59.  
  60. def get_name():
  61. return self_name
  62.  
  63. def describe_item(self):
  64. print("The item is a " +self.name + ", and it's color is " + self.color)
  65.  
  66. def carry_item_room(self, room_its_in , carried):
  67. self.carry[carried] = room_its_in
  68.  
  69. def get_details(self):
  70. #carried = 0
  71. if carried == 1:
  72. print("You are currently carrying " + self.name + " and it's color is " + item_color)
  73.  
  74. else:
  75. print("You aren't carrying any items")
  76. carried = input("Would you like to take the " + self.name + "\nIf Yes press 'Y' and if No press 'N':")
  77.  
  78. if carried.lower() == "y":
  79. carried = 1
  80. print("You are now carrying the " + self.name + "\n")
  81. else:
  82. carried = 0
  83. print("OK " + "\n")
  84.  
  85. #main.py
  86. from room import Room
  87. from item import Item
  88.  
  89.  
  90. kitchen = Room ("Kitchen")
  91. kitchen.set_description("A dank and dirty room buzzing with flies.")
  92.  
  93. dining_hall = Room ("Dining Hall")
  94. dining_hall.set_description("A well lit room with lots of food")
  95.  
  96. ballroom = Room ("Ballroom")
  97. ballroom.set_description("A high ceiling room with a beautiful chandelier and lots of space")
  98.  
  99. kitchen.get_description()
  100.  
  101.  
  102. #kitchen.describe()
  103. #dining_hall.describe()
  104. #ballroom.describe()
  105.  
  106. kitchen.link_room(dining_hall, "south")
  107. dining_hall.link_room(kitchen , "north")
  108. dining_hall.link_room(ballroom , "west")
  109. ballroom.link_room(dining_hall, "east")
  110.  
  111.  
  112. #dining_hall.get_details()
  113. #kitchen.get_details()
  114. #ballroom.get_details()
  115.  
  116. current_room = kitchen
  117.  
  118. knife = Item ("Knife" , "Red")
  119.  
  120. current_item = knife
  121. carried = 0
  122.  
  123. while True:
  124. print("\n")
  125. current_item.describe_item()
  126. current_item.get_details()
  127. current_room.get_details()
  128. command = input(">")
  129. command = command.lower()
  130. current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement