Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Basic_Text_Adventure.py
- import os
- import random
- class Cv():
- loop='1'
- cv=Cv()
- got=[]
- def ask(q):
- if not q: q="What do you do? "
- return raw_input(q).lower().strip()
- def opt(options):
- s=[]
- print
- z=options.replace('\t','')
- z=z.split('\n')
- for a,b in enumerate(z):
- if a:
- b,c=b.split(' <> ')
- s.append(c)
- print a,'=',b
- print
- try:
- ans=int(ask(z[0]))
- cls()
- if '#' in s[ans-1]:
- cv.loop=s[ans-1][1:]
- print 'CHANGE OF SCENARIO --'
- else:
- print s[ans-1]
- return ans
- except:
- cls()
- print '???'
- def repl_(z,x):
- x=x.replace('\t','')
- target,found,zzz,x=x.split('\n')
- if target not in got:
- return z.replace('@'+target,found)
- return z.replace('@'+target,zzz)
- def sep():
- print("_"*80)
- def cls():
- os.system('cls' if os.name == 'nt' else 'clear')
- print
- while True:
- cls()
- print("Welcome to Zork - The Unofficial Python Demo Version")
- # First Input
- while cv.loop == '1':
- sep()
- print("You are standing in an open field west of a white mansion.")
- print("A secret path leads southwest into the forest.")
- print("There is a small mailbox.")
- z='''
- open door <> The door is heavily secured.
- look at house <> It is clear that the owners must have been wealthy.
- take mailbox <> It is securely anchored.
- @leaflet
- go southwest <> #2'''
- z=repl_(z, '''leaflet
- open mailbox <> Opening the small mailbox reveals a leaflet.
- read leaflet <> Written: Your mission is to find a Jade Statue.
- ''')
- ans=opt(z)
- if ans is 4: got.append('leaflet')
- # Southwest
- while cv.loop == '2':
- sep()
- print("This is a forest, with trees in all directions. To the east, there appears to be sunlight.")
- opt('''
- go west <> You would need a machete to go further west
- go north <> The forest becomes impenetrable to the North
- go south <> Storm-tossed trees block your way
- go east <> #3''')
- # East and Grating Input
- while cv.loop == '3':
- sep()
- print("You are in a clearing, with a forest surrounding you on all sides.\nA path leads south.")
- print("There is an open grating, descending into darkness.")
- opt('''
- go south <> You see a large ogre and turn around
- descend grating <> #4''')
- # Grating and Cave Input
- while cv.loop == '4':
- sep()
- print("You are in a tiny cave with a dark, forbidding staircase leading down.")
- print("There is a skeleton of a human male in one corner.")
- opt('''
- take skeleton <> Why would you do that? Are you some sort of sicko?
- smash skeleton <> Ugh... have you no respect?
- light up room <> You would need a torch or lamp to do that.
- ascend grating <> #5
- descend staircase <> #6
- go down staircase <> #6''')
- if cv.loop == '5':
- sep()
- print("In backing out, you are immediately met with shadowy large monster just outside that... took your life.")
- print
- cv.loop='end'
- # Final Destination
- while cv.loop == '6':
- sep()
- print("You have entered a mud-floored room.")
- print("Lying half buried in the mud is an old trunk... bulging with assorted jewels !!!")
- print("There is an old trunk here, bulging with assorted jewels.")
- opt('''
- open trunk <> #glory''')
- # End of game
- while cv.loop == 'glory':
- sep()
- print("You have found the Jade Statue and have completed your quest !!!")
- cv.loop='end'
- # Exit at the end of game
- while cv.loop == 'end':
- yn=ask("Do you want to play again? Y/N ")
- if yn == ("n"): quit(1)
- elif yn == ("y"): cv.loop='1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement