Module: Gamefic::World::Scenes
- Included in:
- Gamefic::World
- Defined in:
- lib/gamefic/world/scenes.rb
Instance Method Summary collapse
-
#conclusion {|| ... } ⇒ Class<Gamefic::Scene::Conclusion>
Create a conclusion.
-
#custom(cls = Scene::Custom) {|| ... } ⇒ Class<Gamefic::Scene::Custom>
Create a custom scene.
- #default_conclusion ⇒ Class<Gamefic::Scene::Conclusion>
- #default_scene ⇒ Class<Gamefic::Scene::Activity>
-
#introduce(player) ⇒ Object
Introduce a player to the game.
-
#introduction {|| ... } ⇒ Object
Add a block to be executed when a player is added to the game.
-
#multiple_choice(*choices) {|, | ... } ⇒ Class<Gamefic::Scene::MultipleChoice>
Create a multiple-choice scene.
-
#multiple_scene(map = {}) {|, | ... } ⇒ Class<Gamefic::Scene::MultipleScene>
Choose a new scene based on a list of options.
-
#pause(prompt = nil) {|| ... } ⇒ Class<Gamefic::Scene::Pause>
Create a scene that pauses the game.
-
#question(prompt = 'What is your answer?') {|, | ... } ⇒ Class<Gamefic::Scene::Custom>
Create a scene with custom processing on user input.
- #scene_classes ⇒ Array<Class<Gamefic::Scene::Base>>
-
#yes_or_no(prompt = nil) {|, | ... } ⇒ Class<Gamefic::Scene::YesOrNo>
Create a yes-or-no scene.
Instance Method Details
#conclusion {|| ... } ⇒ Class<Gamefic::Scene::Conclusion>
Create a conclusion. The game (or the character’s participation in it) will end after this scene is complete.
142 143 144 145 146 |
# File 'lib/gamefic/world/scenes.rb', line 142 def conclusion &block s = Scene::Conclusion.subclass &block scene_classes.push s s end |
#custom(cls = Scene::Custom) {|| ... } ⇒ Class<Gamefic::Scene::Custom>
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.
169 170 171 172 173 |
# File 'lib/gamefic/world/scenes.rb', line 169 def custom cls = Scene::Custom, &block s = cls.subclass &block scene_classes.push s s end |
#default_conclusion ⇒ Class<Gamefic::Scene::Conclusion>
10 11 12 |
# File 'lib/gamefic/world/scenes.rb', line 10 def default_conclusion @default_conclusion ||= Scene::Conclusion end |
#default_scene ⇒ Class<Gamefic::Scene::Activity>
5 6 7 |
# File 'lib/gamefic/world/scenes.rb', line 5 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.
32 33 34 35 36 37 38 39 |
# File 'lib/gamefic/world/scenes.rb', line 32 def introduce(player) player.playbooks.push playbook unless player.playbooks.include?(playbook) player.cue default_scene players.push player @introduction.call(player) unless @introduction.nil? # @todo Find a better way to persist player characters # Gamefic::Index.stick 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.
24 25 26 |
# File 'lib/gamefic/world/scenes.rb', line 24 def introduction(&proc) @introduction = proc end |
#multiple_choice(*choices) {|, | ... } ⇒ Class<Gamefic::Scene::MultipleChoice>
Create a multiple-choice scene. The user will be required to make a valid choice to continue.
55 56 57 58 59 60 61 62 |
# File 'lib/gamefic/world/scenes.rb', line 55 def multiple_choice *choices, &block s = Scene::MultipleChoice.subclass do |actor, scene| scene..concat choices scene.on_finish &block end scene_classes.push s s end |
#multiple_scene(map = {}) {|, | ... } ⇒ Class<Gamefic::Scene::MultipleScene>
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.
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/gamefic/world/scenes.rb', line 209 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) {|| ... } ⇒ Class<Gamefic::Scene::Pause>
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.
122 123 124 125 126 127 128 129 |
# File 'lib/gamefic/world/scenes.rb', line 122 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?') {|, | ... } ⇒ Class<Gamefic::Scene::Custom>
Create a scene with custom processing on user input.
100 101 102 103 104 105 106 107 |
# File 'lib/gamefic/world/scenes.rb', line 100 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_classes ⇒ Array<Class<Gamefic::Scene::Base>>
221 222 223 |
# File 'lib/gamefic/world/scenes.rb', line 221 def scene_classes @scene_classes ||= [] end |
#yes_or_no(prompt = nil) {|, | ... } ⇒ Class<Gamefic::Scene::YesOrNo>
Create a yes-or-no scene. The user will be required to answer Yes or No to continue.
80 81 82 83 84 85 86 87 |
# File 'lib/gamefic/world/scenes.rb', line 80 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 |