from Interface import displayMessage from Utilities import verbalizeList, delQ class Person(object): def __init__(self, name, place): self.name = name self.place = place self.possessions = [] place.gain(self) def say(self, text): displayMessage("At " + self.place.name + ": " + self.name + " says -- " + text) def lookAround(self): otherItems = [o.name for o in self.place.contents if o != self] self.say("I see " + verbalizeList(otherItems, "nothing") + " and can go " + verbalizeList(self.place.exits(), "nowhere")) def listPossessions(self): stuff = [o.name for o in self.possessions] self.say("I have " + verbalizeList(stuff, "nothing")) def read(self, scroll): if self == scroll.owner: scroll.beRead() else: displayMessage(self.name + " does not have " + scroll.name) def haveFit(self): self.say("Yaaaah! I am upset!") def moveTo(self, newPlace): displayMessage(self.name + " moves from " + self.place.name + " to " + newPlace.name) self.place.lose(self) newPlace.gain(self) for p in self.possessions: self.place.lose(p) newPlace.gain(p) self.place = newPlace self.interactWith(self.otherPeopleAtSamePlace()) def go(self, direction): newPlace = self.place.neighborTowards(direction) if newPlace != None: self.moveTo(newPlace) else: displayMessage("you cannot go " + direction + " from " + self.place.name) def take(self, thing): if self == thing.owner: displayMessage(self.name + " already has " + thing.name) else: if thing.owner != None: owner = thing.owner owner.lose(thing) owner.haveFit() thing.owner = self self.possessions = [thing] + self.possessions self.say("I take " + thing.name) def lose(self, thing): if self != thing.owner: displayMessage(self.name + " doesn't have " + thing.name) else: thing.owner = None self.possessions = delQ(thing, self.possessions) self.say("I lose " + thing.name) def interactWith(self, people): if people != []: self.say("Hi " + verbalizeList([p.name for p in people], "no one")) for person in people: person.respondTo(self) def respondTo(self, newcomer): pass def otherPeopleAtSamePlace(self): return [o for o in self.place.contents if o != self and isinstance(o, Person)]