Sha256: 75ff3ccab7ed26cec539ab30510f6b7743bd3bb19353e1df4b4841f6c3094153

Contents?: true

Size: 782 Bytes

Versions: 19

Compression:

Stored size: 782 Bytes

Contents

methods_for :dialplan do
  def simon_game
    SimonGame.new(self).start
  end
end

class SimonGame

  def initialize(call)
    @call = call
    reset
  end

  def start
    loop do
      say_number
      collect_attempt
      verify_attempt
    end
  end

  def random_number
    rand(10).to_s
  end

  def update_number
    @number << random_number
  end

  def say_number
    update_number
    @call.say_digits @number
  end

  def collect_attempt
    @attempt = @call.input @number.length
  end

  def verify_attempt
    if attempt_correct?
      @call.play 'good'
    else
      @call.play %W[#{@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

19 entries across 19 versions & 3 rubygems

Version Path
adhearsion-1.2.6 lib/adhearsion/generators/app/templates/components/simon_game/simon_game.rb
adhearsion-1.2.5 lib/adhearsion/generators/app/templates/components/simon_game/simon_game.rb
adhearsion-1.2.4 lib/adhearsion/generators/app/templates/components/simon_game/simon_game.rb
adhearsion-1.2.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.2.1 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.2.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.1.1 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.1.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.0.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.0.2 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-cw-1.0.2.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-cw-1.0.2.2 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-cw-1.0.2.1 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.0.1 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-1.0.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
rene-adhearsion-0.8.6 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.6 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.5 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.4 app_generators/ahn/templates/components/simon_game/simon_game.rb