Esempio n. 1
0
        /// <summary>
        /// If cells in m_highlightPositions forms one block, add block in m_puzzle, and draw the block. Otherwise, do nothing.
        /// </summary>
        /// <returns>PlacedBlock if block is found, null otherwise</returns>
        private PlacedBlock FindAndHighlightBlockMaybe()
        {
            if (m_highlightPositions.Count == 0)
            {
                return(null);
            }
            int minX = m_highlightPositions.Select(pos => pos.x).Min();
            int minY = m_highlightPositions.Select(pos => pos.y).Min();
            int maxX = m_highlightPositions.Select(pos => pos.x).Max();
            int maxY = m_highlightPositions.Select(pos => pos.y).Max();

            if (maxX - minX > 3 || maxY - minY > 3)
            {
                return(null);
            }
            int[,] hlBlockIndex = new int[4, 4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (m_highlightPositions.Contains(new Position(minX + i, minY + j)))
                    {
                        hlBlockIndex[i, j] = 1;
                    }
                }
            }
            foreach (string name in BlockFactory.m_blockNames)
            {
                Block b = BlockFactory.GetBlockByName(name);
                for (int i = 0; i < b.m_varients.Count; i++)
                {
                    if (BlockFactory.ArrayEquals(b.m_varients[i], hlBlockIndex))
                    {
                        PlacedBlock pb = new PlacedBlock(b, i, minX, minY);
                        return(pb);
                    }
                }
            }
            return(null);
        }