コード例 #1
0
        private IEnumerable <Cell> GetMatchesHorizontally(Cell cell)
        {
            List <Cell> matches = new List <Cell>();

            matches.Add(cell);

            //Left items
            if (cell.Column != 0)
            {
                for (int column = cell.Column - 1; column >= 0; column--)
                {
                    Cell left = cells[cell.Row, column];
                    if (left.IsMatched(cell))
                    {
                        matches.Add(left);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //Right items
            if (cell.Column != columns - 1)
            {
                for (int column = cell.Column + 1; column < columns; column++)
                {
                    Cell right = cells[cell.Row, column];
                    if (right.IsMatched(cell))
                    {
                        matches.Add(right);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //Check for minimum matches
            if (matches.Count < minMatches)
            {
                matches.Clear();
            }

            return(matches.Distinct());
        }
コード例 #2
0
        private IEnumerable <Cell> GetMatchesVertically(Cell cell)
        {
            List <Cell> matches = new List <Cell>();

            matches.Add(cell);

            //Bottom items
            if (cell.Row != 0)
            {
                for (int row = cell.Row - 1; row >= 0; row--)
                {
                    Cell bottom = cells[row, cell.Column];
                    if (bottom.IsMatched(cell))
                    {
                        matches.Add(bottom);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //Top items
            if (cell.Row != rows - 1)
            {
                for (int row = cell.Row + 1; row < rows; row++)
                {
                    Cell top = cells[row, cell.Column];
                    if (top.IsMatched(cell))
                    {
                        matches.Add(top);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //Check for minimum matches
            if (matches.Count < minMatches)
            {
                matches.Clear();
            }

            return(matches.Distinct());
        }