Advertisement
kevinbocky

main1.py

Jan 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. #Room class
  2. class Room():
  3.  
  4. def __init__(self, room_name):
  5. self.name = room_name
  6. self.description = None
  7. self.character = None
  8. self.linked_rooms ={}
  9.  
  10. def set_name(self, room_name):
  11. self.name = room_name
  12.  
  13.  
  14. def set_description(self, room_description):
  15. self.description = room_description
  16.  
  17.  
  18. def get_description(self):
  19. return(self.description)
  20.  
  21. def describe(self):
  22. print(self.description)
  23.  
  24. def get_name(self):
  25. return (self.name)
  26.  
  27. def set_character(self, character):
  28. self.character = character
  29.  
  30. def get_character(self):
  31. return self.character
  32.  
  33.  
  34.  
  35. def linked_room(self, room_to_link, direction):
  36. self.linked_rooms[direction] = room_to_link
  37. print(self.name + " linked rooms : " + repr(self.linked_rooms))
  38.  
  39.  
  40.  
  41.  
  42. def get_details(self):
  43. for direction in self.linked_rooms:
  44. room = self.linked_rooms[direction]
  45. print(" The " + room.get_name() + " is " + direction)
  46.  
  47. def move(self, direction):
  48. if direction in self.linked_rooms:
  49. return self.linked_rooms[direction]
  50. else:
  51. print("you can't go that way")
  52. return self
  53.  
  54. -----------------------------------------------------------------------------------
  55. #character class
  56. class Character:
  57.  
  58.  
  59. def __init__ (self, char_name, char_description):
  60. self.name = char_name
  61. self.description = char_description
  62. self.conversation = None
  63.  
  64. def describe(self):
  65. print(self.name + " is here! ")
  66. print(self.description)
  67.  
  68. def occupation(self):
  69. print(self.name + " is in this room")
  70. print(self.description)
  71.  
  72. def set_weakness(self):
  73. print(self.name + " has no weakness ")
  74.  
  75. def warning(self):
  76. print(self.name + self.description + " is wandering around the house")
  77.  
  78. def fight(self):
  79. print(self.name + " doesn't want to fight with you")
  80. question = input(self.name + " wants a hug, do you want a hug? yes or no, or do you prefer to talk? ")
  81. if question == ("yes"):
  82. print("thanks")
  83. elif question == ("talk"):
  84. self.talk()
  85. else:
  86. print("nevermind, forget i asked")
  87.  
  88.  
  89. def talk(self):
  90.  
  91. for loop in range(1):
  92. print("Hi i'm " + self.name)
  93. question1 = input("How are you? ")
  94. if question1 == "Good" or question1 == "good":
  95. print("OK nice")
  96. elif question1 == "Bad" or question1 == "bad":
  97. print("I'm sorry to hear that")
  98. else:
  99. print("I'm sorry i don't understand")
  100.  
  101.  
  102. class Enemy(Character):
  103.  
  104. def __init__ (self, char_name, char_description):
  105.  
  106. super(). __init__(char_name, char_description)
  107. self.weakness = None
  108.  
  109. def set_weakness(self, weakness):
  110. self.weakness = weakness
  111.  
  112. def get_weakness(self):
  113. return self.weakness
  114.  
  115. def fight(self):
  116. combat_item = input("What will you fight with? ")
  117. if combat_item == self.weakness:
  118. print("You fend " + self.name + " off with the " + combat_item)
  119. return True
  120. else:
  121. print(self.name + " crushes you, puny adventurer")
  122. return False
  123.  
  124. -------------------------------------------------------------------------
  125. #main.py
  126. #added a lot of print("") to make sure the tekst doesn't bunch up in the python shell
  127. from room import Room
  128. from character import Character
  129. from character import Enemy
  130.  
  131. kitchen = Room("Kitchen")
  132. kitchen.set_description("A dirty room full of rotten food and flies")
  133.  
  134. kitchen.describe()
  135.  
  136. dining = Room("Dining hall")
  137. dining.set_description("A wonderfull and large room for christmas dinner")
  138. print("")
  139. dining.describe()
  140. print("")
  141. ballroom = Room("Ballroom")
  142. print("")
  143. ballroom.set_description("A wonderfull room for dancing and music")
  144. print("")
  145. ballroom.describe()
  146. print("")
  147. kitchen.linked_room(dining, "South")
  148. print("")
  149. ballroom.linked_room(dining, "West")
  150. print("")
  151. dining.linked_room(kitchen, "North")
  152. print("")
  153. dining.linked_room(ballroom, "East")
  154. print("")
  155. kitchen.get_details()
  156. print("")
  157. ballroom.get_details()
  158. print("")
  159. dave = Enemy("Dave", "A smelly zombie")
  160. print("")
  161. dave.describe()
  162. print("")
  163. #dave.talk()
  164. #print("")
  165. dennis = Character("Dennis", "A friendly skeleton")
  166. print("")
  167. dennis.describe()
  168. print("")
  169. #dennis.talk()
  170. #print("")
  171.  
  172. current_room = kitchen
  173. print("")
  174. dining.set_character(dave)
  175. ballroom.set_character(dennis)
  176. print("")
  177. dave.set_weakness("cheese")
  178. print("")
  179.  
  180.  
  181.  
  182.  
  183. while True:
  184. print("\n")
  185. print("You are in the " + current_room.name)
  186. print("")
  187.  
  188. inhabitant = current_room.get_character()
  189. if inhabitant is not None:
  190. inhabitant.occupation()
  191. print("")
  192. if inhabitant.fight() == False:
  193. print("You lost")
  194. break
  195.  
  196.  
  197. current_room.get_details()
  198. print("")
  199. command = input("> ")
  200. current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement