Class: Gamefic::Scene::MultipleChoice

Inherits:
Base show all
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

MultipleScene

Instance Attribute Summary collapse

Attributes inherited from Base

#actor, #data, #input, #prompt, #type

Instance Method Summary collapse

Methods inherited from Base

#[], #finished?, #initialize, #on_finish, on_start, #start, start_block, subclass, #tracked=, #tracked?, tracked?, #update

Methods included from Gamefic::Serialize

#serialized_class, string_to_constant, #to_serial

Constructor Details

This class inherits a constructor from Gamefic::Scene::Base

Instance Attribute Details

#indexInteger (readonly)

The zero-based index of the selected option.

Returns:

  • (Integer)


13
14
15
# File 'lib/gamefic/scene/multiple_choice.rb', line 13

def index
  @index
end

#invalid_messageString

The text to display when an invalid selection is received.

Returns:



51
52
53
# File 'lib/gamefic/scene/multiple_choice.rb', line 51

def invalid_message
  @invalid_message ||= 'That is not a valid choice.'
end

#numberInteger (readonly)

The one-based index of the selected option.

Returns:

  • (Integer)


18
19
20
# File 'lib/gamefic/scene/multiple_choice.rb', line 18

def number
  @number
end

#selectionString (readonly)

The full text of the selected option.

Returns:



23
24
25
# File 'lib/gamefic/scene/multiple_choice.rb', line 23

def selection
  @selection
end

Instance Method Details

#finishObject



32
33
34
35
36
37
38
39
# File 'lib/gamefic/scene/multiple_choice.rb', line 32

def finish
  get_choice
  if selection.nil?
    actor.tell invalid_message
  else
    super
  end
end

#optionsArray<String>

The array of available options.

Returns:



44
45
46
# File 'lib/gamefic/scene/multiple_choice.rb', line 44

def options
  @options ||= []
end

#post_initializeObject



27
28
29
30
# File 'lib/gamefic/scene/multiple_choice.rb', line 27

def post_initialize
  self.type = 'MultipleChoice'
  self.prompt = 'Enter a choice:'
end

#stateObject



55
56
57
# File 'lib/gamefic/scene/multiple_choice.rb', line 55

def state
  super.merge options: options
end