Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- import random
- cave_numbers = range(0, 20)
- caves =[]
- for i in cave_numbers:
- caves.append([])
- unvisited_caves = range(0,20)
- visited_caves = [0]
- #unvisited caves == []
- unvisited_caves.remove(0)
- while unvisited_caves != []:
- i = choice(visited_caves)
- if len(caves[i]) >= 3:
- break
- next_cave = choice(unvisited_caves)
- caves[i].append(next_cave)
- caves[next_cave].append(i)
- visited_caves.append(next_cave)
- unvisited_caves.remove(next_cave)
- for number in cave_numbers:
- print number, ":", caves[number]
- print '----------'
- for i in cave_numbers:
- while len(caves[i]) < 3:
- passage_to = choice(cave_numbers)
- caves[i].append(passage_to)
- for i in cave_numbers:
- while len(caves[i]) < 3:
- passage_to = choice(cave_numbers)
- caves[i].append(passage_to)
- for number in cave_numbers:
- print number, ":", caves[number]
- print '----------'
- for i in cave_numbers:
- for j in range(3):
- passage_to = choice(cave_numbers)
- caves[i].append(passage_to)
- def print_location(player_location):
- """ Tell the player where they are """
- print
- print cave_names[player_location]
- print "From here, you can see:"
- neighbors = caves[player_location]
- for tunnel in range (0,3):
- #next_cave = neighbors[tunnel]
- next_cave = caves[player_location][tunnel]
- print " ", tunnel+1, "-", cave_names[next_cave]
- if wumpus_location in neighbors:
- print "I smell a wumpus!"
- def setup_caves(cave_numbers):
- """ Create the starting list of caves """
- caves = []
- for cave in cave_numbers:
- caves.append([])
- return caves
- def link_caves():
- """ Make sure all of the caves are conneceted with two-way tunnels """
- while unvisited_caves != []:
- this_cave = choose_cave(visited_caves)
- next_cave = choose_cave(unvisited_caves)
- create_tunnel(this_cave, next_cave)
- visit_cave(next_cave)
- def finish_caves():
- """ Link the rest of the caves with one-way tunnels """
- for cave in cave_numbers:
- while len(caves[cave]) < 3:
- passage_to = choose_cave(cave_numbers)
- caves[cave].append(passage_to)
- def ask_for_cave():
- """Ask the player to choose a cave from their current_location."""
- player_input = raw_input("Which cave?")
- if player_input in ['1', '2', '3']:
- index = int(player_input) - 1
- neighbors = caves[player_location]
- cave_number = neighbors[index]
- return cave_number
- else:
- print player_input + "?"
- print "That's not a direction I can see!"
- return False
- def get_action():
- """ Find out what the player wants to do next. """
- print "What do you do next?"
- print " m) move"
- print " a) fire an arrow"
- action = raw_input(">")
- if action == "m" or action == "a":
- return action
- else:
- print action + "?"
- print "That's not an action that I know about"
- return None
- def do_movement():
- print "Moving...."
- new_location = ask_for_cave()
- if new_location is None:
- return player_location
- else:
- return new_location
- def do_shooting():
- print "Firing..."
- shoot_at = ask_for_cave()
- if shoot_at is None:
- return False
- if shoot_at == wumpus_location:
- print "Kapow! Well done buddy, you shot the mighty wumpus!"
- print "You are the mighty wumpus hunter."
- else:
- print "Twang... clatter, clatter!"
- print "You wasted your ONLY arrow!"
- print "Empty handed, you begin the "
- print "long trek back to your village. A failure."
- return True
- cave_names = [
- "Screaming Shadows",
- "Black Wizards Pass",
- "Transylvanian Hunger Way",
- "Dead Skin Masked Throughfare",
- "Sleepy Hallows",
- "Black Metal Halls",
- "Painkiller Pass",
- "Deadhall Chasm",
- "Old Crusted Gateway",
- "Haunted Hall",
- "Gloomy Gus",
- "Moldy Pits",
- "Hall of the Dead",
- "Silent Screams",
- "Abigails Way",
- "Wumpus Lair",
- "Wumpus Nest",
- "Wumpus Main Avenue",
- "Dark Shadows",
- "Sandman Hall",
- ]
- #...
- print caves
- wumpus_location = choice(cave_numbers)
- player_location = choice(cave_numbers)
- #while player_location == wumpus_location
- player_location = choice(cave_numbers)
- print "Welcome to Hunt the Wumpus!"
- print "You can see", len(cave_numbers), "caves"
- print "To play, just type the number"
- print "of the cave you wish to enter next"
- while 1:
- print_location(player_location)
- action = get_action()
- if action is None:
- continue
- if action == "m":
- player_location = do_movement()
- if player_location == wumpus_location:
- print "Argh, the wumpus ATE you!"
- print "Game over bro, game over!"
- break
- if action == "a":
- game_over = do_shooting()
- if game_over:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement