// The Hollow Cottage // Chapter 8 const cottageName = "The Hollow Cottage" 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 = num(input("Turn the dial to a number (1-100): ")) guessesLeft = guessesLeft - 1 if guess == secret then writeln("The chest clicks open!") found = true else var distance = abs(guess - secret) if distance <= 5 then writeln("Very warm. " + guessesLeft + " turns left.") else if distance <= 20 then writeln("Warm. " + guessesLeft + " turns left.") else writeln("Cold. " + guessesLeft + " turns left.") end if 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] if verb == "take" then showInventory(inventory) else if verb == "look" then writeln("A small cottage, one room, one door out.") else if verb == "quit" then writeln("You step back out into the cold.") else if verb == "exit" then writeln("You step back out into the cold.") else writeln("Nothing happens.") end if end if