Example #1
0
        public void SimulationInput(TetrisInput tetrisInput)
        {
            switch (tetrisInput)
            {
            case TetrisInput.Up:
                Rotate();
                HasStateChangedSinceRender = true;
                break;

            case TetrisInput.Left:
                Left();
                break;

            case TetrisInput.Right:
                Right();
                break;

            case TetrisInput.Down:
                DownPressed();
                break;

            case TetrisInput.Space:
                Space();
                break;

            case TetrisInput.Enter:
                Enter();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tetrisInput), tetrisInput, null);
            }
        }
Example #2
0
        /*
         *      This method can be thought of as a game controller port.
         *      Pass an action as a TetrisInput enumeration to give player input to the game.
         *      This method causes observers to be notified of game board changes, for instance.
         *      Nothing happens if the current game is over. Call Restart to restart the game.
         */
        public void GiveInput(TetrisInput input)
        {
            if (_stateLogic.GameState == GameState.Over)
            {
                return;
            }

            switch (input)
            {
            case TetrisInput.Left:
                _boardLogic.MoveLeft();
                break;

            case TetrisInput.Right:
                _boardLogic.MoveRight();
                break;

            case TetrisInput.RotateLeft:
                _boardLogic.RotateLeft();
                break;

            case TetrisInput.RotateRight:
                _boardLogic.RotateRight();
                break;

            case TetrisInput.Drop:
                _boardLogic.Drop();
                break;

            case TetrisInput.HoldTetromino:
                _boardLogic.HoldTetromino();
                break;
            }
        }