Class: SimonGame

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

Constant Summary

Constant Summary

Constants included from Adhearsion::CallController::Record

Adhearsion::CallController::Record::RecordError

Constants included from Adhearsion::CallController::Output

Adhearsion::CallController::Output::PlaybackError

Instance Attribute Summary

Attributes inherited from Adhearsion::CallController

#call, #metadata

Instance Method Summary (collapse)

Methods inherited from Adhearsion::CallController

#answer, exec, #hangup, #initialize, #invoke, #join, mixin, #mute, #pass, #reject, #unmute

Methods included from Adhearsion::CallController::Record

#record

Methods included from Adhearsion::CallController::Output

#interruptible_play, #play, #play_audio, #play_numeric, #play_time, #say, #stream_file

Methods included from Adhearsion::CallController::Input

#ask, #menu

Methods included from Adhearsion::CallController::Dial

#dial

Constructor Details

This class inherits a constructor from Adhearsion::CallController

Instance Method Details

- (Boolean) attempt_correct?

Returns:

  • (Boolean)


36
37
38
# File 'lib/adhearsion/generators/app/templates/lib/simon_game.rb', line 36

def attempt_correct?
  @attempt == @number
end

- (Object) collect_attempt



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

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

- (Object) random_number



14
15
16
# File 'lib/adhearsion/generators/app/templates/lib/simon_game.rb', line 14

def random_number
  rand(10).to_s
end

- (Object) reset



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

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

- (Object) run



4
5
6
7
8
9
10
11
12
# File 'lib/adhearsion/generators/app/templates/lib/simon_game.rb', line 4

def run
  answer
  reset
  loop do
    update_number
    collect_attempt
    verify_attempt
  end
end

- (Object) update_number



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

def update_number
  @number << random_number
end

- (Object) verify_attempt



27
28
29
30
31
32
33
34
# File 'lib/adhearsion/generators/app/templates/lib/simon_game.rb', line 27

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