Example #1
0
        public void Register(PianoButton pb)
        {
            // Ignore if we're not playing
            if (!SongPlayer.IsRunning)
            {
                return;
            }

            List <Note> notes = SongPlayer.currentNotes;

            // Iterate over all current notes to see if the pressed button
            // should've been pressed at all.
            foreach (Note n in notes)
            {
                // A PianoButton equals a Note when it's the same octave, letter and key color.
                if (pb.Equals(n))
                {
                    // We know the user pressed a button he should have; but now we need to check
                    // if he has already hit the button before.

                    // If it was already hit, decrease score, otherwise increase it.
                    if (Hits.ContainsKey(n))
                    {
                        HitCount--;
                    }
                    else
                    {
                        HitCount++;
                        Hits[n] = true;
                    }
                    return;
                }
            }
            HitCount--;
        }
Example #2
0
 public override bool Equals(object obj)
 {
     if (obj is PianoButton)
     {
         PianoButton pb = (PianoButton)obj;
         return(pb.octave == this.octave &&
                pb.letter == this.letter &&
                pb.black == this.black);
     }
     else if (obj is Note)
     {
         Note note = (Note)obj;
         return(note.Octave == this.octave &&
                note.Letter.ToString() == this.letter &&
                note.Black == this.black);
     }
     return(base.Equals(obj));
 }