Class: Gamefic::Engine::Base

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

Overview

Basic functionality for running a single-player game from a console.

Direct Known Subclasses

Tty

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#plotGamefic::Plot (readonly)

Returns:



10
11
12
# File 'lib/gamefic/engine/base.rb', line 10

def plot
  @plot
end

#user_classObject



21
22
23
# File 'lib/gamefic/engine/base.rb', line 21

def user_class
  @user_class ||= Gamefic::User::Base
end

Instance Method Details

#connectObject



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_initializeObject



17
18
19
# File 'lib/gamefic/engine/base.rb', line 17

def post_initialize
  # Override in subclasses
end

#receiveObject



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

#runObject



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

#turnObject



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