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
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 |
#user_class ⇒ Object
18 19 20 |
# File 'lib/gamefic/engine/base.rb', line 18 def user_class @user_class ||= Gamefic::User::Base 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
46 47 48 49 50 |
# File 'lib/gamefic/engine/base.rb', line 46 def receive print @character.scene.prompt_for(@character) + ' ' input = STDIN.gets @character.queue.push input unless input.nil? end |
#run ⇒ Object
29 30 31 32 33 34 |
# File 'lib/gamefic/engine/base.rb', line 29 def run connect @plot.introduce @character turn until @character.concluded? print @user.flush end |
#turn ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/gamefic/engine/base.rb', line 36 def turn @plot.ready print @user.flush if @character.queue.empty? receive end @plot.update print @user.flush end |