bensimmo

OOP 4.7 main.py

Jan 13th, 2021
715
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from room import Room
  2. from item import Item
  3. from rpginfo import RPGInfo
  4. from character import Character, Enemy, Animal
  5.  
  6. # game settings
  7. game_name = "Adventure around the house"
  8. RPGInfo.author = "Raspberry Pi Foundation and Me"
  9.  
  10. # setup rooms
  11. kitchen = Room("kitchen")
  12. kitchen.description= "a dank and dirty room buzzing with flies"
  13.  
  14. ballroom = Room("ballroom")
  15. ballroom.description = "a large clean room with a sparkling floor"
  16.  
  17. dining_hall = Room("dining hall")
  18. dining_hall.description = "a dimly lit room with scraps of food surrounding a table"
  19.  
  20. office = Room("office")
  21. office.description = "a small room with bright LED lighting, looks a nice place to work"
  22.  
  23. # setup items
  24. table = Item("table")
  25. table.set_description("round and has places for four people")
  26. table.set_mass("heavy")
  27. table.set_material("metal")
  28.  
  29. sword = Item("sword", "light", "wood")
  30. sword.set_description("long and pointy with a small handle, it has lots of small holes in it")
  31.  
  32. cheese = Item("cheese", "light", "cheese")
  33. cheese.set_description("Smelly, a little bit gooey")
  34.  
  35. metal_key = Item("metal key", "heavy", "iron")
  36. metal_key.set_description("large rusty old key, seems a little bent")
  37.  
  38. plastic_key = Item("flimsy key", "light", "plastic")
  39. plastic_key.set_description("a 3D printed key, red in colour.  You can see the layer lines")
  40.  
  41. #setup room maze
  42. kitchen.link_room(dining_hall, "south")
  43. ballroom.link_room(dining_hall, "east")
  44. dining_hall.link_room(kitchen, "north")
  45. dining_hall.link_room(ballroom, "west")
  46. dining_hall.link_room(office, "south")
  47. office.link_room(dining_hall, "north")
  48.  
  49.  
  50. #setup characters
  51. dave = Enemy("Dave", "A smelly zombie")
  52. dave.set_conversation("Brrlgrh... rgrhl... brains...")
  53. dave.set_weakness("sword")
  54.  
  55. pam = Enemy("Pam", "A glowing zombie")
  56. pam.set_conversation("foood....fooood.")
  57. pam.set_weakness("sword")
  58. pam.set_item("metal_key")
  59.  
  60. fred = Character("Fred", "Busy making computer games")
  61. fred.set_conversation("Sorry, to busy, send me an email")
  62. fred.set_item("plastic_key")
  63.  
  64. cat = Animal("Cat", "Laid down, half sleeping. Acts like it owns the place")
  65. cat.set_huggable(True)
  66. cat.set_food("cheese")
  67. cat.set_hug_sound("purrrrr")
  68.  
  69.  
  70. #setup character locations
  71. dining_hall.character = dave
  72. office.character = fred
  73. kitchen.character = cat
  74. ballroom.character = pam
  75.  
  76.  
  77.  
  78. #set starting room
  79. current_room = kitchen
  80.  
  81.  
  82. #start game
  83. alive = True
  84. the_game = RPGInfo(game_name)
  85. the_game.welcome()
  86. RPGInfo.info()
  87.  
  88. print(f"There are {str(Room.number_of_rooms)} rooms to explore.")
  89.  
  90. while alive:
  91.     current_room.get_details()
  92.     inhabitant = current_room.character
  93.     if inhabitant is not None:
  94.         inhabitant.describe()
  95.    
  96.     # loop so we don't display room details after every action.
  97.     while True:
  98.         command = input(" What would would you like to do? >")
  99.        
  100.         # Check whether a direction was typed
  101.         if command in ["north", "south", "east", "west"]:
  102.             in_room = current_room
  103.             current_room = current_room.move(command)
  104.             if current_room == in_room:
  105.                 pass
  106.             else:
  107.                 break # Moved so we need to start the main loop again
  108.        
  109.         elif command == "talk":
  110.             if inhabitant is not none:
  111.                 inhabitant.talk()
  112.        
  113.         elif command == "fight":
  114.             if isinstance(inhabitant, Enemy):
  115.                 fight_item = input(" What item do you want to use >?")
  116.                 if inhabitant.fight(fight_item):
  117.                     current_room.character = None
  118.                 else:
  119.                     print("You died")
  120.                     alive = False
  121.                     break # You're dead, so no more action, break this while and the the main while using above
  122.             else:
  123.                 print("You cannot fight anyone")
  124.  
  125.         elif command == "info":
  126.             break
  127.        
  128.         elif command == "feed":
  129.             if isinstance(inhabitant, Animal):
  130.                 feed_item = input(" What item do you want to use >?")
  131.                 if inhabitant.feed(feed_item):
  132.                     current_room.character = None
  133.                     print(f"{inhabitant.name} has left the room")
  134.             else:
  135.                 print("you cannot feed anyone")
  136.  
  137.         elif command == "hug":
  138.             if isinstance(inhabitant, Animal):
  139.                 inhabitant.hug()
  140.            
  141.             elif isinstance(inhabitant, Enemy):
  142.                 print(f"{inhabitant.name} is an Enemy")
  143.            
  144.             else:
  145.                 print("nothing to hug")
  146.                
  147.         elif command == "steal":
  148.             if inhabitant is not None:
  149.                 steal_item = input(" What item do you want to steal >?")
  150.                 if isinstance(inhabitant, Enemy): #and inhabitant.item is not None:
  151.                     if inhabitant.steal(steal_item) is False:
  152.                         alive = False
  153.                         break # You're dead, so no more action, break this while and the the main while using above
  154.                 else:
  155.                     print("you cannot steal from them")
  156.            
  157.         else:
  158.             print("that is not a command")
  159.  
  160. RPGInfo.credits()
RAW Paste Data