Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. # Since there are no methods needed for a player a dictionary may be a better option since this is only storing data.
  2.  
  3. player_location = "start_room"
  4.  
  5. player_data = {
  6. "name": "none", # This will come from input.
  7. "location": "You are at the start of the game in a small dining room in a small house.n", # The player will always start here.
  8. "location_name": "start_room",
  9. "health": 100
  10. }
  11.  
  12. # Create locations for the game with directions as to where a player can go in them.
  13. class Location:
  14. def __init__(self, moves, actions, keys):
  15. self.moves = moves
  16. self.actions = actions
  17. self.keys = keys
  18. self.description = "You are in a small dining room in a small house. There is no furniture in this room.nnYou are facing a short hallway leading to a staircase.nnThere is an open door to your left leading to a small porch.nnTo your right is the living room.nnThe area of the room back behind you is dark.nnThere is a light switch on the wall.nn"
  19.  
  20.  
  21. # ---------------------------------------------------------
  22. # This will print at the beginning of the game and every time a player enters "help".
  23.  
  24. def help_file():
  25.  
  26. print("n- - - - - - - - - - - - - - - - - - - - - - - - -n")
  27.  
  28. print("You will be exploring places and interacting with items in the game.n")
  29.  
  30. print("Please use words like 'forward', 'left', 'right' and 'back' for movement inside a structure.n")
  31.  
  32. print("Directions such as 'north' or 'n'; 'south' or 's'; 'east' or 'e'; and 'west' or 'w' will work when you are outside.n")
  33.  
  34. print("When you want to use an item in the game, just enter the name of the item like 'boomerang'. You will then be prompted for what you want to do with that item.n")
  35.  
  36. print("To see a description of where you are in a room or an area, just type 'description'.n")
  37.  
  38. print("To see this introductory list again, type 'help'.n")
  39.  
  40. print("When you are ready to continue, press the ENTER key.n")
  41. input()
  42.  
  43. print("n- - - - - - - - - - - - - - - - - - - - - - - - -n")
  44.  
  45.  
  46.  
  47. # ---------------------------------------------------------
  48. # The starting room:
  49.  
  50. # This creates a new object based on the Location class.
  51. # The two tuples are the moves list and the actions list for later validation.
  52.  
  53. start_room_keys = {"light": "off"}
  54.  
  55. start_room = Location(("stairs", "staircase", "forward", "porch", "left", "living room", "right", "back"),
  56. ("look", "light", "light switch", "box", "open"), start_room_keys)
  57.  
  58.  
  59. # Functions for a player move or action in this room:
  60. def start_room_moves_actions(player_input):
  61. if player_input in start_room.moves:
  62. start_room_moves(player_input)
  63. elif player_input in start_room.actions:
  64. start_room_action(player_input)
  65. else:
  66. print("nThat is not a valid request for this situation.n")
  67. play_game()
  68.  
  69.  
  70. def start_room_moves(player_move):
  71.  
  72. print()
  73.  
  74. if player_move == "stairs" or player_move == "staircase" or player_move == "forward":
  75. print("You walk to the bottom of the stairs. There is an old rug at the base of the stairs.")
  76. player_data["location"] = "At the bottom of the stairs in the small house"
  77. player_data["location_name"] = "house_stairs"
  78. elif player_move == "porch" or player_move == "left":
  79. print("You walk through the open door to the porch.")
  80. print("The view from here is spectacular. You are looking out over a wooded valley with a river far below.")
  81. print("There are rolling hills off in the distance.")
  82. print("You walk to the edge of the porch and see some letters carved in the railing.")
  83. print()
  84. print("RWBL")
  85. print()
  86. print("Hmm...I wonder what that means?n")
  87. player_data["location"] = "On the back porch of a small house."
  88. player_data["location_name"] = "house_porch"
  89. elif player_move == "right" or player_move == "living room":
  90. print("As you enter the living room you notice a large painting of a sunset scene over a wooded valley on one wall.n")
  91. player_data["location"] = "You are in the living room in a small house."
  92. player_data["location_name"] = "house_living_room"
  93. elif player_move == "back":
  94. if start_room.keys["light"] == "off":
  95. print("It is too dark to go in that direction. You should be more careful about where you go.n")
  96. else:
  97. print("There is an old shoe box in the back next to the wall.n")
  98.  
  99.  
  100. def start_room_action(player_action):
  101. if player_action == "look":
  102. print("There is no furniture in this room. There is an old hanging light fixture that has a bulb in the middle of the ceiling. There is a light switch to your right on the wall. The room back behind you is dark and you cannot see what is there.n")
  103. elif player_action == "light" or player_action == "light switch":
  104. print("nThe hanging light in the middle of the ceiling illuminates the room. There appears to be a box back of the room where it was previously dark.n")
  105. start_room.keys["light"] = "on"
  106. elif player_action == "box" or player_action == "open":
  107. if start_room.keys["light"] == "off":
  108. print("What are you trying to do? You need to lighten up.n")
  109. else:
  110. print("nThere is a brand new pair of running shoes in the box.n")
  111. print("As you take them out, you see...SOMETHING.n")
  112.  
  113.  
  114. # ---------------------------------------------------------
  115. # The porch:
  116.  
  117.  
  118. # ---------------------------------------------------------
  119. # The stairs:
  120.  
  121.  
  122. # ---------------------------------------------------------
  123. # The living room:
  124.  
  125.  
  126. # -------------------------------------------------------------
  127. # End of code/functions for individual rooms/locations.
  128. # -------------------------------------------------------------
  129.  
  130. # Get a name from player and update player object.
  131. print("Welcome to the game.")
  132.  
  133. def get_player_name():
  134. name_input = input("What is your name?")
  135.  
  136. if len(name_input) > 10 or len(name_input) < 1:
  137. print("Please enter a name with 0 - 10 letters.")
  138. get_player_name()
  139. else:
  140. player_data["name"] = name_input
  141.  
  142.  
  143. get_player_name()
  144.  
  145.  
  146. # Print welcome to player using name.
  147. print("nWelcome, " + str(player_data["name"]) + "!")
  148.  
  149. # Print the starting story text.
  150. # Print a description of the game with examples of valid entries.
  151. help_file()
  152.  
  153. # Print a description of the starting room.
  154. print(start_room.description)
  155.  
  156. # ---------------------------------------------------------
  157. # Main game loop
  158.  
  159. def play_game():
  160. # Get input from player for move or interaction.
  161. player_input = input("What would you like to do now?n")
  162.  
  163. # If 'description', then print the current location's description, and then prompt again for input.
  164. if player_input == "description":
  165. current_location = player_data["location"]
  166. print("n" + str(current_location))
  167. elif player_input == "help":
  168. help_file()
  169. elif player_input == "":
  170. print("Please try again.")
  171. else:
  172. # Get the name of the player's current location.
  173. current_location_name = player_data["location_name"]
  174. if current_location_name == "start_room":
  175. start_room_moves_actions(player_input)
  176.  
  177. # Add elif statements here checking for rooms.
  178.  
  179.  
  180. # Check to see if the game is over at this point.
  181. if player_data["health"] < 1:
  182. print("You are dead! Too bad. You seemed like a nice person.")
  183. else:
  184. play_game()
  185.  
  186.  
  187. play_game()
Add Comment
Please, Sign In to add comment