Sha256: 910ff8a029e9b66b81d5fd3eaf4b85323046aa95d10e06e5a129bf783d3300d8

Contents?: true

Size: 789 Bytes

Versions: 12

Compression:

Stored size: 789 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

12 entries across 12 versions & 6 rubygems

Version Path
eric-adhearsion-0.8.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
jicksta-adhearsion-0.7.999 app_generators/ahn/templates/components/simon_game/simon_game.rb
jicksta-adhearsion-0.8.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
jicksta-adhearsion-0.8.2 app_generators/ahn/templates/components/simon_game/simon_game.rb
jicksta-adhearsion-0.8.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
kenwiesner-adhearsioncw-0.8.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
mtrudel-adhearsion-0.8.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
sevenscale-adhearsion-0.8.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.3 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.0 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.2 app_generators/ahn/templates/components/simon_game/simon_game.rb
adhearsion-0.8.1 app_generators/ahn/templates/components/simon_game/simon_game.rb