Exemplo n.º 1
0
        public void Rotate()
        {
            // only rotate if currently valid
            if (false == this.IsValid())
            {
                return;
            }

            // First, retrieve maximum non-redundant orientation values
            int totalOrientations = 0;

            totalOrientations = STPiece.GetMaximumOrientationsOfShape(this.mShape);
            if (0 == totalOrientations)
            {
                return;
            }

            // Add one to current orientation value
            int newOrientation = (this.mOrientation + 1);

            // Force newOrientation to range 1..totalOrientations
            newOrientation =
                1 + ((((newOrientation - 1) % totalOrientations)
                      + totalOrientations) % totalOrientations);

            this.mOrientation = newOrientation;
        }
Exemplo n.º 2
0
        public static bool GetCellOffsetXYOccupiedForShape
        (
            STPieceShape shape, // O,I,S,Z,L,J,T; None
            int orientation,    // 1,2,3,4; 0 == none
            int x,
            int y
        )
        {
            if (STPieceShape.None == shape)
            {
                return(false);
            }


            // force orientation to range 1..totalOrientations
            int totalOrientations = 0;

            totalOrientations = STPiece.GetMaximumOrientationsOfShape(shape);

            if (0 == totalOrientations)
            {
                return(false);
            }

            orientation =
                1 + ((((orientation - 1) % totalOrientations)
                      + totalOrientations) % totalOrientations);


            // Loop through all cells and test against supplied cell.
            int totalCells = 0;

            totalCells = STPiece.GetTotalCellsForShape(shape);
            int cellIndex = 0;

            for (cellIndex = 1; cellIndex <= totalCells; cellIndex++)
            {
                int cellX = 0;
                int cellY = 0;
                STPiece.GetCellOffsetXYForShape(shape, orientation, cellIndex, ref cellX, ref cellY);
                if ((x == cellX) && (y == cellY))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public void SetOrientation(int orientation)
        {
            int totalOrientations = 0;

            totalOrientations = STPiece.GetMaximumOrientationsOfShape(this.mShape);

            if (0 == totalOrientations)
            {
                this.mOrientation = 0;
                return;
            }

            orientation =
                1 + ((((orientation - 1) % totalOrientations)
                      + totalOrientations) % totalOrientations);

            this.mOrientation = orientation;
        }
Exemplo n.º 4
0
        public int GetOrientation()
        {
            int totalOrientations = 0;

            totalOrientations = STPiece.GetMaximumOrientationsOfShape(this.mShape);

            if (0 == totalOrientations)
            {
                this.mOrientation = 0;
                return(0);
            }

            this.mOrientation =
                1 + ((((this.mOrientation - 1) % totalOrientations)
                      + totalOrientations) % totalOrientations);

            return(this.mOrientation);
        }
Exemplo n.º 5
0
        public static void GetCellOffsetXYForShape
        (
            STPieceShape shape, // O,I,S,Z,L,J,T; None
            int orientation,    // 1,2,3,4; 0 == none
            int cellIndex,      // 1,2,3,4; 0 == none
            ref int x,
            ref int y
        )
        {
            x = 0;
            y = 0;

            // force cellIndex to range 1..4
            cellIndex = 1 + (((cellIndex - 1) % 4 + 4) % 4);


            // force orientation to range 1..totalOrientations
            int totalOrientations = 0;

            totalOrientations = STPiece.GetMaximumOrientationsOfShape(shape);

            if (0 == totalOrientations)
            {
                return;
            }

            orientation =
                1 + ((((orientation - 1) % totalOrientations)
                      + totalOrientations) % totalOrientations);


            if (STPieceShape.None == shape)
            {
                return;
            }

            if (STPieceShape.O == shape)
            {
                // orientation 1,2,3,4 : (-1, -1),  ( 0, -1),  ( 0,  0),  (-1,  0)
                if (1 == cellIndex)
                {
                    x = -1; y = -1;
                }
                else if (2 == cellIndex)
                {
                    x = 0; y = -1;
                }
                else if (3 == cellIndex)
                {
                    x = 0; y = 0;
                }
                else if (4 == cellIndex)
                {
                    x = -1; y = 0;
                }
            }

            if (STPieceShape.I == shape)
            {
                // orientation 1,3: (-2,  0),  (-1,  0),  ( 0,  0),  ( 1,  0)
                // orientation 2,4: ( 0, -2),  ( 0, -1),  ( 0,  0),  ( 0,  1)
                if ((1 == orientation) || (3 == orientation))
                {
                    if (1 == cellIndex)
                    {
                        x = -2; y = 0;
                    }
                    else if (2 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -2;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
            }

            if (STPieceShape.S == shape)
            {
                // orientation 1,3: (-1, -1),  ( 0, -1),  ( 0,  0),  ( 1,  0)
                // orientation 2,4: ( 1, -1),  ( 0,  0),  ( 1,  0),  ( 0,  1)
                if ((1 == orientation) || (3 == orientation))
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = 1; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
            }

            if (STPieceShape.Z == shape)
            {
                // orientation 1,3: ( 0, -1),  ( 1, -1),  (-1,  0),  ( 0,  0)
                // orientation 2,4: ( 0, -1),  ( 0,  0),  ( 1,  0),  ( 1,  1)
                if ((1 == orientation) || (3 == orientation))
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 1; y = -1;
                    }
                    else if (3 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 1;
                    }
                }
            }


            if (STPieceShape.L == shape)
            {
                // orientation 1: (-1, -1),  (-1,  0),  ( 0,  0),  ( 1,  0)
                // orientation 2: ( 0, -1),  ( 1, -1),  ( 0,  0),  ( 0,  1)
                // orientation 3: (-1,  0),  ( 0,  0),  ( 1,  0),  ( 1,  1)
                // orientation 4: ( 0, -1),  ( 0,  0),  (-1,  1),  ( 0,  1)
                if (1 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                }
                else if (2 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 1; y = -1;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
                else if (3 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 1;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = -1; y = 1;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
            }


            if (STPieceShape.J == shape)
            {
                // orientation 1: ( 1, -1),  (-1,  0),  ( 0,  0),  ( 1,  0)
                // orientation 2: ( 0, -1),  ( 0,  0),  ( 0,  1),  ( 1,  1)
                // orientation 3: (-1,  0),  ( 0,  0),  ( 1,  0),  (-1,  1)
                // orientation 4: (-1, -1),  ( 0, -1),  ( 0,  0),  ( 0,  1)
                if (1 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = 1; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                }
                else if (2 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 1;
                    }
                }
                else if (3 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = -1; y = 1;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
            }


            if (STPieceShape.T == shape)
            {
                // orientation 1: ( 0, -1),  (-1,  0),  ( 0,  0),  ( 1,  0)
                // orientation 2: ( 0, -1),  ( 0,  0),  ( 1,  0),  ( 0,  1)
                // orientation 3: (-1,  0),  ( 0,  0),  ( 1,  0),  ( 0,  1)
                // orientation 4: ( 0, -1),  (-1,  0),  ( 0,  0),  ( 0,  1)
                if (1 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                }
                else if (2 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
                else if (3 == orientation)
                {
                    if (1 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (2 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 1; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
                else
                {
                    if (1 == cellIndex)
                    {
                        x = 0; y = -1;
                    }
                    else if (2 == cellIndex)
                    {
                        x = -1; y = 0;
                    }
                    else if (3 == cellIndex)
                    {
                        x = 0; y = 0;
                    }
                    else if (4 == cellIndex)
                    {
                        x = 0; y = 1;
                    }
                }
            }
        }