Beispiel #1
0
        private void OnButtonStateChanged(int button, bool down)
        {
            Log($"[Game.ButtonStateChanged] button: {button}, down: {down}");

            switch (CurrentState)
            {
            case State.PLAYER_INPUT:

                SetLed(button, down);

                // button up
                if (!down)
                {
                    var expectedButton = (int)Solution[CurrentPosition];

                    Log($"[Game.ButtonStateChanged] Button pressed -> player: {button}, expected: {expectedButton}");

                    // check if correct button pressed
                    if (expectedButton == button)
                    {
                        CurrentPosition++;

                        // player has pressed all buttons correctly
                        if (CurrentPosition >= Solution.Count)
                        {
                            Hardware.DisplayScore(Solution.Count);

                            CurrentPosition = 0;
                            CurrentState    = State.SHOW_NEXT_SOLUTION;
                        }
                    }
                    else
                    {
                        CurrentState = State.PLAYER_MISTAKE;
                    }
                }

                break;
            }
        }