Advertisement
Guest User

Wumpus 018

a guest
Aug 3rd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. from random import choice
  2.  
  3. import random
  4.  
  5. cave_numbers = range(0, 20)
  6. caves =[]
  7.  
  8.  
  9. for i in cave_numbers:
  10. caves.append([])
  11.  
  12. unvisited_caves = range(0,20)
  13. visited_caves = [0]
  14. #unvisited caves == []
  15. unvisited_caves.remove(0)
  16.  
  17. while unvisited_caves != []:
  18. i = choice(visited_caves)
  19. if len(caves[i]) >= 3:
  20. break
  21.  
  22. next_cave = choice(unvisited_caves)
  23. caves[i].append(next_cave)
  24. caves[next_cave].append(i)
  25.  
  26. visited_caves.append(next_cave)
  27. unvisited_caves.remove(next_cave)
  28.  
  29. for number in cave_numbers:
  30. print number, ":", caves[number]
  31. print '----------'
  32.  
  33. for i in cave_numbers:
  34. while len(caves[i]) < 3:
  35. passage_to = choice(cave_numbers)
  36. caves[i].append(passage_to)
  37.  
  38. for i in cave_numbers:
  39. while len(caves[i]) < 3:
  40. passage_to = choice(cave_numbers)
  41. caves[i].append(passage_to)
  42.  
  43. for number in cave_numbers:
  44. print number, ":", caves[number]
  45. print '----------'
  46.  
  47. for i in cave_numbers:
  48. for j in range(3):
  49. passage_to = choice(cave_numbers)
  50. caves[i].append(passage_to)
  51.  
  52. def print_location(player_location):
  53. """ Tell the player where they are """
  54. print
  55. print cave_names[player_location]
  56. print "From here, you can see:"
  57. neighbors = caves[player_location]
  58. for tunnel in range (0,3):
  59. #next_cave = neighbors[tunnel]
  60. next_cave = caves[player_location][tunnel]
  61. print " ", tunnel+1, "-", cave_names[next_cave]
  62. if wumpus_location in neighbors:
  63. print "I smell a wumpus!"
  64.  
  65. def setup_caves(cave_numbers):
  66. """ Create the starting list of caves """
  67. caves = []
  68. for cave in cave_numbers:
  69. caves.append([])
  70. return caves
  71.  
  72. def link_caves():
  73. """ Make sure all of the caves are conneceted with two-way tunnels """
  74. while unvisited_caves != []:
  75. this_cave = choose_cave(visited_caves)
  76. next_cave = choose_cave(unvisited_caves)
  77. create_tunnel(this_cave, next_cave)
  78. visit_cave(next_cave)
  79.  
  80. def finish_caves():
  81. """ Link the rest of the caves with one-way tunnels """
  82. for cave in cave_numbers:
  83. while len(caves[cave]) < 3:
  84. passage_to = choose_cave(cave_numbers)
  85. caves[cave].append(passage_to)
  86.  
  87. def ask_for_cave():
  88. """Ask the player to choose a cave from their current_location."""
  89. player_input = raw_input("Which cave?")
  90. if player_input in ['1', '2', '3']:
  91. index = int(player_input) - 1
  92. neighbors = caves[player_location]
  93. cave_number = neighbors[index]
  94. return cave_number
  95. else:
  96. print player_input + "?"
  97. print "That's not a direction I can see!"
  98. return False
  99.  
  100.  
  101. def get_action():
  102. """ Find out what the player wants to do next. """
  103. print "What do you do next?"
  104. print " m) move"
  105. print " a) fire an arrow"
  106. action = raw_input(">")
  107. if action == "m" or action == "a":
  108. return action
  109. else:
  110. print action + "?"
  111. print "That's not an action that I know about"
  112. return None
  113.  
  114. def do_movement():
  115. print "Moving...."
  116. new_location = ask_for_cave()
  117. if new_location is None:
  118. return player_location
  119. else:
  120. return new_location
  121.  
  122. def do_shooting():
  123. print "Firing..."
  124. shoot_at = ask_for_cave()
  125. if shoot_at is None:
  126. return False
  127.  
  128. if shoot_at == wumpus_location:
  129. print "Kapow! Well done buddy, you shot the mighty wumpus!"
  130. print "You are the mighty wumpus hunter."
  131. else:
  132. print "Twang... clatter, clatter!"
  133. print "You wasted your ONLY arrow!"
  134. print "Empty handed, you begin the "
  135. print "long trek back to your village. A failure."
  136. return True
  137.  
  138. cave_names = [
  139. "Screaming Shadows",
  140. "Black Wizards Pass",
  141. "Transylvanian Hunger Way",
  142. "Dead Skin Masked Throughfare",
  143. "Sleepy Hallows",
  144. "Black Metal Halls",
  145. "Painkiller Pass",
  146. "Deadhall Chasm",
  147. "Old Crusted Gateway",
  148. "Haunted Hall",
  149. "Gloomy Gus",
  150. "Moldy Pits",
  151. "Hall of the Dead",
  152. "Silent Screams",
  153. "Abigails Way",
  154. "Wumpus Lair",
  155. "Wumpus Nest",
  156. "Wumpus Main Avenue",
  157. "Dark Shadows",
  158. "Sandman Hall",
  159. ]
  160.  
  161. #...
  162. print caves
  163. wumpus_location = choice(cave_numbers)
  164. player_location = choice(cave_numbers)
  165. #while player_location == wumpus_location
  166. player_location = choice(cave_numbers)
  167.  
  168. print "Welcome to Hunt the Wumpus!"
  169. print "You can see", len(cave_numbers), "caves"
  170. print "To play, just type the number"
  171. print "of the cave you wish to enter next"
  172.  
  173.  
  174. while 1:
  175. print_location(player_location)
  176.  
  177. action = get_action()
  178. if action is None:
  179. continue
  180.  
  181. if action == "m":
  182. player_location = do_movement()
  183. if player_location == wumpus_location:
  184. print "Argh, the wumpus ATE you!"
  185. print "Game over bro, game over!"
  186. break
  187.  
  188. if action == "a":
  189. game_over = do_shooting()
  190. if game_over:
  191. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement