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

#flush, #initialize, initialize_block, #on_finish, on_initialize, 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



48
49
50
# File 'lib/gamefic/scene/multiple_choice.rb', line 48

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



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 invalid_message
    tell_options
  else
    super
  end
end

#optionsObject



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

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

#startObject

def start actor

data = start_data_for(actor)
data.clear
do_start_block actor, data
tell_options

end



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

def start
  super
  raise "MultipleChoice scene has zero options" if options.empty?
end

#stateObject



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

def state
  super.merge options: options
end