Class: Gamefic::Scene::MultipleChoice
- Defined in:
- lib/gamefic/scene/multiple_choice.rb
Overview
Provide a list of options and process the selection in the scene’s finish block. After the scene is finished, the :active scene will be cued unless some other scene has already been prepared or cued.
The finish block’s input parameter receives a MultipleChoice::Input object instead of a String.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
- #invalid_message ⇒ Object
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#selection ⇒ Object
readonly
Returns the value of attribute selection.
Attributes inherited from Base
#actor, #input, #prompt, #type
Instance Method Summary collapse
- #finish ⇒ Object
- #options ⇒ Object
- #post_initialize ⇒ Object
-
#start ⇒ Object
def start actor data = start_data_for(actor) data.clear do_start_block actor, data tell_options end.
- #state ⇒ Object
Methods inherited from Base
#flush, #initialize, initialize_block, #on_finish, on_initialize, subclass, #update
Constructor Details
This class inherits a constructor from Gamefic::Scene::Base
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
11 12 13 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 11 def index @index end |
#invalid_message ⇒ Object
48 49 50 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 48 def ||= 'That is not a valid choice.' end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
12 13 14 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 12 def number @number end |
#selection ⇒ Object (readonly)
Returns the value of attribute selection.
13 14 15 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 13 def selection @selection end |
Instance Method Details
#finish ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 33 def finish #data = finish_data_for(actor, input) get_choice if selection.nil? actor.tell else super end end |
#options ⇒ Object
44 45 46 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 44 def ||= [] end |
#post_initialize ⇒ Object
16 17 18 19 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 16 def post_initialize self.type = 'MultipleChoice' self.prompt = 'Enter a choice:' end |
#start ⇒ Object
def start actor
data = start_data_for(actor)
data.clear
do_start_block actor, data
end
28 29 30 31 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 28 def start super raise "MultipleChoice scene has zero options" if .empty? end |
#state ⇒ Object
52 53 54 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 52 def state super.merge options: end |