def parseCMD(msg): cmds = msg.split(); cmd = SearchableString(len(cmds) > 0 and cmds[0] or "") curArea = Areas[States["area"]] if cmd == "load": SaveName = len(cmds) > 1 and cmds[1] or raw_input("Save name: >") if SaveName: NewStates, NewInventory = dson.load(open(SaveName+".dson","r")) States.clear(); Inventory.clear() States.update(NewStates); Inventory.update(NewInventory) print("== Progress loaded from '"+SaveName+".dson' ==") elif cmd == "save": SaveName = len(cmds) > 1 and cmds[1] or raw_input("Save name: >") if SaveName: dson.dump((States, Inventory), open(SaveName+".dson","w"), indent=2) print("== Progress saved to '"+SaveName+".dson' ==") elif cmd in ("clear", "cls"): consolelib.clear() print(" ") elif cmd in ("h", "help"): print ("You consider for a moment the verbs you've learned:\n" "go/enter [room]\n" "back/return/last goes to previous room\n" "look/examine/view [object]\n" "grab/pick/get/take [object]\n" "use [object] on [object]\n" "lockpick [object]\n" "time\n" "map\n" "i/inventory\n" "save [filename]\n" "load [filename]") elif cmd in ("i", "inventory"): if "backpack" in States: print("You stop and look at the contents of your leather backpack:") for item in Inventory.values(): print("\t- "+item) print("\t- Lockpicking pins: "+str(States["pins"])) print("\t- Money: $%.2f" % States["money"]) else: say("There isn't anything in your pockets. You try to start missions light.") elif cmd in ("time", "watch"): if "watch" in States: say("You glance at your Booker's display of the current local time: "+getTime()) else: say("Your booker's internal clock hasn't been configured for this locale, and is still displaying your home time: " + str(int(States["time"]/1.44))) elif cmd in ("map",): say("You review your Booker's spatial layouting program.") with consolelib.lineByLine(0.03): openMap(curArea.zone) elif cmd == "" or (cmd in LOOK and len(cmds) == 1): curArea.describe() elif cmd in ("back", "return", "last") or "go back" in msg: if "lastarea" in States: setArea(States["lastarea"]) else: say("You just walked into the building, you can't leave yet.") elif cmd in GO: curArea.GO(cmd, cmds, msg) elif cmd in LOOK: if ("booker", "arm") in msg: say("The Booker on your arm is an advanced Personal Information Processor. The 2000 model premiered in the year 8AA, and is primarily built from salvaged Old world components modified to support an MF power core. Its many features include a watch, 3D scanner, 1w laser pointer (doubles as a microwelder), journal logging, and flying toasters screensaver.") elif ("keyhole") in msg: say("You peer through the door's keyhole, but can't see anything, since there's a lock in the way.") else: curArea.LOOK(cmd, cmds, msg) elif cmd in GET: curArea.GET(cmd, cmds, msg) elif cmd in USE: with consolelib.listenPrints() as printedString: curArea.USE(cmd, cmds, msg) if printedString[0]: pass elif "magazines" in Inventory and ("maga", "zine") in msg: say("Is now the best time to be doing that?") elif "crochetagebook" in Inventory and "crochet" in msg: say("You flip through the booklet, but you can't understand the language. The diagrams detail the basics of picking locks.") elif ("water", "hydra", "bottle") in msg and "waterbottle" in Inventory: say("You're not thirsty at the moment.") elif cmd in LOCKPICK: if len(cmds) == 1: say("What locked object do you want to pick?") else: curArea.LOCKPICK(cmd, cmds, msg) elif "bumbl" in cmd: say("Bumbling around into furniture isn't really productive." "Besides, you're supposed to follow 'leave no trace' when Seeking.") elif ("break", "kick", "smash") in cmd: say("Seekers can't just go around breaking things, especially not in old ruins.") elif ("hello", "hi", "hey") in cmd: say("Ello.") elif ("yes") in cmd: say("Nope.") elif ("no") in cmd: say("Yep.")
"W8KMA", "#%$" ] for t in range(1,5*5): width = (t//5)*3 #Every 4 ticks, increase doorframe width by 3 s = "" for y in range(-17,13): #Offset from -15,-15 so the door ends at the bottom of the screen for x in range(-39,39): picked = 5 for i in range(5): if abs(x) < (width+4*i) and abs(y) < (width+3*i): picked = i break s += random.choice(greyscale[picked]) s+="\n" consolelib.clear() print(s) time.sleep(0.18) time.sleep(0.8) consolelib.clear() time.sleep(0.3) if "time" not in States: #New game! States["time"] = 9*60 States["pins"] = 0 States["money"] = 3 consolelib.clear() if(raw_input("""\n\n\n\n\n\n\n\n\n\n\n There is much to see in this world, take care to `look` at everything you find.
def parseCMD(msg): msg = SearchableString(msg.lower()) cmds = msg.split() cmd = SearchableString(len(cmds) > 0 and cmds[0] or "") curArea = Areas[States["area"]] if cmd == "load": SaveName = len(cmds) > 1 and cmds[1] or input("Save name: >") if SaveName: NewStates, NewInventory = dson.load( open(getSaveDir() + SaveName + ".dson", "r")) States.clear() Inventory.clear() States.update(NewStates) Inventory.update(NewInventory) print("== Progress loaded from '" + SaveName + ".dson' ==") elif cmd == "save": SaveName = len(cmds) > 1 and cmds[1] or input("Save name: >") if SaveName: dson.dump((States, Inventory), open(getSaveDir() + SaveName + ".dson", "w"), indent=2) print("== Progress saved to '" + SaveName + ".dson' ==") elif cmd in ("clear", "cls"): consolelib.clear() print(" ") elif cmd in ("h", "help"): print("You consider for a moment the verbs you've learned:\n" "go/enter [room]\n" "back/return/last goes to previous room\n" "look/examine/view [object]\n" "grab/pick/get/take [object]\n" "use [object] on [object]\n" "lockpick [object]\n" "time\n" "map\n" "i/inventory\n" "save [filename]\n" "load [filename]") elif cmd in ("i", "inventory"): if "backpack" in States: print( "You stop and look at the contents of your leather backpack:") for item in Inventory.values(): print("\t- " + item) print("\t- Lockpicking pins: " + str(States["pins"])) print("\t- Money: $%.2f" % States["money"]) else: say("There isn't anything in your pockets. You try to start missions light." ) elif cmd in ("time", "watch"): if "watch" in States: say("You glance at your Booker's display of the current local time: " + getTime()) else: say("Your booker's internal clock hasn't been configured for this locale, and is still displaying your home time: " + str(int(States["time"] / 1.44))) elif cmd in ("map", ): say("You review your Booker's spatial layouting program.") with consolelib.lineByLine(0.03): openMap(curArea.zone) elif cmd == "" or (cmd in LOOK and len(cmds) == 1): curArea.describe() elif cmd in ("back", "return", "last") or "go back" in msg: if "lastarea" in States: setArea(States["lastarea"]) else: say("You just walked into the building, you can't leave yet.") elif cmd in GO: curArea.GO(cmd, cmds, msg) elif cmd in LOOK: if ("booker", "arm") in msg: say("The Booker on your arm is an advanced Personal Information Processor. The 2000 model premiered in the year 8AA, and is primarily built from salvaged Old world components modified to support an MF power core. Its many features include a watch, 3D scanner, 1w laser pointer (doubles as a microwelder), journal logging, and flying toasters screensaver." ) elif ("keyhole") in msg: say("You peer through the door's keyhole, but can't see anything, since there's a lock in the way." ) else: curArea.LOOK(cmd, cmds, msg) elif cmd in GET: curArea.GET(cmd, cmds, msg) elif cmd in USE: with consolelib.listenPrints() as printedString: curArea.USE(cmd, cmds, msg) if printedString[0]: pass elif "magazines" in Inventory and ("maga", "zine") in msg: say("Is now the best time to be doing that?") elif "crochetagebook" in Inventory and "crochet" in msg: say("You flip through the booklet, but you can't understand the language. The diagrams detail the basics of picking locks." ) elif ("water", "hydra", "bottle") in msg and "waterbottle" in Inventory: say("You're not thirsty at the moment.") elif cmd in LOCKPICK: if len(cmds) == 1: say("What locked object do you want to pick?") else: curArea.LOCKPICK(cmd, cmds, msg) elif "bumbl" in cmd: say("Bumbling around into furniture isn't really productive." "Besides, you're supposed to follow 'leave no trace' when Seeking." ) elif ("break", "kick", "smash") in cmd: say("Seekers can't just go around breaking things, especially not in old ruins." ) elif ("hello", "hi", "hey") in cmd: say("Ello.") elif ("yes") in cmd: say("Nope.") elif ("no") in cmd: say("Yep.")
for t in range(1, 5 * 5): width = (t // 5) * 3 #Every 4 ticks, increase doorframe width by 3 s = "" for y in range( -17, 13 ): #Offset from -15,-15 so the door ends at the bottom of the screen for x in range(-39, 39): picked = 5 for i in range(5): if abs(x) < (width + 4 * i) and abs(y) < (width + 3 * i): picked = i break s += random.choice(greyscale[picked]) s += "\n" consolelib.clear() print(s) time.sleep(0.18) time.sleep(0.8) consolelib.clear() time.sleep(0.3) if "time" not in States: #New game! States["time"] = 9 * 60 States["pins"] = 0 States["money"] = 3 consolelib.clear() if (input("""\n\n\n\n\n\n\n\n\n\n\n There is much to see in this world, take care to `look` at everything you find.
def main(difficulty, pins): """Engages the lockpicking minigame. returns 0 (player gave up with ctrl-c), False (fail), True (success) """ #Draw the lock (left hand side) lock = random.choice(locks[difficulty-1]) slock = " Lock:\n" for y in range(-1, 6): for x in range(-1, 6): if x == -1 or y == -1 or x == 5 or y == 5: slock += "#" #borders else: slock += lock[y*5 + x] == "=" and "." or "#" slock += "\n" tkey = [" "]*25 posx = posy = 0 pick = 0 press = "" while True: #Change selected tetronimo pick += (press == "q" and -1 or (press == "e" and 1) or 0) if pick < 0: pick = len(picks) - 1 elif pick >= len(picks): pick = 0 #Move the tetromino around posx += (press == "d" and 1 or (press == "a" and -1)) posy += (press == "s" and 1 or (press == "w" and -1)) while (posx + picks[pick].width) > 5: posx -= 1 while (posy + picks[pick].height) > 5: posy -= 1 if posx < 0: posx = 0 if posy < 0: posy = 0 #Save the current tetronimo + position with `space` if press == " ": if pins < 1: print "You don't have any pins remaining." return 0, pins for y, row in enumerate(picks[pick].s.split("\n")): for x, char in enumerate(row): if char == "=": tkey[(posy+y)*5 + (posx+x)] = "=" pins -= 1 #Clear the saved tetrominos with `z` elif press == "z": tkey = [" "]*25 #Attempt to solve the lock elif press == "\r": result = lock == tkey if result: print("Your makeshift key manages to open the lock!") else: print("Your makeshift key isn't tripping all the tumblers; the door remains locked.") return result, pins #== DRAWING == #============= current = [" "]*25 #Draw the previous tetrominos for i, char in enumerate(tkey): if char != " ": current[i] = char #Draw the current tetromino for y, row in enumerate(picks[pick].s.split("\n")): for x, char in enumerate(row): if char != " ": current[(posy+y)*5 + (posx+x)] = consolelib.background(current[(posy+y)*5 + (posx+x)], "RED") #Convert the current board into a string skey = " Key:\n" + "#"*7 + "\n" for i in range(0,25,5): skey += "#" + "".join(current[i:i+5]) + "#\n" skey += "#"*7 consolelib.clear() print """\ Using your Booker, you scan the internal layout of the tumblers, creating a 3D model. You'll need to bend your flexium pins to the correct shape, and then flashweld them to create a working key.\n""" print consolelib.screenSplit((slock, skey, helptext + str(pins)), width=10) + "\n" try: press = consolelib.getKey() except KeyboardInterrupt: print "You decide to give up on picking the lock for now." return 0, pins
def main(difficulty, pins): """Engages the lockpicking minigame. returns 0 (player gave up with ctrl-c), False (fail), True (success) """ #Draw the lock (left hand side) lock = random.choice(locks[difficulty-1]) slock = " Lock:\n" for y in range(-1, 6): for x in range(-1, 6): if x == -1 or y == -1 or x == 5 or y == 5: slock += "#" #borders else: slock += lock[y*5 + x] == "=" and "." or "#" slock += "\n" tkey = [" "]*25 posx = posy = 0 pick = 0 press = "" while True: #Change selected tetronimo pick += (press == "q" and -1 or (press == "e" and 1) or 0) if pick < 0: pick = len(picks) - 1 elif pick >= len(picks): pick = 0 #Move the tetromino around posx += (press == "d" and 1 or (press == "a" and -1)) posy += (press == "s" and 1 or (press == "w" and -1)) while (posx + picks[pick].width) > 5: posx -= 1 while (posy + picks[pick].height) > 5: posy -= 1 if posx < 0: posx = 0 if posy < 0: posy = 0 #Save the current tetronimo + position with `space` if press == " ": if pins < 1: print("You don't have any pins remaining.") return 0, pins for y, row in enumerate(picks[pick].s.split("\n")): for x, char in enumerate(row): if char == "=": tkey[(posy+y)*5 + (posx+x)] = "=" pins -= 1 #Clear the saved tetrominos with `z` elif press == "z": tkey = [" "]*25 #Attempt to solve the lock elif press == "\r": result = lock == tkey if result: print("Your makeshift key manages to open the lock!") else: print("Your makeshift key isn't tripping all the tumblers; the door remains locked.") return result, pins #== DRAWING == #============= current = [" "]*25 #Draw the previous tetrominos for i, char in enumerate(tkey): if char != " ": current[i] = char #Draw the current tetromino for y, row in enumerate(picks[pick].s.split("\n")): for x, char in enumerate(row): if char != " ": current[(posy+y)*5 + (posx+x)] = consolelib.background(current[(posy+y)*5 + (posx+x)], "RED") #Convert the current board into a string skey = " Key:\n" + "#"*7 + "\n" for i in range(0,25,5): skey += "#" + "".join(current[i:i+5]) + "#\n" skey += "#"*7 consolelib.clear() print("""\ Using your Booker, you scan the internal layout of the tumblers, creating a 3D model. You'll need to bend your flexium pins to the correct shape, and then flashweld them to create a working key.\n""") print(consolelib.screenSplit((slock, skey, helptext + str(pins)), width=10) + "\n") try: press = consolelib.getKey() except KeyboardInterrupt: print("You decide to give up on picking the lock for now.") return 0, pins