Guest User

Untitled

a guest
May 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.95 KB | None | 0 0
  1. import characters as char
  2. import items as item
  3. import random as ran
  4. import time
  5.  
  6.  
  7. class Room(object):
  8. def __init__(self, name, description, north, south, east, west):
  9. self.name = name
  10. self.desc = description
  11. self.north = north
  12. self.south = south
  13. self.east = east
  14. self.west = west
  15.  
  16. def move(self, direction):
  17. global current
  18. current = globals()[getattr(self, direction)]
  19. print(current.name + '\n' + current.desc)
  20.  
  21.  
  22. # Extra Variables
  23. wait = time.sleep
  24. _low = str.lower
  25. _isi = isinstance
  26. _nil = []
  27.  
  28.  
  29. mid_hall_desc = "You see a light at the end of the hallway."
  30. corner_desc = "You are at the end of the hallway. There is a way in every direction."
  31. s_bridge_desc = "You are at the start of a bridge."
  32. elevator_desc = "You step into the elevator, but upon stepping into it, you feel very unstable."
  33. e_bridge_desc = "You are at the end of the bridge."
  34. auth_desc = "You are in front of a small military building."
  35. in_desc = "You are inside of the small military building."
  36. cam_desc = "Numerous amounts of screens, viewing every room that you've been in.\nEven the one you're in right now ..."
  37. pain_desc = "смерть неизбежна"
  38.  
  39. # Room Instantiation
  40.  
  41. # West Map
  42. light_room = Room("Light Room", "You are in a room with a dimly lit light above.", None, None, None, "hallway")
  43. hallway = Room("Hallway", "You are in a dark hallway.", None, "mid_hallway", "light_room", "elevator")
  44. mid_hallway = Room("Hallway", mid_hall_desc, "hallway", "corner", "dark_room2", "lift")
  45. elevator = Room("Elevator", elevator_desc, None, None, "hallway", None)
  46. dark_room = Room("Dark Room", "You are in a room with no light.", None, None, "mid_hallway", None)
  47. dark_room2 = Room("Dark Room", "You are in a room with no light.", None, None, None, "mid_hallway")
  48.  
  49. corner = Room("End of Hallway", corner_desc, "mid_hallway", "stairs", "start_bridge", "closet")
  50.  
  51. # Intersection
  52. closet = Room("Closet", "You enter a small closet.", None, None, "corner", None)
  53.  
  54. # South Map
  55. lounge = Room("Lounge Area", "You are in, what seems like, a hangout spot.", "stairs", None, "hole", "bar")
  56. bar = Room("Bar", "You are in a small bar.", None, None, "lounge", None)
  57. hole = Room("Hole", "You are in front of a deeply dug hole.", "pit", None, "in_hole", None)
  58. in_hole = Room("Inside of Hole", "You are in a pile of rotten screech corpses.", None, None, None, "hole")
  59. pit = Room("Pit of Garbage", "You are in front of a pit of garbage.", "start_bridge", "hole", "in_pit", None)
  60. in_pit = Room("Inside of Pit", "You step into the pile of trash.", None, None, None, "pit")
  61.  
  62. # Middle Map
  63. start_bridge = Room("Start of Bridge", s_bridge_desc, None, "pit", "bridge", "corner")
  64. bridge = Room("Bridge", "You are at the middle of the bridge.", None, None, "end_bridge", "start_bridge")
  65. end_bridge = Room("End of Bridge", e_bridge_desc, None, None, "authority", "bridge")
  66.  
  67. # East Map
  68. authority = Room("Front of Military Building", auth_desc, "alley", "cliff", "inside", "end_bridge")
  69. alley = Room("Alley Way", "You are in a dark alley way.", None, "authority", "cliff", None)
  70. inside = Room("Inside of Military Building", in_desc, "camera", "locker", "hatch", "authority")
  71. camera = Room("Camera Room", cam_desc, "pain", inside, None, None)
  72. pain = Room("боль", pain_desc, None, "camera", None, None)
  73. locker = Room("Locker Room", "You are in a locker room, with 5 different rows.", "inside", "row1", None, None)
  74. row1 = Room("Row One", "You are in the first row in the locker room.", "locker", "row2", None, None)
  75. row2 = Room("Row Two", "You are in the second row in the locker room.", "row1", "row3", None, None)
  76. row3 = Room("Row Three", "You are in the third row in the locker room.", "row2", "row4", None, None)
  77. row4 = Room("Row Four", "You are in the fourth row in the locker room.", "row3", "row5", None, None)
  78. row5 = Room("Row Five", "You are in the fifth row in the locker room.", "row4", None, None, None)
  79. hatch = Room("Hatch Room", "You are in a small room with only a hatch on the floor", None, None, None, "inside")
  80.  
  81. # Item Instantiation
  82. expired_beans = item.BadFood("Expired Beans", "A can of expired beans.", light_room, False, 15, 10)
  83. water_bottle = item.Beverage("Water Bottle", "A clear bottle of water.", light_room, False, 25)
  84. rusty_nail = item.BadMelee("Rusty Nail", "A short, bent, rusty nail.", light_room, False, 15, 15, False)
  85. plastic_bag = item.Bag("Plastic Bag", "A tiny plastic bag used for storage.", light_room, False, 5, False)
  86.  
  87. # Enemy Items
  88. s_body1 = item.BadFood("Screech Arm", "A skinny arm, with bloody white meat.", mid_hallway, True, 20, 25)
  89. s_body2 = item.BadFood("Screech Leg", "A skinny leg, with bloody white meat.", lounge, True, 25, 30)
  90.  
  91. item_list = [expired_beans, water_bottle, rusty_nail, plastic_bag, s_body1, s_body2]
  92.  
  93. # Enemy Instantiation
  94. screech = char.Enemy("Screech", "A limping humanoid with a gaping mouth.", 50, mid_hallway, s_body1)
  95. screech2 = char.Enemy("Screech", "A limping humanoid with a gaping mouth.", 50, lounge, s_body2)
  96. enemy_list = [screech, screech2]
  97.  
  98.  
  99. def put(__item):
  100. item_list.remove(_item)
  101. item_list.append(__item)
  102.  
  103.  
  104. # Player Variables
  105. health = 100
  106. hunger = 50
  107. thirst = 50
  108. room = 5
  109. starving = False
  110. thirsty = False
  111. inventory = []
  112. current = light_room
  113. weapon = None
  114. backpack = None
  115.  
  116.  
  117. # Functions
  118. def eat(command, _item, hp, hg):
  119. if _low(_item.name) in command:
  120. if _isi(_item, item.BadFood):
  121. hp -= _item.health
  122. hg += _item.hunger
  123. print("You ate the %s, but it didn't taste so good." % _item.name)
  124. elif _isi(_item, item.Food):
  125. hg += _item.hunger
  126. print("You ate the %s." % _item.name)
  127.  
  128.  
  129. def take(command, _item):
  130. _b = item.BadMelee
  131. _m = item.Melee
  132. _bg = item.Bag
  133. _bp = item.Backpack
  134. _hbp = item.HeavyBackpack
  135. if _low(_item.name) in command and _item.room is current and not _item.pick:
  136. item_list.remove(_item)
  137. inventory.append(_item)
  138. _item.pick = True
  139. if _isi(_item, _b) or _isi(_item, _m) or _isi(_item, _bg) or _isi(_item, _bp) or _isi(_item, _hbp):
  140. print("You took the %s, but you need to equip it before you can use it." % _low(_item.name))
  141. else:
  142. print("You took the %s" % _low(_item.name))
  143.  
  144.  
  145. def drop(command, _item):
  146. if _low(_item.name) in command and _item.pick:
  147. inventory.remove(_item)
  148. item_list.append(_item)
  149. _item.pick = False
  150. print("You dropped the %s" % _low(_item.name))
  151.  
  152.  
  153. def view_room():
  154. items = False
  155. print(current.name + '\n' + current.desc)
  156. for __item in item_list:
  157. if __item.room is current:
  158. items = True
  159. if items:
  160. print("There are items in the room.")
  161.  
  162.  
  163. def view_items(_item):
  164. if _item.room is current:
  165. print(' - ' + _item.name)
  166.  
  167.  
  168. def use(command, _item):
  169. if _low(_item.name) in command:
  170. if not _item.used:
  171. if _isi(_item, item.BadMelee) or _isi(_item, item.Melee):
  172. _item.used = True
  173. print("You equipped the %s" % _low(_item.name))
  174. elif _isi(_item, item.Bag) or _isi(_item, item.Backpack) or _isi(_item, item.HeavyBackpack):
  175. _item.used = True
  176. print("You wore the %s" % _low(_item.name))
  177. else:
  178. print("You cannot do that now.")
  179.  
  180.  
  181. def remove(command, _item):
  182. if _low(_item.name) in command:
  183. if _item.used:
  184. _item.used = False
  185. print("You removed the %s" % _low(_item.name))
  186. else:
  187. print("You cannot remove that")
  188.  
  189.  
  190. def view_statistics():
  191. print("Your current health is %d\nYour current hunger is %d" % (health, hunger))
  192. print("Your current thirst is %d\nYour current inventory space is %d" % (thirst, room))
  193. if backpack is not None:
  194. print("Your current backpack is : %s" % backpack.name)
  195. if weapon is not None:
  196. print("Your current weapon is : %s" % weapon.name)
  197.  
  198.  
  199. def view_inventory(_item):
  200. if _item.used:
  201. print(' - ' + _item.name + ' [USING]')
  202. else:
  203. print(' - ' + _item.name)
  204.  
  205.  
  206. directions = ['north', 'south', 'east', 'west']
  207. short = ['n', 's', 'e', 'w']
  208.  
  209.  
  210. def move(direction):
  211. try:
  212. current.move(direction)
  213. except KeyError:
  214. print("You can't move that way.")
  215.  
  216.  
  217. def attack(command, health, plr_weapon):
  218. accuracy = ran.randint(0, 2)
  219. if _low(enemy.name) in command and enemy.room is current:
  220. if weapon is not None and accuracy > 0:
  221. enemy.health -= weapon.damage
  222. print("You attacked %s." % enemy.name)
  223. elif accuracy is 0:
  224. print("You missed!\nThe %s took advantage and attacked you." % _low(enemy.name))
  225. health -= ran.randint(10, 20)
  226. elif weapon is None:
  227. print("You have no weapon to attack with, so you freeze out of fear.")
  228. wait(1)
  229. print("The %s sees your fear, and takes advantage." % _low(enemy.name))
  230. wait(1)
  231. print("The %s cracked your skull open." % _low(enemy.name))
  232. health -= health
  233. if enemy.health <= 0:
  234. print("You killed %s with your %s" % (_low(enemy.name), _low(plr_weapon.name)))
  235.  
  236.  
  237. while True:
  238. if hunger is 0:
  239. health -= 5
  240. if thirst is 0:
  241. health -= 5
  242. attack_accuracy = ran.randint(0, 2)
  243. cmd = _low(input('> ')).strip()
  244. if cmd in directions:
  245. if hunger < 0:
  246. hunger = 0
  247. if thirst < 0:
  248. thirst = 0
  249. move(cmd)
  250. if cmd == 'quit':
  251. quit(0)
  252. elif cmd in short:
  253. pos = short.index(cmd)
  254. move(directions[pos])
  255. elif cmd == 'look' or cmd == 'room':
  256. view_room()
  257. elif cmd == 'inventory':
  258. for _item in inventory:
  259. view_inventory(_item)
  260. elif cmd == "items":
  261. for _item in item_list:
  262. view_items(_item)
  263. elif cmd == 'stats' or cmd == 'statistics':
  264. view_statistics()
  265. elif 'take' in cmd:
  266. for _item in item_list:
  267. take(cmd, _item)
  268. elif 'drop' in cmd:
  269. for _item in inventory:
  270. drop(cmd, _item)
  271. elif 'eat' in cmd:
  272. for _item in inventory:
  273. eat(cmd, _item, health, hunger)
  274. elif 'use' in cmd:
  275. w = weapon
  276. b = backpack
  277. for _item in inventory:
  278. if _isi(_item, item.BadMelee) or _isi(_item, item.Melee):
  279. use(cmd, _item)
  280. elif _isi(_item, item.Bag) or _isi(_item, item.Backpack) or _isi(_item, item.HeavyBackpack):
  281. use(cmd, _item)
  282. elif 'remove' in cmd:
  283. w = weapon
  284. b = backpack
  285. bm = item.BadMelee
  286. m = item.Melee
  287. bg = item.Bag
  288. bp = item.Backpack
  289. hbp = item.HeavyBackpack
  290. for _item in inventory:
  291. if _isi(_item, bm) or _isi(_item, m) or _isi(_item, bg) or _isi(_item, bp) or _isi(_item, hbp):
  292. remove(cmd, _item)
  293. elif 'attack' in cmd:
  294. for enemy in enemy_list:
  295. if enemy.room is current:
  296. hp = health
  297. attack(cmd, hp, weapon)
  298. if health is 0:
  299. print("Too much damage has been inflicted on you.")
  300. wait(1)
  301. print("You are dead.")
  302. break
Add Comment
Please, Sign In to add comment