Class: Gamefic::Scene::YesOrNo

Inherits:
Custom show all
Defined in:
lib/gamefic/scene/yes_or_no.rb

Overview

Prompt the user to answer “yes” or “no”. The scene will accept variations like “YES” or “n” and normalize the answer to “yes” or “no” in the finish block. After the scene is finished, the :active scene will be cued if no other scene has been prepared or cued.

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

Constructor Details

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

Instance Attribute Details

#invalid_messageString

The message sent to the user for an invalid answer, i.e., the input could not be resolved to either Yes or No.

Returns:



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

def invalid_message
  @invalid_message ||= 'Please enter Yes or No.'
end

Instance Method Details

#finishObject



39
40
41
42
43
44
45
# File 'lib/gamefic/scene/yes_or_no.rb', line 39

def finish
  if yes? or no?
    super
  else
    actor.tell invalid_message
  end
end

#no?Boolean

True if the actor’s answer is No. Any answer beginning with letter N is considered No.

Returns:

  • (Boolean)


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

def no?
  input.to_s[0,1].downcase == 'n' or input.to_i == 2
end

#post_initializeObject



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

def post_initialize
  self.type = 'YesOrNo'
  self.prompt = 'Yes or No:'
end

#stateObject



47
48
49
# File 'lib/gamefic/scene/yes_or_no.rb', line 47

def state
  super.merge options: ['Yes', 'No']
end

#yes?Boolean

True if the actor’s answer is Yes. Any answer beginning with letter Y is considered Yes.

Returns:

  • (Boolean)


19
20
21
# File 'lib/gamefic/scene/yes_or_no.rb', line 19

def yes?
  input.to_s[0,1].downcase == 'y' or input.to_i == 1
end