Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # now 38
- from room import Room
- from item import Item
- from character import Enemy, Friend
- kitchen = Room("Kitchen")
- kitchen.set_description("A filthy, steamy room teeming with cockroaches and flies.")
- dining_hall = Room("Dining Hall")
- dining_hall.set_description("A large room with ornate golden decorations on the walls.")
- # dining_hall.describe() comment out for 2.7
- ballroom = Room("Ballroom")
- ballroom.set_description("A vast room with a shiny wooden floor; huge candlesticks guard the entrance.")
- # ballroom.describe() comment out for 2.7
- kitchen.link_room(dining_hall, "south")
- dining_hall.link_room(kitchen, "north")
- dining_hall.link_room(ballroom, "west")
- ballroom.link_room(dining_hall, "east")
- dave = Enemy("Dave", "A smelly zombie") # ref 3 6
- dave.set_conversation("Brrngrh... rgrhl... brains...")
- dave.set_weakness("cheese")
- dining_hall.set_character(dave)
- catrina = Friend("Catrina", "A friendly skeleton")
- catrina.set_conversation("Why hello there.")
- ballroom.set_character(catrina)
- current_room = kitchen #2.9 Start in Kitchen.
- dead = False
- while dead == False:
- # print("\n")
- current_room.get_details()
- inhabitant = current_room.get_character()
- if inhabitant is not None:
- inhabitant.describe()
- command = input("> ")
- # Check whether a direction was typed
- if command in ["north", "south", "east", "west"]:
- current_room = current_room.move(command)
- # Hmmm How to print on one line
- elif command == "talk":
- # Talk to the inhabitant - check whether there is one!
- if inhabitant is not None:
- inhabitant.talk()
- elif command == "fight":
- # You can check whether an object is an instance of a particular
- # class with isinstance() - useful! This code means
- # "If the character is an Enemy"
- if inhabitant is not None and isinstance(inhabitant, Enemy):
- # Fight with the inhabitant, if there is one
- print("What will you fight with?")
- fight_with = input()
- if inhabitant.fight(fight_with) == True:
- # What happens if you win?
- print("Hooray, you won the fight!")
- current_room.set_character(None)
- else:
- # What happens if you lose?
- print("Oh dear, you lost the fight.")
- print("That's the end of the game")
- dead = True
- else:
- print("There is no one here to fight with")
- elif command == "hug":
- if inhabitant is not None:
- if isinstance(inhabitant, Enemy):
- print("I wouldn't do that if I were you...")
- else:
- inhabitant.hug()
- else:
- print("There is no one here to hug :(")
- # Cannot find a way to output items yet.
Add Comment
Please, Sign In to add comment