예제 #1
0
        public void LegalMoveLeftRight(int moveVal)
        {
            // Copy Active Piece And Simulate Move
            Tetrimino copy = GeneratePiece(_activePiece.GetBlockValue());

            _activePiece.MakeCopy(copy);
            copy.MoveLeftRight(moveVal);

            // If In Bounds, Perform Actual Move
            if (copy.IsInBounds(_tower))
            {
                _activePiece.MoveLeftRight(moveVal);
            }
        }
예제 #2
0
        public void TryRotate(Tetrimino piece, bool clockwise)
        {
            // Copy Active Piece And Simulate Rotation
            Tetrimino copy = GeneratePiece(piece.GetBlockValue());

            piece.MakeCopy(copy);
            copy.Rotate(clockwise);

            // If Everything Looks Good, Rotate Active Piece
            if (copy.IsInBounds(_tower))
            {
                piece.Rotate(clockwise);
            }
            // If It Doesn't, Try To Apply An Offset To The Rotation
            else
            {
                int rotationOffsetValue = -1;

                while (!copy.IsInBounds(_tower))
                {
                    rotationOffsetValue++;

                    switch (rotationOffsetValue)
                    {
                    case 0:
                        // 1 Space Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 1:
                        // 2 Spaces Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 2:
                        // 1 Space Right
                        copy.MoveLeftRight(3);
                        break;

                    case 3:
                        // 2 Spaces Right
                        copy.MoveLeftRight(1);
                        break;

                    case 4:
                        // 1 Space Down
                        copy.MoveLeftRight(-2);
                        copy.MoveUpDown(1);
                        break;

                    case 5:
                        // 2 Spaces Down
                        copy.MoveUpDown(1);
                        break;

                    default:
                        return;
                    }
                }

                // Rotate And Apply Offset
                piece.Rotate(clockwise);
                switch (rotationOffsetValue)
                {
                case 0:
                    piece.MoveLeftRight(-1);
                    break;

                case 1:
                    piece.MoveLeftRight(-2);
                    break;

                case 2:
                    piece.MoveLeftRight(1);
                    break;

                case 3:
                    piece.MoveLeftRight(2);
                    break;

                case 4:
                    piece.MoveUpDown(1);
                    break;

                case 5:
                    piece.MoveUpDown(2);
                    break;
                }
            }

            _rotateSound.Play();
        }