Example #1
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="field">Field</param>
 internal Field(IField field)
 {
     if (field == null)
     {
         cells = new ECell[width * height];
     }
     else
     {
         SelectedBlock          = field.SelectedBlock;
         SelectedBlockPositionX = field.SelectedBlockPositionX;
         SelectedBlockPositionY = field.SelectedBlockPositionY;
         SelectedBlockRotation  = field.SelectedBlockRotation;
         cells = new ECell[field.Width * field.Height];
         field.CopyCellsTo(cells, false);
     }
 }
Example #2
0
        /// <summary>
        /// Rotate block
        /// </summary>
        /// <param name="blockCells">Block cells</param>
        /// <param name="blockRotation">Block rotation</param>
        /// <returns>ROtated block cells</returns>
        private static ECell[,] RotateBlock(ECell[,] blockCells, EBlockRotation blockRotation)
        {
            ECell[,] ret = null;
            switch (blockRotation)
            {
            case EBlockRotation.ZeroDegree:
                ret = blockCells;
                break;

            case EBlockRotation.NinetyDegree:
                ret = new ECell[blockCells.GetLength(1), blockCells.GetLength(0)];
                for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++)
                {
                    for (y = 0; y < y_len; y++)
                    {
                        ret[x, y_len - y - 1] = blockCells[y, x];
                    }
                }
                break;

            case EBlockRotation.OneHundredEightyDegree:
                ret = new ECell[blockCells.GetLength(0), blockCells.GetLength(1)];
                for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++)
                {
                    for (y = 0; y < y_len; y++)
                    {
                        ret[x_len - x - 1, y_len - y - 1] = blockCells[x, y];
                    }
                }
                break;

            case EBlockRotation.TwoHundredSeventyDegree:
                ret = new ECell[blockCells.GetLength(1), blockCells.GetLength(0)];
                for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++)
                {
                    for (y = 0; y < y_len; y++)
                    {
                        ret[x_len - x - 1, y] = blockCells[y, x];
                    }
                }
                break;
            }
            return(ret);
        }
Example #3
0
        /// <summary>
        /// Turn block
        /// </summary>
        /// <param name="turnLeft">Turn left</param>
        /// <returns>"true" if successful, otherwise "false"</returns>
        private bool TurnBlock(bool turnLeft)
        {
            bool  ret   = false;
            Field field = user.FieldInternal;

            if (field.SelectedBlock != EBlock.Nothing)
            {
                EBlockRotation block_rotation = (EBlockRotation)(((int)(field.SelectedBlockRotation) + (turnLeft ? 1 : 3)) % blockRotationCount);
                ECell[]        field_cells    = new ECell[Field.width * Field.height];
                ECell[,] block_cells = GetBlockCells(field.SelectedBlock, block_rotation);
                int x_origin = (int)(field.SelectedBlockPositionX);
                int y_origin = (int)(field.SelectedBlockPositionY);
                if (field.CopyCellsTo(field_cells, false))
                {
                    ret = CheckCells(field_cells, block_cells, x_origin, y_origin);
                    if (ret)
                    {
                        field.SelectedBlockRotation = block_rotation;
                    }
                }
            }
            return(ret);
        }
Example #4
0
 /// <summary>
 /// Get block cells
 /// </summary>
 /// <param name="block">Block</param>
 /// <param name="blockRotation">Block rotation</param>
 /// <returns>Block cells</returns>
 internal static ECell[,] GetBlockCells(EBlock block, EBlockRotation blockRotation) => blocksCells[(int)block][(int)blockRotation];