Sha256: a721462339d9e1473204f4dc01c0e9a74a37e0b5009407f4a8d240f41554e889
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Gamefic # Basic functionality for running a single-player game from a console. # class Engine::Base attr_writer :user_class attr_reader :plot def initialize(plot) @plot = plot post_initialize end def post_initialize # Override in subclasses end def user_class @user_class ||= Gamefic::User::Base end def connect @character = @plot.make Character, name: 'yourself', synonyms: 'self myself you me', proper_named: true @user = user_class.new @character.connect @user @character end def run connect @plot.introduce @character @user.update @character.state turn until @character.concluded? #print @user.flush end def turn @plot.ready unless @character.state[:options].nil? list = '<ol class="multiple_choice">' @character.state[:options].each { |o| list += "<li><a href=\"#\" rel=\"gamefic\" data-command=\"#{o}\">#{o}</a></li>" } list += "</ol>" @character.tell list end #print @user.flush @user.update @character.state #@character.flush if @character.queue.empty? receive end @plot.update #print @user.flush @user.update @character.state #@character.flush end def receive print @character.scene.prompt + ' ' input = STDIN.gets @character.queue.push input unless input.nil? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gamefic-1.6.0 | lib/gamefic/engine/base.rb |