Advertisement
kevinbocky

main.py

Jan 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. class Room():
  2.  
  3. def __init__(self, room_name):
  4. self.name = room_name
  5. self.description = None
  6. self.character = None
  7. self.linked_rooms ={}
  8.  
  9. def set_name(self, room_name):
  10. self.name = room_name
  11.  
  12.  
  13. def set_description(self, room_description):
  14. self.description = room_description
  15.  
  16.  
  17. def get_description(self):
  18. return(self.description)
  19.  
  20. def describe(self):
  21. print(self.description)
  22.  
  23. def get_name(self):
  24. return (self.name)
  25.  
  26. def set_character(self, character):
  27. self.character = character
  28.  
  29. def get_character(self):
  30. return self.character
  31.  
  32.  
  33.  
  34. def linked_room(self, room_to_link, direction):
  35. self.linked_rooms[direction] = room_to_link
  36. print(self.name + " linked rooms : " + repr(self.linked_rooms))
  37.  
  38.  
  39.  
  40.  
  41. def get_details(self):
  42. for direction in self.linked_rooms:
  43. room = self.linked_rooms[direction]
  44. print(" The " + room.get_name() + " is " + direction)
  45.  
  46. def move(self, direction):
  47. if direction in self.linked_rooms:
  48. return self.linked_rooms[direction]
  49. else:
  50. print("you can't go that way")
  51. return self
  52.  
  53. ------------------------------------------------------
  54. from room import Room
  55. from character import Character
  56. from character import Enemy
  57.  
  58. kitchen = Room("Kitchen")
  59. kitchen.set_description("A dirty room full of rotten food and flies")
  60.  
  61. kitchen.describe()
  62.  
  63. dining = Room("Dining hall")
  64. dining.set_description("A wonderfull and large room for christmas dinner")
  65.  
  66. dining.describe()
  67.  
  68. ballroom = Room("Ballroom")
  69. ballroom.set_description("A wonderfull room for dancing and music")
  70.  
  71. ballroom.describe()
  72.  
  73. kitchen.linked_room(dining, "South")
  74. ballroom.linked_room(dining, "West")
  75. dining.linked_room(kitchen, "North")
  76. dining.linked_room(ballroom, "East")
  77. kitchen.get_details()
  78. ballroom.get_details()
  79.  
  80. dave = Enemy("Dave", "A smelly zombie")
  81.  
  82. dave.describe()
  83.  
  84. dave.talk()
  85.  
  86.  
  87. current_room = kitchen
  88. dining.set_character(dave)
  89. while True:
  90. print("\n")
  91. current_room.get_details()
  92.  
  93. inhabitant = current_room.get_character()
  94. if inhabitant is not None:
  95. inhabitant.describe()
  96.  
  97.  
  98. command = input("> ")
  99. current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement