Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
- require 'loader'
- require 'world'
- class Game
- include Loader
- attr_accessor :world
- def initialize(story_path, options={})
- @input = options.fetch(:input) { $stdin }
- @output = options.fetch(:output) { $stdout }
- @world = World.new load(story_path)
- end
- def play!
- start!
- execute_one_command! until ended?
- end
- def start!
- @output.puts @world.start
- @output.print "> "
- end
- def execute_one_command!
- input = @input.gets
- output = @world.execute!(input)
- @output.puts output unless output.empty?
- @output.print "> " unless ended?
- end
- def ended?
- @world.ended?
- end
- end
- if $PROGRAM_NAME == __FILE__
- story_path = ARGV[0]
- unless story_path
- warn "Usage: #{$PROGRAM_NAME} STORY_FILE"
- exit 1
- end
- game = Game.new(story_path)
- game.play!
- end
Add Comment
Please, Sign In to add comment