Esempio n. 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);
            }
        }
Esempio n. 2
0
        public bool StartNewGame()
        {
            var newGame = System.Windows.Forms.MessageBox.Show("Are you sure you want to start a new game?", "New Game", MessageBoxButtons.YesNo, MessageBoxIcon.None);

            if (newGame == DialogResult.Yes)
            {
                StopTimer();
                foreach (Cell c in g.GetCells())
                {
                    this.Controls.Remove(c.GetControl());
                }
                return(true);
            }
            return(false);
        }