Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. #Adventure Game Code - Main File
  2. ########## Adventure Game - Training for Jaimie Summers ##########
  3. from room import Room
  4. from item import Item
  5. from food import Food
  6. from character import Enemy, Character, Friend
  7.  
  8. #########Players Back Pack - A list to store items in ###################
  9.  
  10. backpack = ["fists"]
  11. command_list = ["north", "east", "south", "west", "talk", "fight", "hug", "take", "eat"]
  12.  
  13. ###### Setting numbers of lives
  14. lives = 2
  15. enemies_beaten = 0
  16.  
  17. ##Food = None
  18.  
  19. ############ Setting up the rooms ##########
  20.  
  21. #Main Room
  22. mainroom = Room ("Intro")
  23. mainroom.set_description("Welcome to the 'Adventure Game'. In this adventure you must defeat the enemies and save 'Summers Mansion'. You are equipped only with your fists and have 2 lives, what can you do to save the Mansion? \nRead the clues and type commands to play the game. \n Type options to find out what choices you have \nTo start the game go south!")
  24. #Room 1 - The Kitchen
  25. kitchen = Room("Kitchen")
  26. kitchen.set_description("""A dank and dirty room buzzing with flies, there is a sink full of washing up, dirty clothes infront of the washing machine and a kitchen table in the centre of the room. The kitchen table has a newspaper, dirty coffee mug and the remains of someones breakfast.""")
  27. #Room 2 - The Dining Room
  28. dining_hall = Room("Dining Room")
  29. dining_hall.set_description("""A large room with ornate golden decorations on each wall. There is a large dining table with 10 chairs, golden cutlery and white plates are set for each dinner guest. There is a painting of a elderly woman on the wall.""")
  30. #Room 3 - The Ball Room
  31. ball_room = Room ("Ball Room")
  32. ball_room.set_description("""A vast room with a huge chandelier. To the south of the room are large doors each decorated with red velvet floor length curtains. There is a grand piano to the east of the room.""")
  33. #Room 4 - Cupboard 1
  34. cupboard_kitchen = Room("Kitchen Cupboard")
  35. cupboard_kitchen.set_description("""A small cupboard full of food, there is a whiff of stale and rotten food""")
  36.  
  37. ########### All rooms need to be linked ##########
  38. #Linking the rooms
  39. mainroom.link_room(kitchen, "south")
  40.  
  41. kitchen.link_room(dining_hall, "south")
  42. kitchen.link_room(cupboard_kitchen, "east")
  43. cupboard_kitchen.link_room(kitchen, "west")
  44. dining_hall.link_room(kitchen, "north")
  45. dining_hall.link_room(ball_room, "west")
  46. ball_room.link_room(dining_hall, "east")
  47.  
  48. ######### Putting enemy's and characters into the rooms ##########
  49. #Dave an Enemy in the Dining Room
  50. dave = Enemy("Dave", "A smelly zombie")
  51. dave.set_conversation("What's up, dude!")
  52. dave.set_weakness("cheese")
  53. dining_hall.set_character(dave)
  54.  
  55. #Catrina the friendly skeletan in the Ball Room ##########
  56. catrina = Friend("Catrina", "A friendly skeleton")
  57. catrina.set_conversation("Why hello there.")
  58. ball_room.set_character(catrina)
  59.  
  60.  
  61. ##### Food items in rooms #####
  62. crisps = Food ("Crisps")
  63. crisps.set_description("A half eaten bag of crisps, there is enough to gain some energy")
  64. cupboard_kitchen.set_food(crisps)
  65.  
  66. ##### Items in rooms #####
  67. cheese = Item ("Cheese")
  68. cheese.set_description ("A large block of smelly cheese")
  69. ball_room.set_item(cheese)
  70.  
  71. sword = Item ("Sword")
  72. sword.set_description ("A blunt sword!")
  73. kitchen.set_item(sword)
  74.  
  75.  
  76.  
  77. ##Current room to start the game##
  78. current_room = mainroom
  79.  
  80. ########## Dead means GAME OVER ##########
  81. dead = False
  82.  
  83. ########### Game loop ##########
  84. while dead == False:
  85.  
  86. print("\n")
  87. current_room.get_details()
  88.  
  89. inhabitant = current_room.get_character()
  90. if inhabitant is not None:
  91. inhabitant.describe()
  92.  
  93. item = current_room.get_item()
  94. if item is not None:
  95. item.describe()
  96.  
  97. food = current_room.get_food()
  98. if food is not None:
  99. food.describe()
  100.  
  101.  
  102.  
  103.  
  104.  
  105. command = input("Type your command here > ")
  106. ################################ Call commands
  107. if command == "options":
  108. print ("You can type the following options...")
  109. print (command_list)
  110. ################################ MOVE
  111. if command in ["north", "south", "east", "west"]:
  112. # Move in the given direction
  113. current_room = current_room.move(command)
  114. ################################# TALK
  115. elif command == "talk":
  116. # Talk to the inhabitant - check whether there is one!
  117. if inhabitant is not None:
  118. inhabitant.talk()
  119.  
  120. ################################## FIGHT
  121.  
  122. elif command == "fight":
  123. # Check whether an object is an instance of a particular
  124. if inhabitant == None or isinstance(inhabitant, Friend):
  125. print("There is no one here to fight with")
  126.  
  127. else:
  128. print("What will you fight with?")
  129. fight_with = input("Choose your weapon! >")
  130. print(backpack)
  131. if fight_with in backpack:
  132.  
  133. if inhabitant.fight(fight_with) == True:
  134. enemies_beaten = enemies_beaten + 1
  135. print ("You have beeaten " + str(enemies_beaten) + " enemies!")
  136. print("Hooray, you won the fight!")
  137. if enemies_beaten == 1:
  138. print ("You have been successful in saving Summers Mansion!!! Well done!")
  139. dead = True
  140. else:
  141. print ("Continue finding the enemies to save Summers Mansion!")
  142. dead = False
  143. current_room.set_character(None)
  144.  
  145. else:
  146. lives = lives - 1
  147. if lives == 0:
  148. print("That's the end of the game")
  149. dead = True
  150. else:
  151. print("Oh dear, you lost the fight. You now have " + str(lives))
  152.  
  153. else:
  154. print("Try again! You don't have a " + fight_with)
  155. #################################### HUG
  156. elif command == "hug":
  157. if inhabitant == None:
  158. print("There is no one here to hug :(")
  159. else:
  160. if isinstance(inhabitant, Enemy):
  161. print("I wouldn't do that if I were you...")
  162. else:
  163. inhabitant.hug()
  164. #################################### TAKE
  165. elif command == "take":
  166. if item == None:
  167. print ("There is nothing to collect here")
  168. else:
  169. print ("You have collected an item")
  170. backpack.append(item.get_name().lower())
  171. current_room.set_item(None)
  172. print (backpack)
  173.  
  174. #################################### EAT
  175. elif command == "eat":
  176. if food == None:
  177. print ("There is nothing to eat here!")
  178. else:
  179. print ("You have eaten...and now have")
  180. lives = lives + 1
  181. current_room.set_food(None)
  182. Food = None
  183. print ("You now have " + str(lives) + " lives")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement