def printComponentTree(self, firstCall = True): # If function was invoked on current object, print initial message if firstCall: print("\nPrinting '"+self.noun+"' component tree:") iPrint(type(self).__name__, True, "|", "-> ") for componentType, componentList in self.components.items(): for component in componentList: # Pass False as argument to wsWrapper(component.printComponentTree, [False]) if firstCall: print("End of component tree.\n")
def describe(self, masterObject=None, firstCall = True): # Begin a traversal through the sub-objects for this object if firstCall: masterObject = self iPrint("Describing self...", True) description = "" # Iterate through registered 'describe' functions and call each #for key, func in self.descriptionFunctions.items(): # description += str(func()) + ". " if firstCall: description += self.initialDescription() + ". " description += self.describeComponentOverview(True, masterObject) else: if len(self.colours) > 0: description += " is " description += utils.listToCommaString(self.colours) + ". " else: description += random.choice([" has no colour" , " is colourless"]) + ". " # Describe components for componentType, componentList in self.components.items(): componentCounter = 0 for component in componentList: if len(componentList) < 10: componentCounter += 1 description += "The " + utils.intToOrdinalWord(componentCounter) #description += self.describeComponentOverview(False, masterObject) description += component.describe(masterObject, False) if firstCall: iPrint(description) iPrint("End of description \n") else: return description
def __init__(self): Describable.__init__(self) iPrint("Initiating Construction...")
def __init__(self): incWhitespace() iPrint("Initiating Seat...", True) baseDescribable.Construction.__init__(self) decWhitespace
def __init__(self): incWhitespace() iPrint("Initiating Bench...", True) Seat.__init__(self) decWhitespace()
import utils from utils import iPrint from utils import wsWrapper import baseDescribable import geometry import furniture import anatomy import creatures global whitespace iPrint("\nLet's Describe Something!\n", True) print("Creating a cube...") box = geometry.Cube() box.setNoun("box") box.addColours(["red", "orange"]) box.describe() #wsWrapper(box.printComponentTree) print("Creating a rabbit...") rabbit = creatures.Creature() rabbit.setNoun("rabbit") rabbit.addColours(["brown"]) rabbit.describe() print("Creating a humanoid...") percy = creatures.Humanoid() percy.setNoun("human") percy.setName("percy") percy.addColours(["pink"])