Module: Gamefic::Plot::Scenes

Included in:
Gamefic::Plot, Subplot
Defined in:
lib/gamefic/plot/scenes.rb

Instance Method Summary collapse

Instance Method Details

#conclusion {|, | ... } ⇒ Object

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

Yield Parameters:



105
106
107
108
109
# File 'lib/gamefic/plot/scenes.rb', line 105

def conclusion &block
  s = Scene::Conclusion.subclass &block
  scene_classes.push s
  s
end

#custom(cls = Scene::Custom) {|, The| ... } ⇒ Object

Create a custom scene.

Custom scenes should always specify the next scene to be cued or prepared. If not, the scene will get repeated on the next turn.

This method creates a Scene::Custom by default. You can customize other scene types by specifying the class to create.

Examples:

Ask the user for a name

@scene = custom do |scene|
  data.prompt = "What's your name?"
  scene.on_finish do |actor, data|
    actor.name = data.input
    actor.tell "Hello, #{actor.name}!"
    actor.cue :active
  end
end

Parameters:

  • cls (Class) (defaults to: Scene::Custom)

    The class of scene to be instantiated.

Yield Parameters:

  • (Gamefic::Character)
  • The (Scene::Custom)

    instantiated scene.



132
133
134
135
136
# File 'lib/gamefic/plot/scenes.rb', line 132

def custom cls = Scene::Custom, &block
  s = cls.subclass &block
  scene_classes.push s
  s
end

#default_conclusionObject



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

def default_conclusion
  @default_conclusion ||= Scene::Conclusion
end

#default_sceneObject



4
5
6
# File 'lib/gamefic/plot/scenes.rb', line 4

def default_scene
  @default_scene ||= Scene::Activity
end

#introduce(player) ⇒ Object

Introduce a player to the game. This method is typically called by the Engine that manages game execution.

Parameters:

  • (Gamefic::Character)


30
31
32
33
34
35
# File 'lib/gamefic/plot/scenes.rb', line 30

def introduce(player)
  player.playbooks.push playbook unless player.playbooks.include?(playbook)
  player.cue default_scene
  p_players.push player
  @introduction.call(player) unless @introduction.nil?
end

#introduction {|| ... } ⇒ Object

Add a block to be executed when a player is added to the game. Each Plot can only have one introduction. Subsequent calls will overwrite the existing one.

Examples:

Welcome the player to the game

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

Yield Parameters:

  • (Gamefic::Character)


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

def introduction(&proc)
  @introduction = proc
end

#multiple_choice(*choices) {|, | ... } ⇒ Object

Create a multiple-choice scene. The user will be required to make a valid choice to continue.

Yield Parameters:

  • (Gamefic::Character)
  • (Gamefic::Scene::Data::MultipleChoice)


42
43
44
45
46
47
48
49
# File 'lib/gamefic/plot/scenes.rb', line 42

def multiple_choice *choices, &block
  s = Scene::MultipleChoice.subclass do |actor, scene|
    scene.options.concat choices
    scene.on_finish &block
  end
  scene_classes.push s
  s
end

#multiple_scene(map = {}) {|, | ... } ⇒ Object

Choose a new scene based on a list of options. This is a specialized type of multiple-choice scene that determines which scene to cue based on a Hash of choices and scene keys.

Examples:

Select a scene

scene_one = pause do |actor|
  actor.tell "You went to scene one"
end

scene_two = pause do |actor|
  actor.tell "You went to scene two"
end

select_one_or_two = multiple_scene "One" => scene_one, "Two" => scene_two

introduction do |actor|
  actor.cue select_one_or_two # The actor will be prompted to select "one" or "two" and get sent to the corresponding scene
end

Customize options

scene_one = pause # do...
scene_two = pause # do...

# Some event in the game sets actor[:can_go_to_scene_two] to true

select_one_or_two = multiple_scene do |actor, scene|
  scene.map "Go to scene one", scene_one
  scene.map "Go to scene two", scene_two if actor[:can_go_to_scene_two]
end

Parameters:

  • map (Hash) (defaults to: {})

    A Hash of options and associated scenes.

Yield Parameters:



171
172
173
174
175
176
177
178
179
180
# File 'lib/gamefic/plot/scenes.rb', line 171

def multiple_scene map = {}, &block
  s = Scene::MultipleScene.subclass do |actor, scene|
    map.each_pair { |k, v|
      scene.map k, v
    }
    block.call actor, scene unless block.nil?
  end
  scene_classes.push s
  s
end

#pause(prompt = nil) {|, | ... } ⇒ Object

Create a scene that pauses the game. This scene will execute the specified block and wait for input from the the user (e.g., pressing Enter) to continue.

Parameters:

  • prompt (String) (defaults to: nil)

    The text to display when prompting the user to continue.

Yield Parameters:



90
91
92
93
94
95
96
97
# File 'lib/gamefic/plot/scenes.rb', line 90

def pause prompt = nil, &block
  s = Scene::Pause.subclass do |actor, scene|
    scene.prompt = prompt unless prompt.nil?
    block.call(actor, scene) unless block.nil?
  end
  scene_classes.push s
  s
end

#question(prompt = 'What is your answer?') {|, | ... } ⇒ Object

Create a scene with custom processing on user input.

Examples:

Echo the user’s response

@scene = question 'What do you say?' do |actor, scene|
  actor.tell "You said #{scene.input}"
end

Yield Parameters:



74
75
76
77
78
79
80
81
# File 'lib/gamefic/plot/scenes.rb', line 74

def question prompt = 'What is your answer?', &block
  s = Scene::Custom.subclass do |actor, scene|
    scene.prompt = prompt
    scene.on_finish &block
  end
  scene_classes.push s
  s
end

#scene_classesObject



182
183
184
# File 'lib/gamefic/plot/scenes.rb', line 182

def scene_classes
  @scene_classes ||= []
end

#yes_or_no(prompt = nil) {|, | ... } ⇒ Object

Create a yes-or-no scene. The user will be required to answer Yes or No to continue.

Yield Parameters:



56
57
58
59
60
61
62
63
# File 'lib/gamefic/plot/scenes.rb', line 56

def yes_or_no prompt = nil, &block
  s = Scene::YesOrNo.subclass do |actor, scene|
    scene.prompt = prompt
    scene.on_finish &block
  end
  scene_classes.push s
  s
end