Class: Gamefic::Engine::Base
- Inherits:
-
Object
- Object
- Gamefic::Engine::Base
- Defined in:
- lib/gamefic/engine/base.rb
Overview
Basic functionality for running a single-player game from a console.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#plot ⇒ Object
readonly
Returns the value of attribute plot.
- #user_class ⇒ Object
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(plot) ⇒ Base
constructor
A new instance of Base.
- #post_initialize ⇒ Object
- #receive ⇒ Object
- #run ⇒ Object
- #turn ⇒ Object
Constructor Details
#initialize(plot) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/gamefic/engine/base.rb', line 9 def initialize(plot) @plot = plot post_initialize end |
Instance Attribute Details
#plot ⇒ Object (readonly)
Returns the value of attribute plot.
7 8 9 |
# File 'lib/gamefic/engine/base.rb', line 7 def plot @plot end |
Instance Method Details
#connect ⇒ Object
22 23 24 25 26 27 |
# File 'lib/gamefic/engine/base.rb', line 22 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 |
#post_initialize ⇒ Object
14 15 16 |
# File 'lib/gamefic/engine/base.rb', line 14 def post_initialize # Override in subclasses end |
#receive ⇒ Object
59 60 61 62 63 |
# File 'lib/gamefic/engine/base.rb', line 59 def receive print @character.scene.prompt + ' ' input = STDIN.gets @character.queue.push input unless input.nil? end |
#run ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gamefic/engine/base.rb', line 29 def run connect @plot.introduce @character @user.update @character.state turn until @character.concluded? #print @user.flush end |
#turn ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gamefic/engine/base.rb', line 37 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 |