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
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.
12 13 14 15 |
# File 'lib/gamefic/engine/base.rb', line 12 def initialize(plot) @plot = plot post_initialize end |
Instance Attribute Details
#plot ⇒ Gamefic::Plot (readonly)
10 11 12 |
# File 'lib/gamefic/engine/base.rb', line 10 def plot @plot end |
Instance Method Details
#connect ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/gamefic/engine/base.rb', line 25 def connect raise 'Plot did not specify a player class' if @plot.player_class.nil? # @todo The plot itself can define name, etc. character = @plot.make @plot.player_class, name: 'yourself', synonyms: 'self myself you me', proper_named: true @user = user_class.new(self) @user.connect character character.connect @user end |
#post_initialize ⇒ Object
17 18 19 |
# File 'lib/gamefic/engine/base.rb', line 17 def post_initialize # Override in subclasses end |
#receive ⇒ Object
52 53 54 55 56 |
# File 'lib/gamefic/engine/base.rb', line 52 def receive print @user.character.scene.prompt + ' ' input = STDIN.gets @user.character.queue.push input unless input.nil? end |
#run ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/gamefic/engine/base.rb', line 34 def run connect @plot.introduce @user.character #@user.update @character.state turn until @user.character.concluded? @user.update #print @user.flush end |
#turn ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/gamefic/engine/base.rb', line 43 def turn @plot.ready @user.update if @user.character.queue.empty? receive end @plot.update end |