Class: Gamefic::Scene::MultipleChoice

Inherits:
Custom
  • Object
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, #input, #prompt, #type

Instance Method Summary collapse

Methods inherited from Base

#finished?, #flush, #initialize, #on_finish, on_start, #start, start_block, subclass, #update

Constructor Details

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/gamefic/scene/multiple_choice.rb', line 11

def index
  @index
end

#invalid_messageObject



35
36
37
# File 'lib/gamefic/scene/multiple_choice.rb', line 35

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

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

#selectionObject (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

#finishObject



21
22
23
24
25
26
27
28
29
# File 'lib/gamefic/scene/multiple_choice.rb', line 21

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

#optionsObject



31
32
33
# File 'lib/gamefic/scene/multiple_choice.rb', line 31

def options
  @options ||= []
end

#post_initializeObject



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

#stateObject



39
40
41
# File 'lib/gamefic/scene/multiple_choice.rb', line 39

def state
  super.merge options: options
end