from sys import exit word_dictionary = { "aggression": ("attack", "hit", "fight", "chop", "slash", "stab", "charge", "kick", "punch"), "diplomacy": ("talk", "chat", "ask", "greet"), "retreat": ("leave", "flee", "run", "home", "back"), "advance": ("enter", "down", "sneak", "cave", "forward"), "weapon": ("sword", "weapon", "wield"), "outside_ground": ("skeleton", "armor", "wear"), "observe": ("look", "examine", "search"), "get_torch": ("torch", "light", "pick", "grab") } knight_alive = True have_sword = False have_torch = False bats_flown = False cave_looked = False def start(): global word_dictionary global knight_alive global have_sword if knight_alive: print """ You stand before the entrance to a cave. Guarding the entrance is a giant sentry clad in spiked black armor, wielding a spiked club spattered and stained with darkened blood. The ground is littered with rusting swords and skeletons in shattered armor. """ else: print """ You stand at the entrance to the cave. The knight lies beaten and broken here, one more addition to this impromptu graveyard. """ while True: next = raw_input("What do you do next?\n> ") if any (next.find(i) >= 0 for i in word_dictionary["aggression"]) and not have_sword: dead("The black knight's club moves in a blur, knocking your head clean off your shoulders.") elif any(next.find(i) >= 0 for i in word_dictionary["aggression"]) and have_sword and knight_alive: print """ You heroically smite the black knight with your cool sword. You repeatedly smite him. After a time, he is adequately smitten. Smut. Smote? In any case, you win. The black knight lies broken before you. """ knight_alive = False elif any(next.find(i) >= 0 for i in word_dictionary["weapon"]) and not have_sword: print """ You examine your surroundings for a likely looking weapon. You settle for a sword that looks marginally less weathered than the others scattered about. After some straining and cursing you pry it free from the corpse it was previously occupying. Yay, sword! """ have_sword = True elif any(next.find(i) >= 0 for i in word_dictionary["outside_ground"]): print "All of this armor is full of dead people. That's gross." elif any(next.find(i) >= 0 for i in word_dictionary["retreat"]): dead("You bravely ran away and never looked back.") elif any(next.find(i) >=0 for i in word_dictionary["observe"]) and knight_alive: start() elif any(next.find(i) >=0 for i in word_dictionary["observe"]) and not knight_alive: print """ You stand at the entrance to the cave. The knight lies beaten and broken here, one more addition to this impromptu graveyard. """ elif any(next.find(i) >=0 for i in word_dictionary["advance"]) and knight_alive: print """ As you advance to enter the cave, the sentry sternly shakes his head and raises his club. Better re-think that. """ elif any(next.find(i) >= 0 for i in word_dictionary["advance"]) and not knight_alive: cave() elif any(next.find(i) >=0 for i in word_dictionary["diplomacy"]) and knight_alive: print """ As you approach to talk, the sentry sternly shakes his head. Clearly not a chatty guy. """ elif any (next.find(i) >=0 for i in word_dictionary["diplomacy"]) and not knight_alive: print "You talk to yourself for a while. Just like a crazy person." else: print "That doesn't seem to have helped the situation." def cave(): global have_torch global bats_flown global cave_looked print "The cave is dark and damp and maybe full of secrets. Or bats. Or grues." if bats_flown: print "Definitely bats, at least." if cave_looked: print "And how!" if not have_torch: print "You should grab a torch before going down. Conveniently there is one nearby." while True: next = raw_input("What do you do next?\n> ") if any(next.find(i) >= 0 for i in word_dictionary["advance"]) and not have_torch: dead("You venture forth into the darkness. You fumble around in the dark for a while before being eaten by a grue.") elif any(next.find(i) >= 0 for i in word_dictionary["advance"]) and have_torch: cave2() elif any(next.find(i) >= 0 for i in word_dictionary["observe"]) and not have_torch: print "You can't see more than a few feet into the cave, even with the sun high in the sky behind you." print "It is very dark indeed. I thought I mentioned that." elif any(next.find(i) >= 0 for i in word_dictionary["observe"]) and have_torch: print """ You shine the light down the length of the cave. It winds down and around out of sight. The floor of the cave is caked thickly in guano. Here and there, a stalagmite. """ cave_looked = True elif any(next.find(i) >= 0 for i in word_dictionary["get_torch"]) and not have_torch: print """ You pick up the torch. It isn't lit at the moment. You open the torch, put in a few D cell batteries, and it flickers to life. Startled by the light, a colony of bats detaches from the ceiling and takes flight. As they fly out of the cave mouth they briefly blot out the sun. All is quiet. """ have_torch = True bats_flown = True elif any(next.find(i) >= 0 for i in word_dictionary["retreat"]): start() elif any (next.find(i) >=0 for i in word_dictionary["diplomacy"]): print "You talk to yourself for a while. Just like a crazy person." else: print "That doesn't seem to have helped the situation." def cave2(): dead("You travel deeper into the cave and find secrets, gold, %s, and a pretty %s ribbon." % (quest, colour)) def dead(reason): print reason, "Good job, %s!" % name exit(0) print "HALT!" name = raw_input("What is your name, traveler?\n> ") quest = raw_input("What do you seek, %s?\n> " % name) colour = raw_input("What is your favourite colour?\n> ") print "\nAlright, then. Off you go." start()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question