Module: Gamefic::Scriptable::Scenes

Included in:
Gamefic::Scriptable
Defined in:
lib/gamefic/scriptable/scenes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_conclusionScene::Conclusion (readonly)

Returns:



12
13
14
# File 'lib/gamefic/scriptable/scenes.rb', line 12

def default_conclusion
  @default_conclusion
end

#default_sceneScene::Base (readonly)

Returns:



9
10
11
# File 'lib/gamefic/scriptable/scenes.rb', line 9

def default_scene
  @default_scene
end

Instance Method Details

#active_choice(name = nil, &block) ⇒ Class<Scene::ActiveChoice>

Create an active choice scene.

Parameters:

  • name (Symbol, nil) (defaults to: nil)

Returns:



126
127
128
# File 'lib/gamefic/scriptable/scenes.rb', line 126

def active_choice(name = nil, &block)
  self.block Class.new(Scene::ActiveChoice, &block), name
end

#block(scene, name = nil) ⇒ Object Also known as: scene



42
43
44
45
46
# File 'lib/gamefic/scriptable/scenes.rb', line 42

def block(scene, name = nil)
  named_scenes[name] = scene if name
  scene_classes.add scene
  scene
end

#conclusion(name = nil) {|, | ... } ⇒ Class<Scene::Conclusion>

Create a conclusion. The game (or the character’s participation in it) will end after this scene is complete.

Examples:

conclusion :ending do |actor|
  actor.tell 'GAME OVER'
end

Parameters:

  • name (Symbol, nil) (defaults to: nil)

Yield Parameters:

Returns:



159
160
161
162
163
# File 'lib/gamefic/scriptable/scenes.rb', line 159

def conclusion(name = nil, &block)
  self.block(Class.new(Scene::Conclusion) do
    on_start(&block)
  end, name)
end

#introduction {|, | ... } ⇒ void

This method returns an undefined value.

Add a block to be executed when a player is added to the game. Each Plot should only have one introduction.

Examples:

Welcome the player to the game

introduction do |actor|
  actor.tell "Welcome to the game!"
end

Yield Parameters:

Raises:

  • (ArgumentError)

    if an introduction already exists



68
69
70
# File 'lib/gamefic/scriptable/scenes.rb', line 68

def introduction(&start)
  introductions.push start
end

#introductionsArray<Proc>

Returns:



50
51
52
# File 'lib/gamefic/scriptable/scenes.rb', line 50

def introductions
  @introductions ||= []
end

#multiple_choice(name = nil, &block) ⇒ Class<Scene::MultipleChoice>

Create a multiple-choice scene. The user will be required to make a choice to continue. The scene will restart if the user input is not a valid choice.

Examples:

multiple_choice :go_somewhere, do
  on_start do |actor, props|
    props.options.push 'Go to work', 'Go to school'
  end

  on_finish do |actor, props|
    # Assuming the user selected the first choice:
    props.selection #=> 'Go to work'
    props.index     #=> 0
    props.number    #=> 1
  end
end

Parameters:

  • name (Symbol, nil) (defaults to: nil)

Returns:



93
94
95
# File 'lib/gamefic/scriptable/scenes.rb', line 93

def multiple_choice(name = nil, &block)
  self.block Class.new(Scene::MultipleChoice, &block), name
end

#named_scenesObject



26
27
28
# File 'lib/gamefic/scriptable/scenes.rb', line 26

def named_scenes
  @named_scenes ||= {}
end

#pause(name = nil) {|, | ... } ⇒ Class<Scene::Pause>

Create a pause. The block will be executed at the start of the scene and the player will be prompted to press enter to continue.

Parameters:

  • name (Symbol, nil) (defaults to: nil)

Yield Parameters:

Returns:



139
140
141
142
143
# File 'lib/gamefic/scriptable/scenes.rb', line 139

def pause(name = nil, &block)
  self.block(Class.new(Scene::Pause) do
    on_start(&block)
  end, name)
end

#scene_classesObject



30
31
32
# File 'lib/gamefic/scriptable/scenes.rb', line 30

def scene_classes
  @scene_classes ||= Set.new
end

#scene_classes_mapObject



34
35
36
# File 'lib/gamefic/scriptable/scenes.rb', line 34

def scene_classes_map
  scene_classes.each_with_object(named_scenes.clone) { |klass, hash| hash[klass] = klass }
end

#scenesObject



38
39
40
# File 'lib/gamefic/scriptable/scenes.rb', line 38

def scenes
  scene_classes_map.values.uniq
end

#select_default_conclusion(klass) ⇒ Object

Parameters:



21
22
23
24
# File 'lib/gamefic/scriptable/scenes.rb', line 21

def select_default_conclusion(klass)
  scene_classes.add klass
  @default_conclusion = klass
end

#select_default_scene(klass) ⇒ Object

Parameters:



15
16
17
18
# File 'lib/gamefic/scriptable/scenes.rb', line 15

def select_default_scene(klass)
  scene_classes.add klass
  @default_scene = klass
end

#yes_or_no(name = nil, &block) ⇒ Class<Scene::YesOrNo>

Create a yes-or-no scene. The user will be required to answer Yes or No to continue. The scene will restart if the user input is not a valid choice.

Examples:

yes_or_no :answer_scene do
  on_start do |actor, props|
    actor.tell 'Yes or no?'
  end

  on_finish do |actor, props|
    if props.yes?
      actor.tell 'You said yes.'
    else
      actor.tell 'You said no.'
    end
  end
end

Parameters:

  • name (Symbol, nil) (defaults to: nil)

Returns:



118
119
120
# File 'lib/gamefic/scriptable/scenes.rb', line 118

def yes_or_no(name = nil, &block)
  self.block Class.new(Scene::YesOrNo, &block), name
end