Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import threading
  2.  
  3. def showInstructions():
  4. #print a main menu and the commands
  5. print('''
  6. Survival horror
  7. ===============
  8. Commands:
  9. go [direction]
  10. get [item]
  11. You have only 2 minutes to escape!!
  12. ''')
  13.  
  14.  
  15. def GameOver():
  16. print('Time is out! GAME OVER!!!!!!!!!')
  17.  
  18.  
  19. def showStatus():
  20. #print the player's current status
  21. print("---------------------------")
  22. print("You are in the " + rooms[currentRoom]["name"])
  23. #print the current inventory
  24. print("Inventory : " + str(inventory))
  25. #print an item if there is one
  26. if "item" in rooms[currentRoom]:
  27. print("You see a " + rooms[currentRoom]["item"])
  28. print("---------------------------")
  29.  
  30. #an inventory, which is initially empty
  31. inventory = []
  32.  
  33. #a dictionary linking a room to other room positions
  34. rooms = {
  35. 'room_1':{
  36. "name" : "hallWay",
  37. "west" : "room_2",
  38. "east" : "room_4",
  39. "item" : "documents",
  40. },
  41. 'room_2':{
  42. "name" : "terfd",
  43. "north" : "room_3",
  44. "east" : "room_6",
  45. "south": "room_1",
  46. "item" : "phone",
  47. },
  48. 'room_3':{
  49. "name" : "homeTheater",
  50. "south" : "room_2",
  51. "item" : "monster",
  52. },
  53. 'room_4':{
  54. "name" : "kitchen",
  55. "east" : "room_5",
  56. "item" : "gun",
  57. },
  58. 'room_5':{
  59. "name" : "toilet",
  60. "south" : "room_4",
  61. "item" : "monster",
  62. },
  63. 'room_6':{
  64. "name" : "bedRoom",
  65. "west": "room_7",
  66. "south" : "room_2",
  67. },
  68. 'room_7':{
  69. "name": "closet",
  70. "south": "room_6",
  71. "north" : "exit",
  72. "item": "key",
  73. },
  74. 'exit':{
  75. "name": "exit",
  76. "item": "exit",
  77. },
  78.  
  79. }
  80. #start the player in room 1
  81. currentRoom = 'room_1'
  82.  
  83. showInstructions()
  84.  
  85.  
  86. t = threading.Timer(120, GameOver)
  87. t.start()
  88.  
  89. #loop infinitely
  90. while True:
  91.  
  92. showStatus()
  93.  
  94. #get the player's next 'move'
  95. #.split() breaks it up into an list array
  96. #eg typing 'go east' would give the list:
  97. #['go','east']
  98. move = input(">").lower().split()
  99.  
  100. #if they type 'go' first
  101. if move[0] == "go":
  102. #check that they are allowed wherever they want to go
  103. if move[1] in rooms[currentRoom]:
  104. #set the current room to the new room
  105. currentRoom = rooms[currentRoom][move[1]]
  106. #there is no door (link) to the new room
  107. else:
  108. print("You can't go that way!")
  109.  
  110. #if they type 'get' first
  111. if move[0] == "get" :
  112. #if the room contains an item, and the item is the one they want to get
  113. if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]["item"]:
  114. #add the item to their inventory
  115. inventory += [move[1]]
  116. #display a helpful message
  117. print(move[1] + " got!")
  118. #delete the item from the room
  119. del rooms[currentRoom]["item"]
  120. #otherwise, if the item isn't there to get
  121. else:
  122. #tell them they can't get it
  123. print("Can't get " + move[1] + "!")
  124.  
  125. if "item" in rooms[currentRoom] and "monster" in rooms[currentRoom]["item"]:
  126. print("A monster has got you... GAME OVER!")
  127. print("Press any key to quit")
  128. input()
  129. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement