#!/usr/bin/env ruby require "rubygems" require "optparse" require "readline" require "highline" # for testing inside gem dir $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require "room" def usage puts "usage: room" puts " room for [room name]" exit end def find_room name files = [] files << "#{name}.rb" files << File.join(File.dirname(__FILE__), "..", "rooms", "#{name}.rb") files.find { |f| File.readable? f } end opts = OptionParser.new opts.on("-h", "--help") { usage } opts.parse! ARGV if ARGV.length > 0 if ARGV[0] == "for" && !ARGV[1].nil? @room = ARGV[1] @filename = find_room ARGV[1] unless @filename puts "room \"#{ARGV[1]}\" not found" exit 1 end else usage end else @room = "beginners" @filename = find_room "beginners" end reload! @room, @filename if Array === $state[:history] $state[:history].each { |h| Readline::HISTORY.push h } else $state[:history] = [] end 3.times { Printer.puts } trap("INT", "SIG_IGN") Room.do "look" loop do line = if $secretive $secretive = false HighLine.new.ask("> ") { |q| q.echo = false } else x = Readline.readline("> ", true) $state[:history] << x if x x end save! break unless line Room.do line.chomp save! end Printer.puts "\nThe world is your cantaloupe."