Esempio n. 1
0
        private void Value_StateChanged(object sender, EventArgs e)
        {
            var mineBtn = sender as MineButton;


            if (mineBtn.Type != MineButtonType.Mine && mineBtn.MineNear == 0)
            {
                Suspend();
                OpenNearCells(mineBtn.PosX, mineBtn.PosY);
                Unsuspend();
            }
            MinesStateChanged?.Invoke(this, null);
        }
Esempio n. 2
0
        public void FastOpenCells(int x, int y)
        {
            Suspend();
            var mineNear   = _field[x, y].MineNear;
            var mineMarked = 0;

            for (int i = x - 1; i <= x + 1; i++)
            {
                for (int j = y - 1; j <= y + 1; j++)
                {
                    if (i < 0 ||
                        j < 0 ||
                        i >= SizeX ||
                        j >= SizeY ||
                        (i == x && j == y) ||
                        _field[i, j].State != MineButtonState.MarkAsMine)
                    {
                        continue;
                    }
                    mineMarked++;
                }
            }
            if (mineMarked == mineNear)
            {
                for (int i = x - 1; i <= x + 1; i++)
                {
                    for (int j = y - 1; j <= y + 1; j++)
                    {
                        if (i < 0 ||
                            j < 0 ||
                            i >= SizeX ||
                            j >= SizeY ||
                            (i == x && j == y) ||
                            _field[i, j].State != MineButtonState.UnMarked)
                        {
                            continue;
                        }
                        _field[i, j].Detonate();
                        if (_field[i, j].Type != MineButtonType.Mine && _field[i, j].MineNear == 0)
                        {
                            OpenNearCells(i, j);
                        }
                    }
                }
            }
            Unsuspend();
            MinesStateChanged?.Invoke(this, null);
        }