SHARE
    TWEET
    selib

    TA

    Nov 10th, 2013
    74
    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. import shlex
    3. class Room(object):
    4. def __init__(self, location, description):
    5. self.location = location
    6. self.description = description
    7. def display_Room(self):
    8. print self.description
    9. class People(object):
    10. def __init__(self,location,name,text,description,state):
    11. self.location = location
    12. self.name = name
    13. self.text = text
    14. self.description = description
    15. self.state = state
    16. def printText(self):
    17. print self.text
    18. def go(self,location,Decision):
    19. newlocation = list(Player.location)
    20. if Decision == 'go north':
    21. newlocation[1] += 1
    22. test = world.get(tuple(newlocation))
    23. if test == None:
    24. print 'You cannot go there'
    25. else:
    26. self.location = tuple(newlocation)
    27. elif Decision == 'go south':
    28. newlocation[1] -= 1
    29. test = world.get(tuple(newlocation))
    30. if test == None:
    31. print 'You cannot go there'
    32. else:
    33. self.location = tuple(newlocation)
    34. elif Decision == 'go east':
    35. newlocation[0] += 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 west':
    42. newlocation[0] -= 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. class Player(People):
    49. def __init__(self,location,name,text,state):
    50. self.location = location
    51. self.name = name
    52. self.text = text
    53. self.state = state
    54. def pos(self,location):
    55. return self.location
    56. def printlocation(self,location):
    57. return world.get(self.location).display_Room()
    58. def take(self,location,Decision):
    59. if Decision == 'take sword':
    60. if self.location == Sword.location:
    61. Inventory.append(Sword.name)
    62. print 'Taken'
    63. RoomC.description = 'You are in Room C.'
    64. elif Decision == 'take meth' or 'take drugs':
    65. if 'Meth' in Inventory:
    66. print 'YOU ARE HIGH'
    67. Inventory.remove('Meth')
    68. else:
    69. print "You don't have that"
    70. def talk(self,location,Decision):
    71. if Decision == 'talk steve' or Decision == 'talk to steve':
    72. if self.location == Steve.location:
    73. if Jack.state == 'dead':
    74. print 'You killed Jack! Take this is a reward.'
    75. print 'Gold added to Inventory'
    76. Inventory.append(Gold.name)
    77. elif Steve.state == 'dead':
    78. print 'This person is dead.'\
    79. else:
    80. Steve.printText()
    81. else:
    82. print "This person is not here."
    83. elif Decision == 'talk jack' or Decision == 'talk to jack':
    84. if self.location == Jack.location:
    85. if Jack.state == 'dead':
    86. print 'This person is dead.'
    87. else:
    88. Jack.printText()
    89. else:
    90. print 'This person is not here'
    91. if Decision == 'talk jesse' or Decision == 'talk to jesse':
    92. if self.location == Jesse.location:
    93. if Jesse.state == 'dead':
    94. print 'this person is dead'
    95. elif 'Gold' in Inventory:
    96. Drug = raw_input('You wanna buy some drugs?')
    97. if Drug == 'no':
    98. print 'THEN FUCK OFF'
    99. elif Drug == 'yes':
    100. Inventory.remove('Gold')
    101. Inventory.append(Meth.name)
    102. print 'Gold removed from Inventory'
    103. print 'Meth added to Inventory'
    104. else:
    105. Jesse.printText()
    106. else:
    107. print 'This person is not here'
    108. class Item(object):
    109. def __init__(self,name,text,location):
    110. self.name = name
    111. self.text = text
    112. self.location = location
    113. def exam(self):
    114. print self.text
    115. def kill(Decision):
    116. if Decision == 'kill steve':
    117. killhelp('Steve')
    118. elif Decision == 'kill jack':
    119. killhelp('Jack')
    120. elif Decision == 'kill jesse':
    121. killhelp('Jesse')
    122. elif Decision == 'kill steve with sword':
    123. killhelpwithitem('Sword','Steve')
    124. elif Decision == 'kill jack with sword':
    125. killhelpwithitem('Sword','Jack')
    126. elif Decision == 'kill jesse with sword':
    127. killhelpwithitem('Sword','Jesse')
    128. def killhelp(victim):
    129. Dec = raw_input('With what?')
    130. Dec2 = Dec.lower()
    131. if Dec2 == 'sword':
    132. if 'Sword' in Inventory:
    133. killcons(victim)
    134. else:
    135. print "You can't do that"
    136. else:
    137. print "You can't do that"
    138. def killhelpwithitem(Item,victim):
    139. if Item in Inventory:
    140. if Item in Inventory:
    141. killcons(victim)
    142. else:
    143. print "You can't do that"
    144. else:
    145. print "You can't do that"
    146. def killcons(victim):
    147. if victim == 'Steve':
    148. Steve.state = 'dead'
    149. print 'Steve died'
    150. RoomA.description = "You are in Room A. You see Steve's dead body"
    151. if victim == 'Jack':
    152. Jack.state = 'dead'
    153. print 'Jack died'
    154. RoomB.description = "You are in Room B. You see Jack's dead body"
    155. if victim == 'Jesse':
    156. Jesse.state = 'dead'
    157. print 'Jesse died'
    158. RoomD.description = "You are in Room D. You see Jesse's dead body"
    159. def inv():
    160. print Inventory
    161. Inventory = []
    162. Sword = Item('Sword','This is a sword',(2,2))
    163. Gold = Item('Gold','This is gold',(1,1))
    164. Meth = Item('Meth','THIS IS SOME REALLY NICE BLUE METH',(1,2))
    165. Player = Player((1,1),'Player','','alive')
    166. Steve = People((1,1),'Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack.",'This is Steve','alive')
    167. Jack = People((1,2),'Jack',"Hi, I'm Jack.",'This is Jack','alive')
    168. Jesse = People((2,1),'Steve','Piss off, bitch.','This is Jesse','alive')
    169. RoomA = Room((1,1),'You are in Room A. You see Steve.')
    170. RoomB = Room((1,2),'You are in Room B. You see Jack')
    171. RoomC = Room((2,2),'You are in Room C. You see a sword')
    172. RoomD = Room((2,1),'You are in Room D. You see Jesse')
    173. world = {
    174. (1,1):RoomA,
    175. (1,2):RoomB,
    176. (2,2):RoomC,
    177. (2,1):RoomD,
    178. }
    179. def parser():
    180. while Player.state == 'alive':
    181. print Player.printlocation(Player.location)
    182. Decisionst = raw_input('>')
    183. Decisionstr = Decisionst.lower()
    184. lst = shlex.split(Decisionstr)
    185. if lst[0] == 'go':
    186. Player.go(Player.location,Decisionstr)
    187. elif lst[0] == 'take':
    188. Player.take(Player.location, Decisionstr)
    189. elif lst[0] == 'quit':
    190. break
    191. elif lst[0] == 'talk':
    192. Player.talk(Player.location, Decisionstr)
    193. elif lst[0] == 'kill':
    194. kill(Decisionstr)
    195. elif lst[0] == 'inventory':
    196. inv()
    197. elif lst[0] == 'win':
    198. print 'nice try'
    199. else:
    200. print 'This doesnt work'
    201. parser()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /