示例#1
0
        public bool canRotate()
        {
            //Go through all fallenBlocks and cycle through all Rotations and if any of them are inside the fallenBlocks return false
            var   rotations = Enum.GetValues(typeof(Tetro));
            Tetro ogType    = currentTetromino.Type;

            int[,] currentTetroPos;
            for (int i = 0; i < fallenBlocks.GetLength(0); i++)
            {
                for (int c = 0; c < fallenBlocks.GetLength(1); c++)
                {
                    foreach (Tetro rotation in rotations)
                    {
                        currentTetromino.Type = rotation;
                        currentTetromino.updateBlockNoRestriction();
                        try
                        {
                            currentTetroPos = findTetroPositionInField(currentTetromino);
                        }
                        catch
                        {
                            currentTetromino.Type = ogType;
                            currentTetromino.updateBlockNoRestriction();
                            return(false);
                        }
                        for (int pos = 0; pos < currentTetroPos.GetLength(0); pos++)
                        {
                            if (currentTetroPos[pos, 0] == i && fallenBlocks[i, c] && currentTetroPos[pos, 1] == c)
                            {
                                currentTetromino.Type = ogType;
                                currentTetromino.updateBlockNoRestriction();
                                return(false);
                            }
                        }
                    }
                }
            }
            currentTetromino.Type = ogType;
            currentTetromino.updateBlockNoRestriction();
            return(true);
        }