from sys import exit word_dictionary = { "aggression": ("attack", "hit", "fight", "chop", "slash", "stab", "charge", "kick", "punch"), "diplomacy": ("talk", "chat", "reason with", "ask", "greet"), "retreat": ("leave", "flee", "run", "home", "back"), "advance": ("enter", "down", "sneak", "cave", "forward", "go"), "weapon": ("sword", "weapon", "wield"), "spell": ("cast", "magic", "shoot"), "outside_ground": ("skeleton", "armor", "wear"), "observe": ("look", "examine", "search"), "get_torch": ("torch", "light", "pick", "grab"), "meditate": ("focus", "channel", "meditate"), "get_blessing": ("pray", "bless") } knight_alive = True have_sword = False cast_fire = False have_torch = False bats_flown = False cave_looked = False have_mana = False demon_alive = True have_blessing = False def start(): global word_dictionary global knight_alive global have_sword global have_mana if knight_alive: print """ You stand before the entrance to a cave. Guarding the entrance is a giant sentry clad in dragon-scale armor, wielding a spiked club stained with darkened blood. The ground is littered with rusting swords and corpses in shattered armor. """ else: print """ You stand at the entrance to the cave. The knight lies beaten and broken here, another 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 swings his club in a blur, crushing your unprotected skull easily.") elif any(next.find(i) >= 0 for i in word_dictionary["aggression"]) and have_sword and knight_alive: print """ The knight swings his massive club, but you easily sidestep his swing and stab him in the ribs, killing him. The Black Knight has fallen. """ 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. You now have a sword. """ have_sword = True if any(next.find(i) >= 0 for i in word_dictionary["spell"]) and not have_mana: dead("You attempt to cast a fireball at the knight, but mispronounce the spell and blow yourself up.") elif any(next.find(i) >= 0 for i in word_dictionary["spell"]) and have_mana and knight_alive: print""" You cast a powerful fireball at the knight, blowing a hole through his chest. The knight lies in a pile of ash and melted armor. """ knight_alive = False elif any(next.find(i) >= 0 for i in word_dictionary["meditate"]) and not have_mana: print "You meditate, channeling arcane energy through your body." have_mana = True elif any(next.find(i) >= 0 for i in word_dictionary["meditate"]) and have_mana: print "Your mana is already sufficiently charged." elif any(next.find(i) >= 0 for i in word_dictionary["outside_ground"]): print "All of this armor is full of dead people, weirdo." 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 dead on the floor, another 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. """ 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 demons." if bats_flown: print "Definitely bats, at least." if cave_looked: print "Yep, it hasn't changed a bit." 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 hearing an evil sounding laugh from behind you. You are promptly eaten by a demon.") 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 with guano, and the walls are inscribed with odd runes that make your eyes hurt. 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 strike your sword on the wall, using the sparks to ignite your torch. Startled by the light, a colony of bats detach from the ceilling and take 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 call out into the darkness, and are answered only by an echo of your voice." def cave2(): global demon_alive global have_blessing if demon_alive: print """ You hear an awful shriek, followed by echoing laughter. You feel a growing sensation of unease, and a demonic presence surrounds you. A demon appears before you! Maybe contacting a diety could help this situation. """ else: print """ You stand in front of a large door. You have a feeling this is a treasure room. """ 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_blessing: dead(""" You swing your ordinary sword at the demon, but it is unaffected. The demon knocks you unconsious with a clawed hand, before devouring you.""") elif any(next.find(i) >= 0 for i in word_dictionary["aggression"]) and have_blessing: print """ You swing your blade, now imbued with divine energies. The demon let's out an ear-piercing shriek as you cut it clean in half, banishing it back to whatever realm it came from. The feeling of uneasiness fades, and light returns to the cavern. """ demon_alive = False elif any(next.find(i) >= 0 for i in word_dictionary["spell"]) and demon_alive: print "The demon cannot be damaged by means of magic." elif any(next.find(i) >= 0 for i in word_dictionary["get_blessing"]) and not have_blessing: print """ You call out to the pantheon for assistance. Your blade begins to hum, and starts glowing a bright blue color. It appears they've decided to lend a hand. """ have_blessing = True elif any(next.find(i) >= 0 for i in word_dictionary["advance"]) and demon_alive: print"The demon looks at you hungrily. Maybe that isn't a good idea." elif any(next.find(i) >= 0 for i in word_dictionary["advance"]) and not demon_alive: treasureRoom() elif any(next.find(i) >= 0 for i in word_dictionary["observe"]) and demon_alive: cave2() elif any(next.find(i) >= 0 for i in word_dictionary["observe"]) and not demon_alive: print """ You stand in front of a large door. You have a feeling this is the treasure room. """ def treasureRoom(): dead("You enter the treasure room and a chest full of gold, %s, and a sweet %s cape! " % (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 favorite color?\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