Advertisement
here2share

# Basic_Text_Adventure.py

Aug 10th, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. # Basic_Text_Adventure.py
  2. import os
  3. import random
  4.  
  5. class Cv():
  6.     loop='1'
  7. cv=Cv()
  8.  
  9. got=[]
  10. def ask(q):
  11.     if not q: q="What do you do? "
  12.     return raw_input(q).lower().strip()
  13.  
  14. def opt(options):
  15.     s=[]
  16.     print
  17.     z=options.replace('\t','')
  18.     z=z.split('\n')
  19.     for a,b in enumerate(z):
  20.         if a:
  21.             b,c=b.split(' <> ')
  22.             s.append(c)
  23.             print a,'=',b
  24.     print
  25.     try:
  26.         ans=int(ask(z[0]))
  27.         cls()
  28.         if '#' in s[ans-1]:
  29.             cv.loop=s[ans-1][1:]
  30.             print 'CHANGE OF SCENARIO --'
  31.         else:
  32.             print s[ans-1]
  33.         return ans
  34.     except:
  35.         cls()
  36.         print '???'
  37.  
  38. def repl_(z,x):
  39.     x=x.replace('\t','')
  40.     target,found,zzz,x=x.split('\n')
  41.     if target not in got:
  42.         return z.replace('@'+target,found)
  43.     return z.replace('@'+target,zzz)
  44.  
  45. def sep():
  46.     print("_"*80)
  47.    
  48. def cls():
  49.     os.system('cls' if os.name == 'nt' else 'clear')
  50.     print
  51.  
  52. while True:
  53.     cls()
  54.     print("Welcome to Zork - The Unofficial Python Demo Version")
  55.  
  56.     # First Input
  57.     while cv.loop == '1':
  58.         sep()
  59.         print("You are standing in an open field west of a white mansion.")
  60.         print("A secret path leads southwest into the forest.")
  61.         print("There is a small mailbox.")
  62.         z='''
  63.         open door <> The door is heavily secured.
  64.         look at house <> It is clear that the owners must have been wealthy.
  65.         take mailbox <> It is securely anchored.
  66.         @leaflet
  67.         go southwest <> #2'''
  68.         z=repl_(z, '''leaflet
  69.         open mailbox <> Opening the small mailbox reveals a leaflet.
  70.         read leaflet <> Written:  Your mission is to find a Jade Statue.
  71.         ''')
  72.         ans=opt(z)
  73.         if ans is 4: got.append('leaflet')
  74.  
  75.     # Southwest
  76.     while cv.loop == '2':
  77.         sep()
  78.         print("This is a forest, with trees in all directions. To the east, there appears to be sunlight.")
  79.         opt('''
  80.         go west <> You would need a machete to go further west
  81.         go north <> The forest becomes impenetrable to the North
  82.         go south <> Storm-tossed trees block your way
  83.         go east <> #3''')
  84.  
  85.     # East and Grating Input
  86.     while cv.loop == '3':
  87.         sep()
  88.         print("You are in a clearing, with a forest surrounding you on all sides.\nA path leads south.")
  89.         print("There is an open grating, descending into darkness.")
  90.         opt('''
  91.         go south <> You see a large ogre and turn around
  92.         descend grating <> #4''')
  93.  
  94.     # Grating and Cave Input
  95.     while cv.loop == '4':
  96.         sep()
  97.         print("You are in a tiny cave with a dark, forbidding staircase leading down.")
  98.         print("There is a skeleton of a human male in one corner.")
  99.         opt('''
  100.         take skeleton <> Why would you do that? Are you some sort of sicko?
  101.         smash skeleton <> Ugh... have you no respect?
  102.         light up room <> You would need a torch or lamp to do that.
  103.         ascend grating <> #5
  104.         descend staircase <> #6
  105.         go down staircase <> #6''')
  106.     if cv.loop == '5':
  107.         sep()
  108.         print("In backing out, you are immediately met with shadowy large monster just outside that... took your life.")
  109.         print
  110.         cv.loop='end'
  111.  
  112.     # Final Destination
  113.     while cv.loop == '6':
  114.         sep()
  115.         print("You have entered a mud-floored room.")
  116.         print("Lying half buried in the mud is an old trunk... bulging with assorted jewels !!!")
  117.         print("There is an old trunk here, bulging with assorted jewels.")
  118.         opt('''
  119.         open trunk <> #glory''')
  120.  
  121.     # End of game
  122.     while cv.loop == 'glory':
  123.         sep()
  124.         print("You have found the Jade Statue and have completed your quest !!!")
  125.         cv.loop='end'
  126.  
  127.     # Exit at the end of game
  128.     while cv.loop == 'end':
  129.         yn=ask("Do you want to play again? Y/N ")
  130.         if yn == ("n"): quit(1)
  131.         elif yn == ("y"): cv.loop='1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement