Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 40 lines (33 sloc) 0.794 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
class Game
  attr_reader :chord, :played_notes, :results

  def initialize
    @played_notes = []
    @results = []
    new_chord
  end

  def new_chord
    @chord = Chord.new(Note.random, 4, 7)
  end

  def key_down(key)
    @played_notes << Note.new(key)
    if done?
      if @played_notes.all? { |note| note.equal_tone? Note.new("D") }
        @results = []
      end
    else
      if @played_notes.size >= 3
        @results << correct?
        new_chord unless done?
      end
    end
  end

  def key_up(key)
    @played_notes.delete_if { |n| n.equal_tone?(key) }
  end

  def correct?
    @chord.notes.all? { |n| @played_notes.any? { |o| o.equal_tone?(n) } } && @played_notes.all? { |n| @chord.notes.any? { |o| o.equal_tone?(n) } }
  end

  def done?
    @results.size >= 10
  end
end
Something went wrong with that request. Please try again.