コード例 #1
0
def main():
	while True:
		msg = SearchableString(raw_input("\n["+Areas[States["area"]].__class__.__name__+"]--> ").lower())
		print("")
		
		with consolelib.listenPrints() as printedString:
			parseCMD(msg)

		if printedString[0]:
			States["time"] += 5 #Successful actions take 5 minutes
		else:
			#Nothing was printed, so the command/args pair wasn't found
			notFound(msg.split())
コード例 #2
0
ファイル: fade.py プロジェクト: Nebual/fade
def main():
    while True:
        msg = input("\n[" + Areas[States["area"]].__class__.__name__ + "]--> ")
        print("")

        with consolelib.listenPrints() as printedString:
            parseCMD(msg)

        if printedString[0]:
            States["time"] += 5  #Successful actions take 5 minutes
        else:
            #Nothing was printed, so the command/args pair wasn't found
            notFound(msg.lower().split())
コード例 #3
0
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.")
コード例 #4
0
ファイル: fade.py プロジェクト: Nebual/fade
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.")