// The Hollow Cottage // Chapter 11 const cottageName = "The Hollow Cottage" var score = 0 function addScore(amount) score = score + amount writeln("(+" + amount + " points)") end function function showInventory(items) writeln("You are carrying:") for each item in items writeln("- " + item) end for end function writeln("You are standing outside " + cottageName + ".") var playerName = input("What is your name, traveler? ") writeln("Welcome, " + playerName + ".") var tries = 0 var solved = false while tries < 3 and not solved tries = tries + 1 var answer = input("There is a riddle carved into the door. It asks: what has keys but no locks? ") if lower(trim(answer)) == "piano" then writeln("The door swings open. You step inside.") solved = true else writeln("Nothing happens.") end if end while if not solved then writeln("The door refuses to budge. You'll have to find another way in.") else writeln("You step inside. In the corner sits a locked chest with a dial numbered 1 to 100.") var secret = randomint(1, 100) var guessesLeft = 6 var found = false while guessesLeft > 0 and not found var guess = empty var validInput = false while not validInput attempt guess = num(input("Turn the dial to a number (1-100): ")) validInput = true error writeln("That doesn't look like a number. Try again.") end attempt end while guessesLeft = guessesLeft - 1 if guess == secret then writeln("The chest clicks open!") found = true addScore(10) else var distance = abs(guess - secret) match distance when 0 to 5 writeln("Very warm. " + guessesLeft + " turns left.") when 6 to 20 writeln("Warm. " + guessesLeft + " turns left.") when else writeln("Cold. " + guessesLeft + " turns left.") end match end if end while var inventory = array() append(inventory, "rusty key") append(inventory, "half-burned candle") if not found then writeln("The dial jams. The chest stays locked, for now.") else append(inventory, "small silver coin") writeln("Inside, you find a small silver coin.") showInventory(inventory) end if var command = input("What do you do? ") var words = split(lower(trim(command)), " ") var verb = words[0] match verb when "take" showInventory(inventory) when "look" writeln("A small cottage, one room, one door out.") when "quit" when "exit" writeln("You step back out into the cold.") when else writeln("Nothing happens.") end match writeln("Final score: " + score) end if