Advertisement
selib

Text Adventure

Nov 13th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.52 KB | None | 0 0
  1. #Text Adventure
  2.  
  3. import shlex
  4.  
  5. def map():
  6.     print ' ______________________________'
  7.     print '|         |         |          |'
  8.     print '|         |         |          |'
  9.     print '| Room B  = Room D  =  Room E  |'
  10.     print '|   Jack  |  Sword  |   Bear   |'
  11.     print '|         |         |          |'
  12.     print '|----||---|----||---|----------|'
  13.     print '|         |         |'
  14.     print '|         |         |'
  15.     print '|  Steve  |  Jesse  |'
  16.     print '| Room A  = Room C  |'
  17.     print '|_________|_________|'
  18.  
  19.  
  20.  
  21.  
  22. class Room(object):
  23.     def __init__(self, location, description):
  24.         self.location = location
  25.         self.description = description
  26.  
  27.  
  28.     def display_Room(self):
  29.         return self.description
  30.  
  31.  
  32. class People(object):
  33.     def __init__(self,location,name,text,description,state):
  34.         self.location = location
  35.         self.name = name
  36.         self.text = text
  37.         self.description = description
  38.         self.state = state
  39.  
  40.  
  41.     def printText(self):
  42.         print self.text
  43.  
  44.  
  45.  
  46.     def go(self,location,Decision):
  47.  
  48.         newlocation = list(self.location)
  49.  
  50.  
  51.         if Decision == 'go north' or Decision == 'go n' or Decision == 'n':
  52.             newlocation[1] += 1
  53.             test = world.get(tuple(newlocation))
  54.             if test == None:
  55.                 print 'You cannot go there'
  56.             else:
  57.                 Ply.location = tuple(newlocation)
  58.         elif Decision == 'go south' or Decision == 'go s' or Decision == 's':
  59.             newlocation[1] -= 1
  60.             test = world.get(tuple(newlocation))
  61.             if test == None:
  62.                 print 'You cannot go there'
  63.             else:
  64.                 Ply.location = tuple(newlocation)
  65.  
  66.         elif Decision == 'go east' or Decision == 'go e' or Decision == 'e':
  67.             newlocation[0] += 1
  68.             test = world.get(tuple(newlocation))
  69.             if test == None:
  70.                 print 'You cannot go there'
  71.             else:
  72.                 Ply.location = tuple(newlocation)
  73.  
  74.         elif Decision == 'go west' or Decision == 'go w' or Decision == 'w':
  75.             newlocation[0] -= 1
  76.             test = world.get(tuple(newlocation))
  77.             if test == None:
  78.                 print 'You cannot go there'
  79.             else:
  80.                 Ply.location = tuple(newlocation)
  81.  
  82.  
  83. class Player(People):
  84.     def __init__(self,location,name,text,state):
  85.         self.location = location
  86.         self.name = name
  87.         self.text = text
  88.         self.state = state
  89.  
  90.  
  91.  
  92.     def printlocation(self,location):
  93.         return world.get(self.location).display_Room()
  94.  
  95.     def take(self,location,Decision):
  96.         if Decision == 'take sword':
  97.              if self.location == sword.location:
  98.                 Inventory.append(sword.name)
  99.                 print 'Taken'
  100.                 RoomC.description = 'You are in Room C.'
  101.         elif Decision == 'take meth' or 'take drugs':
  102.             if 'Meth' in Inventory:
  103.                 print 'YOU ARE HIGH'
  104.                 Inventory.remove('Meth')
  105.             else:
  106.                 print "You don't have that"
  107.  
  108.  
  109.  
  110.     def talk(self,location,Decision):
  111.         if Decision == 'talk steve' or Decision == 'talk to steve':
  112.             if self.location == Steve.location:
  113.                 if Jack.state == 'dead':
  114.                     print 'You killed Jack! Take this is a reward.'
  115.                     print 'Gold added to Inventory'
  116.                     Inventory.append(gold.name)
  117.                 elif Steve.state == 'dead':
  118.                     print 'This person is dead.'\
  119.  
  120.                 else:
  121.                     Steve.printText()
  122.             else:
  123.                 print "This person is not here."
  124.  
  125.         elif Decision == 'talk jack' or Decision == 'talk to jack':
  126.             if self.location == Jack.location:
  127.                 if Jack.state == 'dead':
  128.                     print 'This person is dead.'
  129.                 else:
  130.                     Jack.printText()
  131.             else:
  132.                 print 'This person is not here'
  133.  
  134.         elif Decision == 'talk jesse' or Decision == 'talk to jesse':
  135.             if self.location == Jesse.location:
  136.                 if Jesse.state == 'dead':
  137.                     print 'this person is dead'
  138.                 elif 'Gold' in Inventory:
  139.                     Drug = raw_input('You wanna buy some drugs?')
  140.                     if Drug == 'no':
  141.                         print 'THEN FUCK OFF'
  142.                     elif Drug == 'yes':
  143.                         Inventory.remove('Gold')
  144.                         Inventory.append(meth.name)
  145.                         print 'Gold removed from Inventory'
  146.                         print 'Meth added to Inventory'
  147.                 else:
  148.                     Jesse.printText()
  149.             else:
  150.                 print 'This person is not here'
  151.  
  152.  
  153.         elif Decision == 'talk bear' or Decision == 'talk to bear':
  154.             if self.location == Bear.location:
  155.                 if Bear.state == 'dead':
  156.                     print 'this monster is dead'
  157.                 else:
  158.                     Bear.printText()
  159.                     print 'The bear killed you'
  160.                     print 'Game over'
  161.                     Ply.state = 'dead'
  162.             else:
  163.                 print 'This thing is not here'
  164.  
  165.  
  166.  
  167. class Item(object):
  168.     def __init__(self,name,text,location):
  169.         self.name = name
  170.         self.text = text
  171.         self.location = location
  172.  
  173.  
  174.  
  175.  
  176. def kill(Decision):
  177.     if Decision == 'kill steve':
  178.         if Ply.location == Steve.location:
  179.             killhelp('Steve')
  180.         else:
  181.             print "You don't see this person"
  182.     elif Decision == 'kill jack':
  183.         if Ply.location == Jack.location:
  184.             killhelp('Jack')
  185.         else:
  186.             print "You don't see this person"
  187.     elif Decision == 'kill jesse':
  188.         if Ply.location == Jesse.location:
  189.             killhelp('Jesse')
  190.         else:
  191.             print "You don't see this person"
  192.     elif Decision == "kill myself":
  193.             killhelp('myself')
  194.  
  195.     elif Decision == "kill bear":
  196.         print "YOU CAN'T KILL A FRICKIN BEAR."
  197.  
  198.     elif Decision == 'kill steve with sword':
  199.         if Ply.location == Steve.location:
  200.             killhelpwithitem('Sword','Steve')
  201.         else:
  202.             print "You don't see this person"
  203.     elif Decision == 'kill jack with sword':
  204.         if Ply.location == Jack.location:
  205.             killhelpwithitem('Sword','Jack')
  206.         else:
  207.             print "You don't see this person"
  208.     elif Decision == 'kill jesse with sword':
  209.         if Ply.location == Jesse.location:
  210.             killhelpwithitem('Sword','Jesse')
  211.         else:
  212.             print "You don't see this person"
  213.     elif Decision == "kill myself with sword":
  214.         killhelpwithitem('Sword','myself')
  215.  
  216.     elif Decision == "kill bear with sword":
  217.         print "YOU CAN'T KILL A FRICKIN BEAR WITH A SWORD."
  218.  
  219.  
  220. def killhelp(victim):
  221.     Dec = raw_input('With what?')
  222.     Dec2 = Dec.lower()
  223.     if Dec2 == 'sword':
  224.         if 'Sword' in Inventory:
  225.             killcons(victim)
  226.         else:
  227.             print "You can't do that"
  228.     else:
  229.         print "You can't do that"
  230.  
  231. def killhelpwithitem(Item,victim):
  232.     if Item in Inventory:
  233.             if Item in Inventory:
  234.                 killcons(victim)
  235.             else:
  236.                 print "You can't do that"
  237.     else:
  238.         print "You can't do that"
  239.  
  240.  
  241. def killcons(victim):
  242.     if victim == 'Steve':
  243.         Steve.state = 'dead'
  244.         print 'Steve died'
  245.         RoomA.description = "You are in Room A. You see Steve's dead body"
  246.     if victim == 'Jack':
  247.         Jack.state = 'dead'
  248.         print 'Jack died'
  249.         RoomB.description = "You are in Room B. You see Jack's dead body"
  250.     if victim == 'Jesse':
  251.         Jesse.state = 'dead'
  252.         print 'Jesse died'
  253.         RoomD.description = "You are in Room D. You see Jesse's dead body"
  254.     if victim == 'myself':
  255.         print 'You killed yourself. Good job, Really. Congratulations.'
  256.         print 'Game over'
  257.         Ply.state = 'dead'
  258.  
  259.  
  260.  
  261. def inv():
  262.     print Inventory
  263.  
  264. def exam(Decision):
  265.     if Decision == "examine sword":
  266.         print sword.text
  267.     elif Decision == "examine gold":
  268.         print gold.text
  269.     elif Decision == "examine meth":
  270.         print meth.text
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. def help():
  281.     print "You can use the following commands:"
  282.     print "go (north,south,west,east)"
  283.     print "talk (person)"
  284.     print "kill (person) with (item)"
  285.     print "take (item)"
  286.     print "inventory"
  287.     print "examine (item)"
  288.     print "quit"
  289.  
  290.  
  291. Inventory = []
  292.  
  293.  
  294. sword = Item('Sword','This is a sword',(2,2))
  295. gold = Item('Gold','This is gold',(1,1))
  296. meth = Item('Meth','THIS IS SOME REALLY NICE BLUE METH',(1,2))
  297.  
  298.  
  299. Ply = Player((1,1),'Player','','alive')
  300. Steve = People((1,1),'Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack.",'This is Steve','alive')
  301. Jack = People((1,2),'Jack',"Hi, I'm Jack.",'This is Jack','alive')
  302. Jesse = People((2,1),'Steve','Piss off, bitch.','This is Jesse','alive')
  303. Bear = People((3,2),'Bear','RAWWWRRR','THIS IS A FUCKING BEAR','alive')
  304.  
  305.  
  306. RoomA = Room((1,1),'You are in Room A. You see Steve.')
  307. RoomB = Room((1,2),'You are in Room B. You see Jack.')
  308. RoomC = Room((2,2),'You are in Room C. You see a sword.')
  309. RoomD = Room((2,1),'You are in Room D. You see Jesse.')
  310. RoomE = Room((3,2),'You are in Room E. You see a bear.')
  311.  
  312.  
  313. world = {
  314. (1,1):RoomA,
  315. (1,2):RoomB,
  316. (2,2):RoomC,
  317. (2,1):RoomD,
  318. (3,2):RoomE
  319. }
  320.  
  321.  
  322.  
  323.  
  324. def parser():
  325.     while Ply.state == 'alive':
  326.  
  327.         print Ply.printlocation(Ply.location)
  328.         Decisionst = raw_input('>')
  329.         Decisionstr = Decisionst.lower()
  330.         lst = shlex.split(Decisionstr)
  331.         if lst[0] == 'go' or lst[0] in 'nwse':
  332.             Ply.go(Ply.location,Decisionstr)
  333.         elif lst[0] == 'take':
  334.             Ply.take(Ply.location, Decisionstr)
  335.         elif lst[0] == 'quit':
  336.             break
  337.         elif lst[0] == 'talk':
  338.             Ply.talk(Ply.location, Decisionstr)
  339.         elif lst[0] == 'kill':
  340.             kill(Decisionstr)
  341.         elif lst[0] == 'inventory':
  342.             inv()
  343.         elif lst[0] == 'help':
  344.             help()
  345.         elif lst[0] == 'win':
  346.             print 'nice try'
  347.         elif lst[0] == 'shout':
  348.             print 'AAARGGGGGGHHHHH'
  349.         elif lst[0] == 'look':
  350.             Ply.printlocation(Ply.location)
  351.         elif lst[0] == 'examine' or 'exam':
  352.             exam(Decisionstr)
  353.         else:
  354.             print 'This doesnt work'
  355.  
  356. map()
  357. parser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement