Sha256: 2a812464b65800e8a8d969d29407c89f10eee47d23cf394364f458827165c939

Contents?: true

Size: 670 Bytes

Versions: 10

Compression:

Stored size: 670 Bytes

Contents

# encoding: utf-8

class SimonGame < Adhearsion::CallController
  def run
    answer
    reset
    loop do
      update_number
      collect_attempt
      verify_attempt
    end
  end

  def random_number
    rand(10).to_s
  end

  def update_number
    @number << random_number
  end

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

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

  def attempt_correct?
    @attempt == @number
  end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
adhearsion-2.1.3 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.1.2 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.1.1 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.1.0 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.1 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.0 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.0.rc5 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.0.rc4 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.0.rc3 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.0.0.rc2 lib/adhearsion/generators/app/templates/lib/simon_game.rb