Advertisement
selib

TA

Nov 10th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.48 KB | None | 0 0
  1. #Text Adventure
  2.  
  3. import shlex
  4.  
  5. class Room(object):
  6.     def __init__(self, location, description):
  7.         self.location = location
  8.         self.description = description
  9.  
  10.  
  11.     def display_Room(self):
  12.         print self.description
  13.  
  14.  
  15. class People(object):
  16.     def __init__(self,location,name,text,description,state):
  17.         self.location = location
  18.         self.name = name
  19.         self.text = text
  20.         self.description = description
  21.         self.state = state
  22.  
  23.  
  24.     def printText(self):
  25.         print self.text
  26.  
  27.  
  28.  
  29.     def go(self,location,Decision):
  30.  
  31.         newlocation = list(Player.location)
  32.  
  33.  
  34.         if Decision == 'go north':
  35.             newlocation[1] += 1
  36.             test = world.get(tuple(newlocation))
  37.             if test == None:
  38.                 print 'You cannot go there'
  39.             else:
  40.                 self.location = tuple(newlocation)
  41.         elif Decision == 'go south':
  42.             newlocation[1] -= 1
  43.             test = world.get(tuple(newlocation))
  44.             if test == None:
  45.                 print 'You cannot go there'
  46.             else:
  47.                 self.location = tuple(newlocation)
  48.  
  49.         elif Decision == 'go east':
  50.             newlocation[0] += 1
  51.             test = world.get(tuple(newlocation))
  52.             if test == None:
  53.                 print 'You cannot go there'
  54.             else:
  55.                 self.location = tuple(newlocation)
  56.  
  57.         elif Decision == 'go west':
  58.             newlocation[0] -= 1
  59.             test = world.get(tuple(newlocation))
  60.             if test == None:
  61.                 print 'You cannot go there'
  62.             else:
  63.                 self.location = tuple(newlocation)
  64.  
  65.  
  66. class Player(People):
  67.     def __init__(self,location,name,text,state):
  68.         self.location = location
  69.         self.name = name
  70.         self.text = text
  71.         self.state = state
  72.  
  73.  
  74.  
  75.     def pos(self,location):
  76.         return self.location
  77.  
  78.  
  79.     def printlocation(self,location):
  80.         return world.get(self.location).display_Room()
  81.  
  82.     def take(self,location,Decision):
  83.         if Decision == 'take sword':
  84.              if self.location == Sword.location:
  85.                 Inventory.append(Sword.name)
  86.                 print 'Taken'
  87.                 RoomC.description = 'You are in Room C.'
  88.         elif Decision == 'take meth' or 'take drugs':
  89.             if 'Meth' in Inventory:
  90.                 print 'YOU ARE HIGH'
  91.                 Inventory.remove('Meth')
  92.             else:
  93.                 print "You don't have that"
  94.  
  95.  
  96.  
  97.     def talk(self,location,Decision):
  98.         if Decision == 'talk steve' or Decision == 'talk to steve':
  99.             if self.location == Steve.location:
  100.                 if Jack.state == 'dead':
  101.                     print 'You killed Jack! Take this is a reward.'
  102.                     print 'Gold added to Inventory'
  103.                     Inventory.append(Gold.name)
  104.                 elif Steve.state == 'dead':
  105.                     print 'This person is dead.'\
  106.  
  107.                 else:
  108.                     Steve.printText()
  109.             else:
  110.                 print "This person is not here."
  111.  
  112.         elif Decision == 'talk jack' or Decision == 'talk to jack':
  113.             if self.location == Jack.location:
  114.                 if Jack.state == 'dead':
  115.                     print 'This person is dead.'
  116.                 else:
  117.                     Jack.printText()
  118.             else:
  119.                 print 'This person is not here'
  120.  
  121.         if Decision == 'talk jesse' or Decision == 'talk to jesse':
  122.             if self.location == Jesse.location:
  123.                 if Jesse.state == 'dead':
  124.                     print 'this person is dead'
  125.                 elif 'Gold' in Inventory:
  126.                     Drug = raw_input('You wanna buy some drugs?')
  127.                     if Drug == 'no':
  128.                         print 'THEN FUCK OFF'
  129.                     elif Drug == 'yes':
  130.                         Inventory.remove('Gold')
  131.                         Inventory.append(Meth.name)
  132.                         print 'Gold removed from Inventory'
  133.                         print 'Meth added to Inventory'
  134.                 else:
  135.                     Jesse.printText()
  136.             else:
  137.                 print 'This person is not here'
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. class Item(object):
  148.     def __init__(self,name,text,location):
  149.         self.name = name
  150.         self.text = text
  151.         self.location = location
  152.  
  153.     def exam(self):
  154.         print self.text
  155.  
  156. def kill(Decision):
  157.     if Decision == 'kill steve':
  158.         killhelp('Steve')
  159.     elif Decision == 'kill jack':
  160.         killhelp('Jack')
  161.     elif Decision == 'kill jesse':
  162.         killhelp('Jesse')
  163.     elif Decision == 'kill steve with sword':
  164.         killhelpwithitem('Sword','Steve')
  165.     elif Decision == 'kill jack with sword':
  166.         killhelpwithitem('Sword','Jack')
  167.     elif Decision == 'kill jesse with sword':
  168.         killhelpwithitem('Sword','Jesse')
  169.  
  170.  
  171. def killhelp(victim):
  172.     Dec = raw_input('With what?')
  173.     Dec2 = Dec.lower()
  174.     if Dec2 == 'sword':
  175.         if 'Sword' in Inventory:
  176.             killcons(victim)
  177.         else:
  178.             print "You can't do that"
  179.     else:
  180.         print "You can't do that"
  181.  
  182. def killhelpwithitem(Item,victim):
  183.     if Item in Inventory:
  184.             if Item in Inventory:
  185.                 killcons(victim)
  186.             else:
  187.                 print "You can't do that"
  188.     else:
  189.         print "You can't do that"
  190.  
  191.  
  192. def killcons(victim):
  193.     if victim == 'Steve':
  194.         Steve.state = 'dead'
  195.         print 'Steve died'
  196.         RoomA.description = "You are in Room A. You see Steve's dead body"
  197.     if victim == 'Jack':
  198.         Jack.state = 'dead'
  199.         print 'Jack died'
  200.         RoomB.description = "You are in Room B. You see Jack's dead body"
  201.     if victim == 'Jesse':
  202.         Jesse.state = 'dead'
  203.         print 'Jesse died'
  204.         RoomD.description = "You are in Room D. You see Jesse's dead body"
  205.  
  206. def inv():
  207.     print Inventory
  208.  
  209.  
  210. Inventory = []
  211.  
  212.  
  213. Sword = Item('Sword','This is a sword',(2,2))
  214. Gold = Item('Gold','This is gold',(1,1))
  215. Meth = Item('Meth','THIS IS SOME REALLY NICE BLUE METH',(1,2))
  216.  
  217.  
  218. Player = Player((1,1),'Player','','alive')
  219. Steve = People((1,1),'Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack.",'This is Steve','alive')
  220. Jack = People((1,2),'Jack',"Hi, I'm Jack.",'This is Jack','alive')
  221. Jesse = People((2,1),'Steve','Piss off, bitch.','This is Jesse','alive')
  222.  
  223.  
  224. RoomA = Room((1,1),'You are in Room A. You see Steve.')
  225. RoomB = Room((1,2),'You are in Room B. You see Jack')
  226. RoomC = Room((2,2),'You are in Room C. You see a sword')
  227. RoomD = Room((2,1),'You are in Room D. You see Jesse')
  228.  
  229.  
  230.  
  231. world = {
  232. (1,1):RoomA,
  233. (1,2):RoomB,
  234. (2,2):RoomC,
  235. (2,1):RoomD,
  236. }
  237.  
  238.  
  239.  
  240.  
  241. def parser():
  242.     while Player.state == 'alive':
  243.  
  244.         print Player.printlocation(Player.location)
  245.         Decisionst = raw_input('>')
  246.         Decisionstr = Decisionst.lower()
  247.         lst = shlex.split(Decisionstr)
  248.         if lst[0] == 'go':
  249.             Player.go(Player.location,Decisionstr)
  250.         elif lst[0] == 'take':
  251.             Player.take(Player.location, Decisionstr)
  252.         elif lst[0] == 'quit':
  253.             break
  254.         elif lst[0] == 'talk':
  255.             Player.talk(Player.location, Decisionstr)
  256.         elif lst[0] == 'kill':
  257.             kill(Decisionstr)
  258.         elif lst[0] == 'inventory':
  259.             inv()
  260.         elif lst[0] == 'win':
  261.             print 'nice try'
  262.         else:
  263.             print 'This doesnt work'
  264.  
  265.  
  266. parser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement