Пример #1
0
        public void Reveal()
        {
            if (flagged)
            {
                return;
            }
            if (revealed)
            {
                return;
            }

            if (this.IsMine())
            {
                revealLabel.Text = "M";
                if (!parent.IsGameOver())
                {
                    parent.EndGame(false);
                }
                return;
            }

            Cell[,] cells = parent.GetCells();

            revealLabel.BackColor = Color.White;
            revealed = true;

            int surroundingMines = CountMines();

            if (surroundingMines == 0)
            {
                revealLabel.Text = "";

                for (int c = -1; c <= 1; c++)
                {
                    for (int r = -1; r <= 1; r++)
                    {
                        if (!(c == 0 && r == 0))
                        {
                            try
                            {
                                if (Math.Abs(c) == Math.Abs(r) && cells[col + c, row + r].CountMines() == 0)
                                {
                                    continue;
                                }

                                cells[col + c, row + r].Reveal();
                            }
                            catch (IndexOutOfRangeException e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }
                }
            }
            else
            {
                revealLabel.Text = Convert.ToString(surroundingMines);
            }
        }