예제 #1
0
        private void PickNextNote()
        {
            base.Stop();

            chosenPitch = (new Random().Next(maximumPitch - minimumPitch)) + minimumPitch;

            // If flats and sharps are disabled, and the chosen pitch is either, drop it by 1 to the nearest natural
            if (!GameConfiguration.Sharps && !GameConfiguration.Flats)
            {
                var position = chosenPitch.PositionInOctave();
                if (SharpOctavePositions.Contains(position))
                {
                    chosenPitch--;
                }
            }

            var viewModel = new NoteTrainerViewModel();

            viewModel.DisplayNotes.Add(new DisplayNote {
                MidiPitch = chosenPitch, State = DisplayNoteState.Neutral
            });
            ViewModelChangedEvent?.Invoke(this, viewModel);

            gameState = GameState.WaitingForInput;

            base.Resume();
        }
예제 #2
0
        private void CheckPressedKeys()
        {
            bool correctKeyPressed = false;
            int  incorrectKeys     = 0;
            var  viewModel         = new NoteTrainerViewModel();

            foreach (KeyboardKey key in keyboardState.DepressedKeys)
            {
                if (key.MidiPitch.Equals(chosenPitch))
                {
                    viewModel.DisplayNotes.Add(new DisplayNote {
                        MidiPitch = key.MidiPitch, State = DisplayNoteState.Correct
                    });
                    correctKeyPressed = true;
                }
                else
                {
                    viewModel.DisplayNotes.Add(new DisplayNote {
                        MidiPitch = key.MidiPitch, State = DisplayNoteState.Incorrect
                    });
                    incorrectKeys++;
                }
            }

            if (!correctKeyPressed)
            {
                viewModel.DisplayNotes.Insert(0, new DisplayNote {
                    MidiPitch = chosenPitch, State = DisplayNoteState.Neutral
                });
            }

            ViewModelChangedEvent?.Invoke(this, viewModel);

            if (correctKeyPressed && incorrectKeys == 0)
            {
                gameState = GameState.ProceedToNext;
                ResetTimer();
            }
        }