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

Attributes inherited from Base

#actor, #input, #type

Instance Method Summary collapse

Methods inherited from Base

#flush, #initialize, initialize_block, #on_finish, on_initialize, #start, #state, subclass, #update

Constructor Details

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

Instance Method Details

#finishObject



30
31
32
33
34
35
36
# File 'lib/gamefic/scene/yes_or_no.rb', line 30

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

#invalid_messageObject



22
23
24
# File 'lib/gamefic/scene/yes_or_no.rb', line 22

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

#no?Boolean

Returns:

  • (Boolean)


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

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

#post_initializeObject



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

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

#promptObject



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

def prompt
  @prompt ||= 'Yes or No?'
end

#yes?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/gamefic/scene/yes_or_no.rb', line 14

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