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.



88
89
90
# File 'lib/gamefic/plot/scenes.rb', line 88

def conclusion &block
  Scene::Conclusion.subclass &block
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:



113
114
115
# File 'lib/gamefic/plot/scenes.rb', line 113

def custom cls = Scene::Custom, &block
  cls.subclass &block
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::Active
end

#introduce(player) ⇒ Object

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

Parameters:



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

def introduce(player)
  player.playbook = 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:



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:



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

def multiple_choice *choices, &block
  Scene::MultipleChoice.subclass do |actor, scene|
    scene.options.concat choices
    scene.on_finish &block
  end
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

Parameters:

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

    A Hash of options and associated scene keys.

Yield Parameters:



139
140
141
142
143
144
145
146
# File 'lib/gamefic/plot/scenes.rb', line 139

def multiple_scene map = {}, &block
  Scene::MultipleScene.subclass do |actor, scene|
    map.each_pair { |k, v|
      scene.map k, v
    }
    block.call actor, scene unless block.nil?
  end
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:



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

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

#question(prompt = 'What is your answer?', &block) ⇒ Object



61
62
63
64
65
66
# File 'lib/gamefic/plot/scenes.rb', line 61

def question prompt = 'What is your answer?', &block
  Scene::Custom.subclass do |actor, scene|
    scene.prompt = prompt
    scene.on_finish &block
  end
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.



54
55
56
57
58
59
# File 'lib/gamefic/plot/scenes.rb', line 54

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