Class: SimonGame
- Inherits:
-
Adhearsion::CallController
show all
- Defined in:
- lib/adhearsion/generators/app/templates/lib/simon_game.rb
Constant Summary
Constant Summary
Adhearsion::CallController::Record::RecordError
Adhearsion::CallController::Output::PlaybackError
Instance Attribute Summary
#call, #metadata
Instance Method Summary
(collapse)
#answer, exec, #hangup, #initialize, #invoke, #join, mixin, #mute, #pass, #reject, #unmute
#record
#interruptible_play, #play, #play_audio, #play_numeric, #play_time, #say, #stream_file
#ask, #menu
#dial
Instance Method Details
- (Boolean) attempt_correct?
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
|
40
41
42
|
# File 'lib/adhearsion/generators/app/templates/lib/simon_game.rb', line 40
def reset
@attempt, @number = '', ''
end
|
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
|