Sha256: 4856c447882cefbb2ed963f33fabe62ce008e74b9cb130ac5c10328db61c9d7a

Contents?: true

Size: 706 Bytes

Versions: 22

Compression:

Stored size: 706 Bytes

Contents

# encoding: utf-8

class SimonGame < Adhearsion::CallController

  attr_accessor :number, :attempt

  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

22 entries across 22 versions & 2 rubygems

Version Path
adhearsion-2.6.4 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.6.3 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.6.2 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.6.1 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.6.0 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.5.4 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.5.3 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.5.2 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.5.0 lib/adhearsion/generators/app/templates/simon_game.rb
adhearsion-2.4.0 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.4.0.beta3 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.4.0.beta2 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.4.0.beta1 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion_sinatra-0.0.1 lib/simon_game.rb
adhearsion-2.3.5 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.3.4 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.3.3 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.3.2 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.3.1 lib/adhearsion/generators/app/templates/lib/simon_game.rb
adhearsion-2.3.0 lib/adhearsion/generators/app/templates/lib/simon_game.rb