Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Week 4
- #class Character
- class Character:
- def __init__ (self, char_name, char_description):
- self.name = char_name
- self.description = char_description
- self.conversation = None
- self.weakness = None
- def describe(self):
- print(self.name + " is here! ")
- print(self.description)
- def occupation(self):
- print(self.name + " is in this room")
- print(self.description)
- def set_weakness(self, weakness):
- self.weakness = weakness
- def get_weakness(self):
- return self.weakness
- def warning(self):
- print(self.name + self.description + " is wandering around the house")
- def instant_loss(self):
- print(self.name + " doesn't want to fight with you")
- question = input(self.name + " wants a hug, do you want a hug? yes or no, or do you prefer to talk? ")
- if question == ("yes"):
- print("thanks")
- elif question == ("talk"):
- self.talk()
- else:
- print("nevermind, forget i asked")
- return True
- def fight(self):
- print(self.name + " doesn't want to fight with you")
- question = input(self.name + " wants a hug, do you want a hug? yes or no, or do you prefer to talk? ")
- if question == ("yes"):
- print("thanks")
- elif question == ("talk"):
- self.talk()
- else:
- print("nevermind, forget i asked")
- def talk(self):
- for loop in range(1):
- print("Hi i'm " + self.name)
- question1 = input("How are you? ")
- if question1 == "Good" or question1 == "good":
- print("OK nice")
- elif question1 == "Bad" or question1 == "bad":
- print("I'm sorry to hear that")
- else:
- print("I'm sorry i don't understand")
- class Enemy(Character):
- def __init__ (self, char_name, char_description):
- super(). __init__(char_name, char_description)
- self.weakness = None
- def set_weakness(self, weakness):
- self.weakness = weakness
- def get_weakness(self):
- return self.weakness
- def instant_loss(self):
- backpack_item = input("What will you fight with? ")
- print("You don't have that item, i will destroy you")
- print(" YOU LOST !!! ")
- return False
- def fight(self):
- combat_item = input("What will you fight with? ")
- if combat_item == self.weakness:
- print("You fend " + self.name + " off with the " + combat_item)
- return True
- else:
- print(self.name + " crushes you, puny adventurer")
- return False
- -------------------------------------------------------------------------------
- #class Room
- class Room():
- def __init__(self, room_name):
- self.name = room_name
- self.description = None
- self.character = None
- self.item = None
- self.linked_rooms ={}
- def set_name(self, room_name):
- self.name = room_name
- def set_description(self, room_description):
- self.description = room_description
- def get_description(self):
- return(self.description)
- def describe(self):
- print(self.description)
- def get_name(self):
- return (self.name)
- def set_character(self, character):
- self.character = character
- def get_character(self):
- return self.character
- def set_item(self, item):
- self.item = item
- def get_item (self):
- return self.item
- def linked_room(self, room_to_link, direction):
- self.linked_rooms[direction] = room_to_link
- print(self.name + " linked rooms : " + repr(self.linked_rooms))
- def get_details(self):
- for direction in self.linked_rooms:
- room = self.linked_rooms[direction]
- print(" The " + room.get_name() + " is " + direction)
- def move(self, direction):
- if direction in self.linked_rooms:
- return self.linked_rooms[direction]
- else:
- print("you can't go that way")
- return self
- -----------------------------------------------------------------------------
- #class Item
- class Item():
- def __init__ (self, name):
- self.name = name
- self.description = None
- def set_description(self, description):
- self.description = description
- def get_description(self):
- return (self.description)
- def describe(self):
- print(self.description)
- def location(self):
- print(self.description)
- print(self.name + " is in this room ")
- -----------------------------------------------------------------------------
- #main.py
- #added a lot print("") to keep the sentences apart in the python shell
- from room import Room
- from character import Character
- from character import Enemy
- from item import Item
- backpack = []
- kitchen = Room("Kitchen")
- kitchen.set_description("A dirty room full of rotten food and flies")
- kitchen.describe()
- dining = Room("Dining hall")
- dining.set_description("A wonderfull and large room for christmas dinner")
- print("")
- dining.describe()
- print("")
- ballroom = Room("Ballroom")
- print("")
- ballroom.set_description("A wonderfull room for dancing and music")
- print("")
- ballroom.describe()
- print("")
- kitchen.linked_room(dining, "South")
- print("")
- ballroom.linked_room(dining, "West")
- print("")
- dining.linked_room(kitchen, "North")
- print("")
- dining.linked_room(ballroom, "East")
- print("")
- kitchen.get_details()
- print("")
- ballroom.get_details()
- print("")
- dave = Enemy("Dave", " A smelly zombie ")
- print("")
- dave.describe()
- print("")
- dave.warning()
- print("")
- dennis = Character("Dennis", " A friendly skeleton ")
- print("")
- dennis.describe()
- print("")
- dennis.warning()
- print("")
- bacon = Item("Bacon")
- bacon.set_description(" A greasy piece of bacon")
- kitchen.set_item(bacon)
- current_room = kitchen
- print("")
- dining.set_character(dave)
- ballroom.set_character(dennis)
- print("")
- dave.set_weakness("Bacon")
- print("")
- dennis.set_weakness("Cake")
- print("")
- while True:
- print("\n")
- print("You are in the " + current_room.name)
- print("")
- suprise = current_room.get_item()
- if suprise is not None:
- suprise.location()
- obtain = input(" Do you want to take the " + suprise.name + " or leave it")
- if obtain == ("take"):
- backpack.append(suprise.name)
- current_room.item = None
- current_room.get_item()
- inhabitant = current_room.get_character()
- if inhabitant is not None:
- inhabitant.occupation()
- print("")
- if inhabitant.weakness in backpack:
- if inhabitant.fight() == False:
- break
- else:
- if inhabitant.instant_loss() == False:
- break
- current_room.get_details()
- print("")
- command = input("> ")
- current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement