Module: Gamefic::Plot::SceneMount

Defined in:
lib/gamefic/plot/scene_mount.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.

Parameters:

  • key (Symbol)

    A unique name for the scene.

Yield Parameters:



106
107
108
109
110
# File 'lib/gamefic/plot/scene_mount.rb', line 106

def conclusion &block
  s = Scene::Conclusion.new
  s.on_start &block
  s
end

#default_conclusionObject



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

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

#default_sceneObject



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

def default_scene
  @default_scene ||= Scene::Active.new(self)
end

#introduce(player) ⇒ Object

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



28
29
30
31
32
33
# File 'lib/gamefic/plot/scene_mount.rb', line 28

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/scene_mount.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:



40
41
42
43
44
45
46
47
48
# File 'lib/gamefic/plot/scene_mount.rb', line 40

def multiple_choice *choices, &block
  s = Scene::MultipleChoice.new
  s.on_start do |actor, data|
    data.options.clear
    data.options.push *choices
  end
  s.on_finish &block
  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

multiple_scene :select_one_or_two, { "one" => :scene_one, "two" => :scene_two }
scene :scene_one do |actor|
  actor.tell "You went to scene one"
end
scene :scene_two do |actor|
  actor.tell "You went to scene two"
end
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:

  • key (Symbol)

    A unique name for the scene.

  • map (Hash)

    A Hash of options and associated scene keys.



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

def multiple_scene map
  s = Scene::MultipleScene.new
  s.on_start do |actor, data|
    map.each { |k, v|
      data.map k, v
    }
  end
  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:

  • key (Symbol)

    A unique name for the scene.

  • prompt (String) (defaults to: nil)

    The text to display when prompting the user to continue.

Yield Parameters:



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gamefic/plot/scene_mount.rb', line 86

def pause prompt = nil, &block
  s = Scene::Pause.new
  s.on_start do |actor, data|
    data.prompt = prompt unless prompt.nil?
    block.call actor, data unless block.nil?
  end
  s.on_finish do |actor, data|
    #actor.cue :active if actor.scene == key and actor.next_scene.nil?

    actor.cue default_scene if actor.scene == s and actor.next_scene.nil?
  end
  s
end

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



69
70
71
72
73
74
75
76
# File 'lib/gamefic/plot/scene_mount.rb', line 69

def question prompt = 'What is your answer?', &block
  s = Scene::Custom.new
  s.on_start do |actor, data|
    data.prompt = prompt
  end
  s.on_finish &block
  s
end

#scene(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 :ask_for_name do |scene|
  scene.on_start do |actor, data|
    data.prompt = "What's your name?"
  end
  scene.on_finish do |actor, data|
    actor.name = data.input
    actor.tell "Hello, #{actor.name}!"
    actor.cue :active
  end
end

Customize the prompt for a MultipleChoice scene

scene :ask_for_choice, Scene::MultipleChoice do |scene|
  scene.on_start do |actor, data|
    data.options.push 'red', 'green', 'blue'
    data.prompt = "Which color?"
  end
  scene.on_finish do |actor, data|
    actor.tell "You chose #{data.selection}"
    actor.cue :active
  end
end

Parameters:

  • key (Symbol)

    A unique name for the scene.

  • key (cls)

    The class of scene to be instantiated.

Yield Parameters:



147
148
149
150
151
# File 'lib/gamefic/plot/scene_mount.rb', line 147

def scene cls = Scene::Custom, &block
  s = cls.new
  yield s if block_given?
  s
end

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

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

Yield Parameters:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gamefic/plot/scene_mount.rb', line 55

def yes_or_no prompt = nil, &block
  s = Scene::YesOrNo.new
  unless prompt.nil?
    s.on_start do |actor, data|
      data.prompt = prompt
    end
  end
  s.on_finish do |actor, data|
    block.call actor, data unless block.nil?
    actor.cue default_scene if actor.scene == s and actor.next_scene.nil?
  end
  s
end