TonyMo

main.py

Mar 14th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. # now 38
  2.  
  3. from room import Room
  4. from item import Item
  5. from character import Enemy, Friend
  6.  
  7. kitchen = Room("Kitchen")
  8. kitchen.set_description("A filthy, steamy room teeming with cockroaches and flies.")
  9.  
  10. dining_hall = Room("Dining Hall")
  11. dining_hall.set_description("A large room with ornate golden decorations on the walls.")
  12. # dining_hall.describe() comment out for 2.7
  13.  
  14. ballroom = Room("Ballroom")
  15. ballroom.set_description("A vast room with a shiny wooden floor; huge candlesticks guard the entrance.")
  16. # ballroom.describe() comment out for 2.7
  17.  
  18. kitchen.link_room(dining_hall, "south")
  19. dining_hall.link_room(kitchen, "north")
  20. dining_hall.link_room(ballroom, "west")
  21. ballroom.link_room(dining_hall, "east")
  22.  
  23. dave = Enemy("Dave", "A smelly zombie")     # ref 3 6
  24. dave.set_conversation("Brrngrh... rgrhl... brains...")
  25. dave.set_weakness("cheese")
  26. dining_hall.set_character(dave)
  27.  
  28. catrina = Friend("Catrina", "A friendly skeleton")
  29. catrina.set_conversation("Why hello there.")
  30. ballroom.set_character(catrina)
  31.  
  32. current_room = kitchen  #2.9 Start in Kitchen.
  33.  
  34. dead = False
  35. while dead == False:
  36.     # print("\n")
  37.     current_room.get_details()
  38.  
  39.     inhabitant = current_room.get_character()
  40.     if inhabitant is not None:
  41.         inhabitant.describe()
  42.  
  43.     command = input("> ")
  44.  
  45.     # Check whether a direction was typed
  46.     if command in ["north", "south", "east", "west"]:
  47.         current_room = current_room.move(command)
  48.     # Hmmm How to print on one line
  49.     elif command == "talk":
  50.         # Talk to the inhabitant - check whether there is one!
  51.         if inhabitant is not None:
  52.             inhabitant.talk()
  53.  
  54.     elif command == "fight":
  55.         # You can check whether an object is an instance of a particular
  56.         # class with isinstance() - useful! This code means
  57.         # "If the character is an Enemy"
  58.         if inhabitant is not None and isinstance(inhabitant, Enemy):
  59.             # Fight with the inhabitant, if there is one
  60.             print("What will you fight with?")
  61.             fight_with = input()
  62.             if inhabitant.fight(fight_with) == True:
  63.                 # What happens if you win?
  64.                 print("Hooray, you won the fight!")
  65.                 current_room.set_character(None)
  66.             else:
  67.                 # What happens if you lose?
  68.                 print("Oh dear, you lost the fight.")
  69.                 print("That's the end of the game")
  70.                 dead = True
  71.         else:
  72.             print("There is no one here to fight with")
  73.  
  74.     elif command == "hug":
  75.         if inhabitant is not None:
  76.             if isinstance(inhabitant, Enemy):
  77.                 print("I wouldn't do that if I were you...")
  78.             else:
  79.                 inhabitant.hug()
  80.         else:
  81.             print("There is no one here to hug :(")
  82.  
  83. # Cannot find a way to output items yet.
Add Comment
Please, Sign In to add comment