示例#1
0
        private void EliminateContiguous()
        {
            List <Tuple <int, int> > toEliminate = new List <Tuple <int, int> >();

            for (int x = 0; x < this.config.BoardWidth; x++)
            {
                int count      = 0;
                int currentGem = Board.EMPTY;
                List <Tuple <int, int> > currentCells =
                    new List <Tuple <int, int> >();

                for (int y = 0; y < this.config.BoardHeight; y++)
                {
                    if (
                        this.board[x, y] == Board.EMPTY || this.isLocked[x, y]
                        )
                    {
                        currentCells.Clear();
                        count      = 0;
                        currentGem = Board.EMPTY;
                        continue;
                    }

                    if (this.board[x, y] != currentGem)
                    {
                        currentGem = this.board[x, y];
                        currentCells.Clear();
                        currentCells.Add(new Tuple <int, int>(x, y));
                        count = 1;
                    }
                    else
                    {
                        currentCells.Add(new Tuple <int, int>(x, y));
                        count++;
                    }

                    if (count >= 3)
                    {
                        toEliminate.AddRange(currentCells);
                    }
                }
            }

            for (int y = 0; y < this.config.BoardHeight; y++)
            {
                int count      = 0;
                int currentGem = Board.EMPTY;
                List <Tuple <int, int> > currentCells =
                    new List <Tuple <int, int> >();

                for (int x = 0; x < this.config.BoardWidth; x++)
                {
                    if (
                        this.board[x, y] == Board.EMPTY || this.isLocked[x, y]
                        )
                    {
                        currentCells.Clear();
                        count      = 0;
                        currentGem = Board.EMPTY;
                        continue;
                    }

                    if (this.board[x, y] != currentGem)
                    {
                        currentGem = this.board[x, y];
                        currentCells.Clear();
                        currentCells.Add(new Tuple <int, int>(x, y));
                        count = 1;
                    }
                    else
                    {
                        currentCells.Add(new Tuple <int, int>(x, y));
                        count++;
                    }

                    if (count >= 3)
                    {
                        toEliminate.AddRange(currentCells);
                    }
                }
            }

            if (toEliminate.Count > 0)
            {
                this.eliminationTimer = TimerManager.AddTimer(
                    durationMilliseconds: this.config.EliminationScrollCooldownMs,
                    onDoneCallback: () =>
                {
                    this.eliminationTimer = null;
                }
                    );
            }

            foreach (Tuple <int, int> cell in toEliminate.Distinct().ToList())
            {
                this.EliminateCell(cell.Item1, cell.Item2);
            }

            int numGemsEliminated = toEliminate.Distinct().Count();

            this.Score += numGemsEliminated * (numGemsEliminated - 2);
        }