Class: Gamefic::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/engine.rb

Direct Known Subclasses

Cgi::Engine, Tty::Engine

Instance Method Summary collapse

Constructor Details

#initialize(plot) ⇒ Engine

Returns a new instance of Engine.



4
5
6
7
# File 'lib/gamefic/engine.rb', line 4

def initialize(plot)
  @plot = plot
  post_initialize
end

Instance Method Details

#post_initializeObject



8
9
10
# File 'lib/gamefic/engine.rb', line 8

def post_initialize
  @user = User.new @plot
end

#runObject



11
12
13
14
15
16
17
18
# File 'lib/gamefic/engine.rb', line 11

def run
  @plot.introduce @user.character
  print @user.state.output
  while !@plot.concluded?(@user.character)
    turn
  end
  print @user.state.output
end

#turnObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gamefic/engine.rb', line 19

def turn
  @plot.ready
  print @user.state.output
  if !@user.character[:test_queue].nil? and @user.character[:test_queue].length > 0
    test_command = @user.character[:test_queue].shift
    @user.character.tell "[TESTING] #{@plot.scenes[@user.character.scene].prompt} #{test_command}"
    @user.character.queue.push test_command 
  else
    @user.stream.select @plot.scenes[@user.character.scene].prompt
    @user.state.input
  end
  @plot.update
  print @user.state.output
end