Class: SimonGame

Inherits:
Adhearsion::CallController show all
Defined in:
lib/adhearsion/generators/app/templates/simon_game.rb

Constant Summary

Constants included from Adhearsion::CallController::Record

Adhearsion::CallController::Record::RecordError

Constants included from Adhearsion::CallController::Output

Adhearsion::CallController::Output::NoDocError, Adhearsion::CallController::Output::PlaybackError

Instance Attribute Summary collapse

Attributes inherited from Adhearsion::CallController

#call, #metadata

Instance Method Summary collapse

Methods inherited from Adhearsion::CallController

#answer, #bg_exec, #eql?, #exec, exec, #exec_with_callback, #hangup, #hard_pass, #initialize, #invoke, #join, #logger, #method_missing, mixin, #mute, #pass, #redirect, #reject, #stop_all_components, #unmute

Methods included from Adhearsion::CallController::Record

#record

Methods included from Adhearsion::CallController::Output

#interruptible_play, #output_formatter, #play, #play!, #play_audio, #play_audio!, #play_document, #play_document!, #play_numeric, #play_numeric!, #play_time, #play_time!, #say, #say!, #say_characters, #say_characters!

Methods included from Adhearsion::CallController::Input

#ask, #menu

Methods included from Adhearsion::CallController::Dial

#dial, #dial_and_confirm

Constructor Details

This class inherits a constructor from Adhearsion::CallController

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Adhearsion::CallController

Instance Attribute Details

#attemptObject

Returns the value of attribute attempt.



5
6
7
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 5

def attempt
  @attempt
end

#numberObject

Returns the value of attribute number.



5
6
7
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 5

def number
  @number
end

Instance Method Details

#attempt_correct?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 39

def attempt_correct?
  @attempt == @number
end

#collect_attemptObject



25
26
27
28
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 25

def collect_attempt
  result = ask @number, :limit => @number.length
  @attempt = result.response
end

#random_numberObject



17
18
19
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 17

def random_number
  rand(10).to_s
end

#resetObject



43
44
45
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 43

def reset
  @attempt, @number = '', ''
end

#runObject



7
8
9
10
11
12
13
14
15
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 7

def run
  answer
  reset
  loop do
    update_number
    collect_attempt
    verify_attempt
  end
end

#update_numberObject



21
22
23
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 21

def update_number
  @number << random_number
end

#verify_attemptObject



30
31
32
33
34
35
36
37
# File 'lib/adhearsion/generators/app/templates/simon_game.rb', line 30

def verify_attempt
  if attempt_correct?
    speak 'good'
  else
    speak "#{@number.length - 1} times wrong, try again smarty"
    reset
  end
end