SHARE
    TWEET
    selib

    Text Adventure

    Nov 7th, 2013
    277
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    text 9.71 KB | None | 0 0
    1. #Text Adventure
    2. import shlex
    3. print
    4. #prints the map for the thing
    5. def map():
    6. print ' ___________________'
    7. print '| | |'
    8. print '| | |'
    9. print '| Room B = Room D |'
    10. print '| Jack | Sword |'
    11. print '| | |'
    12. print '|----||---|----||---|'
    13. print '| | |'
    14. print '| Steve | |'
    15. print '| Room A = Room C |'
    16. print '|_________|_________|'
    17. #Defines a Room Object
    18. class Room(object):
    19. def __init__(self, location, description,people,items):
    20. self.location = location
    21. self.description = description
    22. self.people = people
    23. self.items = items
    24. def display_Room(self):
    25. print self.description
    26. #Defines People
    27. class People(object):
    28. def __init__(self,name,text,state):
    29. self.name = name
    30. self.text = text
    31. self.state = state
    32. def talk(self):
    33. print self.text
    34. #Defines Items
    35. class Item(object):
    36. def __init__(self,name,text,location):
    37. self.name = name
    38. self.text = text
    39. self.location = location
    40. def exam(self):
    41. print self.text
    42. #Creates da stuff
    43. Sword = Item('Sword','This is a sword','22')
    44. Gold = Item('Gold','This is gold','-')
    45. Player = People('Player','','alive')
    46. Steve = People('Steve',"Hi, I'm Steve. Dude, can you do me favor? Kill Jack",'alive')
    47. Jack = People('Steve',"Sup, I'm Jack",'alive')
    48. Jesse = People('Jesse','Go away.','alive')
    49. #This doesn't really do something right now
    50. #since I didn't really know how to implement it:(
    51. peopleinroomA = [Steve]
    52. peopleinroomB = [Jack]
    53. peopleinroomC = []
    54. peopleinroomD = [Jesse]
    55. itemsinroomA = []
    56. itemsinroomB = []
    57. itemsinroomC = []
    58. itemsinroomD = [Sword]
    59. RoomA = Room(1001,'You are in Room A. You see Steve',peopleinroomA,itemsinroomA)
    60. RoomB = Room(2001,'You are in Room B. Jack is here',peopleinroomB,itemsinroomB)
    61. RoomC = Room(1002,'You are in Room C.You see Jesse',peopleinroomC,itemsinroomC)
    62. RoomD = Room(2002,'You are in Room D. You see sword' ,peopleinroomD,itemsinroomD)
    63. #defines the rooms that exist in the game
    64. definedlocations = [RoomA.location,RoomB.location,RoomC.location,RoomD.location]
    65. #defines the players location
    66. location = {'xy':1001}
    67. #opens up a open inventory list
    68. Inventory = []
    69. #adds to player location. 1000 for y values, 1 for the x values
    70. #if a new location doesn't exist in the definedlocations list,
    71. # it doesn't let you go there
    72. def go(Decision,location):
    73. test_n = location['xy']
    74. test_n += 1000
    75. test_s = location['xy']
    76. test_s -= 1000
    77. test_e = location['xy']
    78. test_e += 1
    79. test_w = location['xy']
    80. test_w -= 1
    81. if Decision == 'go north':
    82. if test_n in definedlocations:
    83. location['xy'] += 1000
    84. else:
    85. print "You can't go there"
    86. elif Decision == 'go south':
    87. if test_s in definedlocations:
    88. location['xy'] -= 1000
    89. else:
    90. print "You can't go there"
    91. elif Decision == 'go east':
    92. if test_e in definedlocations:
    93. location['xy'] += 1
    94. else:
    95. print "You can't go there"
    96. elif Decision == 'go west':
    97. if test_w in definedlocations:
    98. location['xy'] -= 1
    99. else:
    100. print "You can't go there"
    101. #decides what the person says, that you talk to
    102. def talk(Decision):
    103. if Decision == 'talk steve' or Decision == 'talk to steve':
    104. if location['xy'] == 1001:
    105. if Jack.state == 'dead':
    106. print 'You killed Jack! Take this is a reward.'
    107. print 'Gold added to Inventory'
    108. Inventory.append('Gold')
    109. elif Steve.state == 'dead':
    110. print 'This person is dead.'\
    111. else:
    112. Steve.talk()
    113. else:
    114. print "This person is not here."
    115. elif Decision == 'talk jack' or Decision == 'talk to jack':
    116. if location['xy'] == 2001:
    117. if Jack.state == 'dead':
    118. print 'This person is dead.'
    119. else:
    120. Jack.talk()
    121. else:
    122. print 'This person is not here'
    123. else:
    124. print 'thing'
    125. if Decision == 'talk jesse' or Decision == 'talk to jesse':
    126. if location['xy'] == 1002:
    127. if Jesse.state == 'dead':
    128. print 'This person is dead'
    129. elif 'Gold' in Inventory:
    130. Drug = raw_input('You wanna buy some drugs?')
    131. if Drug == 'no':
    132. print 'Bitch'
    133. elif Drug == 'yes':
    134. Inventory.remove('Gold')
    135. Inventory.append('Meth')
    136. print 'Meth added to Inventory'
    137. else:
    138. print 'k'
    139. else:
    140. Jesse.talk()
    141. else:
    142. print 'This person is not here'
    143. #adds something to your inventroy
    144. def take(Decision):
    145. if Decision == 'take sword':
    146. if location['xy'] == 2002:
    147. Inventory.append('Sword')
    148. print 'Taken'
    149. RoomD.description = 'You are in Room D.'
    150. if Decision == 'take drugs' or 'take meth':
    151. if 'Meth' in Inventory:
    152. print 'YOU ARE HIGH'
    153. else:
    154. print "You can't do that"
    155. #prints the inventory
    156. def Inv():
    157. print Inventory
    158. #gives back the item description
    159. def examine(Dec):
    160. Decision = Dec.lower()
    161. if Decision == 'examine gold':
    162. if 'Gold' in Inventory:
    163. Gold.exam()
    164. else:
    165. print "You can't do that."
    166. if Decision == 'examine sword':
    167. if 'Sword' in Inventory:
    168. Sword.exam()
    169. elif location['xy'] == 2002:
    170. Sword.exam()
    171. else:
    172. print "You can't do that"
    173. if Decision == 'examine meth':
    174. if 'Meth' in Inventory:
    175. Meth.exam()
    176. else:
    177. print "You can't do that'"
    178. #kills someone, but only if you have the right weapon
    179. def kill(Decision):
    180. if Decision == 'kill steve':
    181. Dec = raw_input('Kill Steve with what?')
    182. Dec2 = Dec.lower()
    183. if Dec2 == 'sword':
    184. if 'Sword' in Inventory:
    185. Steve.state = 'dead'
    186. print 'Steve died'
    187. RoomA.description = "You are in Room A. You see Steve's dead body"
    188. else:
    189. print "You can't do that"
    190. else:
    191. print "You can't do that"
    192. elif Decision == 'kill jack':
    193. Dec = raw_input('Kill Jack with what?')
    194. Dec2 = Dec.lower()
    195. if Dec2 == 'sword':
    196. if 'Sword' in Inventory:
    197. Jack.state = 'dead'
    198. print 'Jack died'
    199. RoomB.description = "You are in Room B. You see Jack's dead body"
    200. else:
    201. print "You can't do that"
    202. else:
    203. print "You can't do that"
    204. elif Decision == 'kill myself':
    205. Dec = raw_input('Kill yourself with what?')
    206. Dec2 = Dec.lower()
    207. if Dec2 == 'sword':
    208. if 'Sword' in Inventory:
    209. print 'You killed yourself. Good job. Really.'
    210. print 'Game Over I guess'
    211. Player.state = 'dead'
    212. else:
    213. print "You can't do that"
    214. else:
    215. print "You can't do that"
    216. if Decision == "kill steve with sword":
    217. if 'Sword' in Inventory:
    218. if 'Sword' in Inventory:
    219. Steve.state = 'dead'
    220. print 'Steve died'
    221. RoomA.description = "You are in Room A. You see Steve's dead body"
    222. else:
    223. print "You can't do that"
    224. else:
    225. print "You can't do that"
    226. if Decision == "kill jack with sword":
    227. if 'Sword' in Inventory:
    228. Jack.state = 'dead'
    229. print 'Jack died'
    230. print Jack.state
    231. RoomB.description = "You are in Room B. You see Jack's dead body"
    232. else:
    233. print "You can't do that"
    234. if Decision == "kill myself with sword":
    235. if 'Sword' in Inventory:
    236. print 'You killed yourself. Good job. Really.'
    237. print 'Game Over I guess'
    238. Player.state = 'dead'
    239. else:
    240. print "You can't do that"
    241. def help():
    242. print "You can use the following commands:"
    243. print "talk (person)"
    244. print "kill (person) with (item)"
    245. print "take (item)"
    246. print "inventory"
    247. print "examine (item)"
    248. print "quit"
    249. #gives back the current location
    250. def printlocation(location):
    251. if location['xy'] == 1001:
    252. RoomA.display_Room()
    253. elif location['xy'] == 2001:
    254. RoomB.display_Room()
    255. elif location['xy'] == 1002:
    256. RoomC.display_Room()
    257. elif location['xy'] == 2002:
    258. RoomD.display_Room()
    259. #the parser
    260. #checks the first word in a command and then uses the corresponding funtion
    261. def parser():
    262. while Player.state == 'alive':
    263. printlocation(location)
    264. Decisionst = raw_input('>')
    265. Decisionstr = Decisionst.lower()
    266. lst = shlex.split(Decisionstr)
    267. if lst[0] == 'go':
    268. go(Decisionstr,location)
    269. elif lst[0] == 'talk':
    270. talk(Decisionstr)
    271. elif lst[0] == 'take':
    272. take(Decisionstr)
    273. elif lst[0] == 'inventory':
    274. Inv()
    275. elif lst[0] == 'kill':
    276. kill(Decisionstr)
    277. elif lst[0] == 'examine':
    278. examine(Decisionstr)
    279. elif lst[0] == 'help':
    280. help()
    281. elif lst[0] == 'win':
    282. print 'nice try'
    283. elif Decisionstr == 'quit':
    284. break
    285. else:
    286. print "Try again"
    287. map()
    288. 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 によって変換されたページ (->オリジナル) /