def __init__(self): self.pc = PC() items.pc = self.pc ti.addTime(0,self.pc) self.pc.location = Room((10,10,9),True,"bedroom") self.pc.location.ceiling.descriptors.append("written on") self.pc.location.ceiling.hidden.append("writing") self.pc.location.ceiling.writing.append("\"pssst go North and look inside the purple bird\"") self.pc.location.ceiling.writing.append("\"gullible\"") self.pc.inventory.addItems([WritingUtensil()],self.pc) self.pc.location.addItems([Nightstand(["white"]),Dresser(),Wardrobe(),Bed()],self.pc) self.pc.location.items[0].spaces[2].door.lock() self.pc.location.items[0].spaces[2].door.examined = False c = Closet() self.pc.location.addDoor("north",c,True) b = Bathroom() self.pc.location.addDoor("east",b,True) hap = Room(self.pc.location.dimensions,True,"way out! Congratulations, you won") self.pc.location.addDoor("south",hap,True) com.findSearch("door",["south"],self.pc)[0].lock() com.findSearch("door",["south"],self.pc)[0].examined = False sh = Bookcase(4) book = Book("The Violet Canary") book.descriptors.append("hollow") book.hidden.append("bird") sp = Space("book","in the",book.dimensions,book.weight,True) sp.door.name = "cover" sp.addItems([Key(com.findSearch("door",["south"],self.pc)[0].ID)],self.pc) book.spaces.append(sp) def newOpen(): return Item.openUp(book) def newClose(): return Item.close(book) book.openUp = newOpen book.close = newClose c.addItems([sh],self.pc) while (sh.spaces[1].items[1].spaces[1].addItems([book],self.pc)=="capErr"): sh.spaces[1].items[1].spaces[1].items.pop() x = Book() def newRead(): return Book.read(x) + "\nIn a margin, someone has scrawled \"It says gullible on the ceiling!!\"" x.read = newRead self.pc.location.items[0].spaces[2].addItems([x],self.pc) self.pc.location.items[0].spaces[3].addItems([Compass()],self.pc) self.pc.location.items[1].spaces[4].addItems([Key(self.pc.location.items[0].spaces[2].door.ID)],self.pc)
def interpret(command,pc): #midPrin(str(command)) if command["verb"]=="save": if ti.loadingGame(): return "Save attempted." return saveGame(command["directObject"]) if command["verb"]=="load": if ti.loadingGame(): return "Load attempted." return loadGame(command["directObject"]) if not com.addTime(1,pc)==None: return com.addTime(1,pc) verb = command["verb"] adverb = command["adverb"] if not adverb == "": adverb = " very " + adverb do = command["directObject"] doMod = command["directObjectMod"] ido = command["indirectObject"] idoMod = command["indirectObjectMod"] location = command["location"] locationPrep = command["locationPrep"] locationMod = command["locationMod"] number = command["number"] directions = ["north","east","south","west","northern","eastern","southern","western"] compass = False doMod = reorder(doMod) idoMod = reorder(idoMod) locationMod = reorder(locationMod) if len(locationMod)==1 and location=="": location = locationMod[0] locationMod = [] for x in pc.inventory.items: if isinstance(x,Compass): compass = True break if not compass: for x in directions: if x in doMod or x in idoMod or x in locationMod or x==location: return "You can't find North without a compass or clear stars." if location=="me": location="" if " of" in locationPrep: locationPrep = locationPrep[0:locationPrep.index(" of")] doMod.append(locationPrep) locationPrep = "" if number=="everything": doMod.append(do) do="thing" number = "1000" if number=="all" or number=="every" or number=="each": number = "1000" if number=="many": number = "10" if number=="some" or number=="few" or number=="several": number = "3" if number=="couple": number = "2" while "" in locationMod: locationMod.remove("") while "" in doMod: doMod.remove("") while "" in idoMod: idoMod.remove("") if location==do and "other" in locationMod and not "other" in do: doMod.append("other") if location==ido and "other" in locationMod and not "other" in ido: idoMod.append("other") if number.isdigit() and int(number)==0: return "You ponder this philosophical dilemma." # if "my" in doMod and location=="" and not verb in directVerbs["put down"] and not verb in directVerbs["take"]: # doMod.remove("my") # location="inventory" # elif "my" in doMod: # doMod.remove("my") if verb=="" or verb=="don't": verb = "wait" Game.lastVerb = verb clothingList = ["clothes","clothing","shirt","pants","pair of pants","shoe","jeans","pair of jeans","hat","glove","tie","dress","skirt","shorts","sock","scarf","jacket","coat","sneaker","sweater","pair of dress pants"] y = len(clothingList) for x in range(y): clothingList.append(plural(clothingList[x])) exList = ["sit","stand"] if location in clothingList and not verb in exList: verb+=" " + locationPrep do = location doMod = locationMod location = "" locationMod = [] locationPrep = "" if do in clothingList and (locationPrep=="off" or locationPrep =="on") and location=="": verb +=" " + locationPrep locationPrep = "" if verb=="search" and locationPrep=="": if location=="room" or location==pc.location.name: verb = "look" do = "" location = "" else: verb = "open" do = location location = "" if verb=="swear" or verb in locationVerbs["swear"]: if com.search("bar of soap",[],pc.inventory,pc)[0]==-1: meh =pc.inventory.addItems([Item("bar of soap",(1/3.0,1/4.0,1/6.0),.2,[Space("bar of soap","on the",(1/2.5,1/3.5,1/5.5),3)])],pc) if meh==None: return "I'll just pretend I didn't hear that.\nA bar of soap has been added to your inventory." return "I'll just pretend I didn't hear that." if verb=="eldritch blast": verb = "cast" ido = "eldritch" do = "blast" if verb=="move" and locationPrep=="" and not location=="" and not location in locations: verb = "push" do = location elif verb=="move" and not do == "": verb = "push" if verb=="use": #ALL THE USING if do=="": return "You must specify an item to use." if do=="key": verb = "unlock" do = location doMod = locationMod location = "" locationMod = [] locationPrep = "" elif do=="toilet": space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." if space=="": space = pc.location t = com.searchMany("toilet",doMod,space,pc) if len(t.keys())>0: return "You use the toilet." return "You can't find a" + makeListSpaces(doMod) + "toilet " + space.prep + " " + space.name + "." elif do in ["sink","shower","bath","bathtub"]: verb = "wash" location = do do = "" locationMod = doMod doMod = [] locationPrep = "in" elif do in ["soap","bar of soap"]: verb = "wash" ido = do idoMod = doMod do= location doMod = locationMod location = "" locationMod = [] locationPrep = "" elif do=="mirror" or do=="glass": verb = "look" location = "mirror" locationMod = doMod do = "" doMod = [] else: return "You aren't sure how to use a " + do + "." if verb=="think" or verb in selfVerbs["think"]: return com.think(pc,verb,adverb) if verb=="scream" or verb in talkVerbs["scream"]: return "Your blood-curdling shriek fills the air." if verb=="laugh" or verb in selfVerbs["laugh"]: if "evilly" in adverb or "maniacally" in adverb or "creepily" in adverb: return "Evil, maniacal pleasure emanates from your very soul, chilling the air around you." return "Joyous laughter bursts forth from your very being, lifting the spirits of those around you. Except Jim. There's no hope for Jim." if verb=="climb": if "on" in locationPrep: verb = "climb on" else: verb = "go" if verb=="climb on" or verb in locationVerbs["climb on"]: verb="go" locationPrep="on" if not do=="": location=do if verb=="enter" or verb in locationVerbs["enter"]: verb = "move" if location=="" and not do=="": locationPrep = "in" locationMod=doMod location=do if verb=="hide" or verb in locationVerbs["hide"]: if do=="": verb = "move" else: verb = "put" if verb=="push" and not location=="": verb = "put" if verb=="turn" or verb in locationVerbs["turn"]: return com.turn(pc,location,locationMod,locationPrep) if verb=="wash" or verb in directVerbs["wash"]: space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." if isPlural(do) and number==-1: number = 1000 if number>1: x = 0 done = None final = "" while x<number: if not "other" in doMod: doMod.append("other") new= com.wash(pc,do,doMod,ido,idoMod,space) #print "test",new if "don't see" in new: return new x+=1 if done==com.recentItems[-1]: break done = com.recentItems[-1] if not repeats(com.recentItems[len(com.recentItems)-x:len(com.recentItems)]): break if not x==1: midPrin(final) final=new return final return com.wash(pc,do,doMod,ido,idoMod,space) if verb=="stack" or verb in directVerbs["stack"]: space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." number = int(number) if isPlural(do) and number==-1: number = 1000 return com.stack(pc,do,doMod,space,number) if verb=="take off" or verb in directVerbs["take off"]: if isPlural(do) and int(number)==-1: number = 1000 if int(number)>1: x = 0 final = "" while x<number: new= com.takeOff(pc,do,doMod) if "aren't wearing" in new: if x==0: return new break x+=1 if not x==1: midPrin(final) final=new return final return com.takeOff(pc,do,doMod) if verb=="put down" or verb in directVerbs["put down"]: if do==""and number.isdigit() and number<1000: return "You must specify an object to " + verb + "." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." if isPlural(do) and int(number)==-1: number = "1000" if number.isdigit() and abs(int(number))>1: return com.dropMany(pc,verb,adverb,do,doMod,abs(int(number)),space) return com.drop(pc,verb,adverb,do,doMod,space) if verb=="take" or verb in directVerbs["take"]: if do=="" and number.isdigit() and number<1000: return "You must specify an object to " + verb + "." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." if isPlural(do) and int(number)==-1: number = "1000" if number.isdigit() and abs(int(number))>1: return com.takeMany(pc,verb,adverb,do,doMod,abs(int(number)),space) return com.take(pc,verb,adverb,do,doMod,space) if verb=="die" or verb in selfVerbs["die"]: return com.die() if verb=="cheat" or verb in selfVerbs["cheat"]: return Game.rant if verb=="live" or verb in selfVerbs["live"]: return "Good job. You deserve a medal or something." if verb=="wait": return com.wait(pc,number,do) if verb=="leave" or verb in selfVerbs["leave"]: return com.escape(pc) if verb=="cry" or verb in selfVerbs["cry"]: return com.cry(verb,adverb) if verb=="cast": if do=="blast" and ido=="eldritch": st = pc.strength pc.strength = 50 r = "You shout and wave your arms, and a surge of force attacks everything in front of you!" for y in range(10): if not "can't reach" in r: midPrin(r) r = com.damage(pc,"thing",["other"],pc.location,"blast","") pc.strength = st return r return "What do you think you are, a mage?" if verb=="dance" or verb in selfVerbs["dance"]: return com.dance(verb,adverb) if verb=="go" or verb in locationVerbs["go"]: if location=="" and not locationMod==[]: space = com.findLocation(pc,locationMod[0],locationPrep,[],True) else: space = com.findLocation(pc,location,locationPrep,locationMod,True) if space=="LockedErr": return "There's a locked door in your way." if space=="WallErr": return "There's a wall there." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " " + locationPrep + " the " + location + "." return com.move(pc,space) if verb=="sing" or verb in selfVerbs["sing"]: return com.sing(verb,adverb) if verb=="sleep" or verb in locationVerbs["sleep"]: timekeeps = ["minute","hour","second","century","eon","millenia","milleniums","decade","week"] for x in timekeeps[0:9]: timekeeps.append(plural(x)) if location in timekeeps and do=="": do = location location = "" space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " " + locationPrep + " the " + location + "." return com.sleep(pc,number,do,space) if verb=="jump" or verb in locationVerbs["jump"]: return com.jump(verb,adverb) if verb=="find" or verb in directVerbs["find"]: return com.find(pc,do,doMod) if verb=="push" or verb in directVerbs["push"]: return com.push(pc,do,doMod) if verb=="throw" or verb in directVerbs["throw"]: if do=="": return "You must specify an object to " + verb + "." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." return com.throw(pc,do,doMod,space,ido,idoMod) if verb=="examine" or verb in directVerbs["examine"]: if do=="" and int(number)<=1: if not location=="": verb="look" else: return "You must specify something to examine." elif int(number)<=1 and not (isPlural(do) and int(number)==-1): return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.examine,number) else: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.examineGeneral,number) if verb=="write" or verb in directVerbs["write"]: if location=="": return "You must specify something to " + verb + " on." return com.write(pc,ido,idoMod,location,locationMod,do) if verb=="draw" or verb in directVerbs["draw"]: if location=="": return "You must specify something to " + verb + " on." return com.draw(pc,ido,idoMod,location,locationMod,do,doMod) if verb=="look" or verb in locationVerbs["look"]: if locationPrep=="in" and location=="mirror": return direct(pc,"","",[],location,locationMod,"look at",com.examine,number) if do=="around": do="" if location=="around": location = "" space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " " + locationPrep + " the " + location + "." if space==pc.location: space = "" if not space=="" and not space==pc.location and isinstance(space,Room): return "Peering in, " + com.look(pc,space,True) + "." return com.look(pc,space) if verb=="touch" or verb in directVerbs["touch"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.touch,number) if verb=="read" or verb in directVerbs["read"]: if do=="writing" or do=="words": do = location doMod = locationMod location = "" locationMod = [] if do=="": do ="it" return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.read,number) if verb=="eat" or verb in directVerbs["eat"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.eat,number) if verb=="smell" or verb in directVerbs["smell"]: if do=="": return "You don't smell much of anything." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " " + locationPrep + " the " + location + "." return com.smell(pc,do,doMod,space) if verb=="taste" or verb in directVerbs["taste"]: if do=="": return "The air tastes stale." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " " + locationPrep + " the " + location + "." return com.taste(pc,do,doMod,space) if verb=="break" or verb in directVerbs["break"] or verb=="attack" or verb in directVerbs["attack"]: if do=="": return "You must specify an object to " + verb + "." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." return com.damage(pc,do,doMod,space,verb,adverb,ido,idoMod) if verb=="open" or verb in directVerbs["open"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.openSesame,number) if verb=="close" or verb in directVerbs["close"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.close,number) if verb=="lock" or verb in directVerbs["lock"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.lock,number) if verb=="unlock" or verb in directVerbs["unlock"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.unlock,number) if verb=="listen to" or verb in directVerbs["listen to"]: return direct(pc,location,locationPrep,locationMod,do,doMod,verb,com.listenTo,number) if verb=="wear" or verb in directVerbs["wear"]: if do=="": do="it" if len(com.recentItems)==0: return "You must specify an object to " + verb + "." space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": return "You can't " + verb + " anything " + locationPrep + " the " + location + "." if isPlural(do) and int(number)==-1: number = 1000 if int(number)>1: x = 0 final = "" while x<number: new= com.wear(pc,do,doMod) if "don't see" in new: break if "already wearing" in new: break x+=1 if not x==1: midPrin(final) final=new if final=="": return com.wear(pc,do,doMod) return final return com.wear(pc,do,doMod,space) if verb=="sit" or verb in locationVerbs["sit"]: space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": if locationPrep in preps["on"]: oldLocation = "" k = com.findSearch(location,[],pc) oldLocation = k[1] space = oldLocation else: return "You can't fit anything " + locationPrep + " the " + location + "." return com.sit(pc,space) if verb=="stand" or verb in locationVerbs["stand"]: space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": if locationPrep in preps["on"]: oldLocation = "" k = com.findSearch(location,[],pc) oldLocation = k[1] space = oldLocation else: return "You can't fit anything " + locationPrep + " the " + location + "." return com.stand(pc,space) if verb=="lay" or verb in locationVerbs["lay"]: space = com.findLocation(pc,location,locationPrep,locationMod) if space=="WallErr": return "There's a wall there." if space=="LockedErr": return "There's a locked door in your way." if space=="ItemErr": return "You can't find " + aan(location) + "." if space=="PrepErr": if locationPrep in preps["on"]: oldLocation = "" k = com.findSearch(location,[],pc) oldLocation = k[1] space = oldLocation else: return "You can't fit anything " + locationPrep + " the " + location + "." return com.layDown(pc,space) if verb=="inventory" or verb in selfVerbs["inventory"]: return com.inventory(pc) return "You aren't sure how to " + verb + "."