Advertisement
kevinbocky

main2.py

Jan 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. #Week 4
  2. #class Character
  3.  
  4. class Character:
  5.  
  6.  
  7. def __init__ (self, char_name, char_description):
  8. self.name = char_name
  9. self.description = char_description
  10. self.conversation = None
  11. self.weakness = None
  12.  
  13.  
  14. def describe(self):
  15. print(self.name + " is here! ")
  16. print(self.description)
  17.  
  18. def occupation(self):
  19. print(self.name + " is in this room")
  20. print(self.description)
  21.  
  22. def set_weakness(self, weakness):
  23. self.weakness = weakness
  24.  
  25. def get_weakness(self):
  26. return self.weakness
  27.  
  28. def warning(self):
  29. print(self.name + self.description + " is wandering around the house")
  30.  
  31. def instant_loss(self):
  32. print(self.name + " doesn't want to fight with you")
  33. question = input(self.name + " wants a hug, do you want a hug? yes or no, or do you prefer to talk? ")
  34. if question == ("yes"):
  35. print("thanks")
  36. elif question == ("talk"):
  37. self.talk()
  38. else:
  39. print("nevermind, forget i asked")
  40. return True
  41.  
  42.  
  43.  
  44.  
  45.  
  46. def fight(self):
  47. print(self.name + " doesn't want to fight with you")
  48. question = input(self.name + " wants a hug, do you want a hug? yes or no, or do you prefer to talk? ")
  49. if question == ("yes"):
  50. print("thanks")
  51. elif question == ("talk"):
  52. self.talk()
  53. else:
  54. print("nevermind, forget i asked")
  55.  
  56.  
  57. def talk(self):
  58.  
  59. for loop in range(1):
  60. print("Hi i'm " + self.name)
  61. question1 = input("How are you? ")
  62. if question1 == "Good" or question1 == "good":
  63. print("OK nice")
  64. elif question1 == "Bad" or question1 == "bad":
  65. print("I'm sorry to hear that")
  66. else:
  67. print("I'm sorry i don't understand")
  68.  
  69.  
  70. class Enemy(Character):
  71.  
  72. def __init__ (self, char_name, char_description):
  73.  
  74. super(). __init__(char_name, char_description)
  75. self.weakness = None
  76.  
  77.  
  78. def set_weakness(self, weakness):
  79. self.weakness = weakness
  80.  
  81. def get_weakness(self):
  82. return self.weakness
  83.  
  84. def instant_loss(self):
  85. backpack_item = input("What will you fight with? ")
  86. print("You don't have that item, i will destroy you")
  87. print(" YOU LOST !!! ")
  88. return False
  89.  
  90. def fight(self):
  91. combat_item = input("What will you fight with? ")
  92. if combat_item == self.weakness:
  93. print("You fend " + self.name + " off with the " + combat_item)
  94. return True
  95. else:
  96. print(self.name + " crushes you, puny adventurer")
  97. return False
  98.  
  99.  
  100.  
  101. -------------------------------------------------------------------------------
  102. #class Room
  103. class Room():
  104.  
  105. def __init__(self, room_name):
  106. self.name = room_name
  107. self.description = None
  108. self.character = None
  109. self.item = None
  110. self.linked_rooms ={}
  111.  
  112. def set_name(self, room_name):
  113. self.name = room_name
  114.  
  115.  
  116. def set_description(self, room_description):
  117. self.description = room_description
  118.  
  119.  
  120. def get_description(self):
  121. return(self.description)
  122.  
  123. def describe(self):
  124. print(self.description)
  125.  
  126. def get_name(self):
  127. return (self.name)
  128.  
  129. def set_character(self, character):
  130. self.character = character
  131.  
  132. def get_character(self):
  133. return self.character
  134.  
  135. def set_item(self, item):
  136. self.item = item
  137.  
  138. def get_item (self):
  139. return self.item
  140.  
  141.  
  142.  
  143. def linked_room(self, room_to_link, direction):
  144. self.linked_rooms[direction] = room_to_link
  145. print(self.name + " linked rooms : " + repr(self.linked_rooms))
  146.  
  147.  
  148.  
  149.  
  150. def get_details(self):
  151. for direction in self.linked_rooms:
  152. room = self.linked_rooms[direction]
  153. print(" The " + room.get_name() + " is " + direction)
  154.  
  155. def move(self, direction):
  156. if direction in self.linked_rooms:
  157. return self.linked_rooms[direction]
  158. else:
  159. print("you can't go that way")
  160. return self
  161.  
  162. -----------------------------------------------------------------------------
  163. #class Item
  164. class Item():
  165.  
  166. def __init__ (self, name):
  167. self.name = name
  168. self.description = None
  169.  
  170.  
  171. def set_description(self, description):
  172. self.description = description
  173.  
  174. def get_description(self):
  175. return (self.description)
  176.  
  177. def describe(self):
  178. print(self.description)
  179.  
  180. def location(self):
  181. print(self.description)
  182. print(self.name + " is in this room ")
  183.  
  184. -----------------------------------------------------------------------------
  185. #main.py
  186. #added a lot print("") to keep the sentences apart in the python shell
  187. from room import Room
  188. from character import Character
  189. from character import Enemy
  190. from item import Item
  191.  
  192. backpack = []
  193.  
  194. kitchen = Room("Kitchen")
  195. kitchen.set_description("A dirty room full of rotten food and flies")
  196.  
  197. kitchen.describe()
  198.  
  199. dining = Room("Dining hall")
  200. dining.set_description("A wonderfull and large room for christmas dinner")
  201. print("")
  202. dining.describe()
  203. print("")
  204. ballroom = Room("Ballroom")
  205. print("")
  206. ballroom.set_description("A wonderfull room for dancing and music")
  207. print("")
  208. ballroom.describe()
  209. print("")
  210. kitchen.linked_room(dining, "South")
  211. print("")
  212. ballroom.linked_room(dining, "West")
  213. print("")
  214. dining.linked_room(kitchen, "North")
  215. print("")
  216. dining.linked_room(ballroom, "East")
  217. print("")
  218. kitchen.get_details()
  219. print("")
  220. ballroom.get_details()
  221. print("")
  222. dave = Enemy("Dave", " A smelly zombie ")
  223. print("")
  224. dave.describe()
  225. print("")
  226. dave.warning()
  227. print("")
  228. dennis = Character("Dennis", " A friendly skeleton ")
  229. print("")
  230. dennis.describe()
  231. print("")
  232. dennis.warning()
  233. print("")
  234. bacon = Item("Bacon")
  235. bacon.set_description(" A greasy piece of bacon")
  236. kitchen.set_item(bacon)
  237.  
  238. current_room = kitchen
  239. print("")
  240. dining.set_character(dave)
  241. ballroom.set_character(dennis)
  242. print("")
  243. dave.set_weakness("Bacon")
  244. print("")
  245. dennis.set_weakness("Cake")
  246. print("")
  247.  
  248.  
  249.  
  250.  
  251. while True:
  252. print("\n")
  253. print("You are in the " + current_room.name)
  254. print("")
  255.  
  256. suprise = current_room.get_item()
  257. if suprise is not None:
  258. suprise.location()
  259. obtain = input(" Do you want to take the " + suprise.name + " or leave it")
  260. if obtain == ("take"):
  261. backpack.append(suprise.name)
  262. current_room.item = None
  263. current_room.get_item()
  264.  
  265.  
  266. inhabitant = current_room.get_character()
  267. if inhabitant is not None:
  268. inhabitant.occupation()
  269. print("")
  270. if inhabitant.weakness in backpack:
  271. if inhabitant.fight() == False:
  272. break
  273.  
  274. else:
  275. if inhabitant.instant_loss() == False:
  276. break
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283. current_room.get_details()
  284. print("")
  285. command = input("> ")
  286. current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement