Advertisement
selib

Text Adventure

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