Exemplo n.º 1
0
        public void OpenCell(ICell cell, bool isWithAround)
        {
            SelectCell(null, isWithAround);
            if (IsFrozen || cell == null)
            {
                return;
            }
            CellOperationOpening opening = cell.Open(isWithAround);

            countOpenedCells += opening.OpenedCount;
            if (opening.HasMines)
            {
                countErrors += opening.MineCount;
                SendFieldMessage(FieldMessage.MinesDetonated);
                countLabels -= opening.MineCount;
                SendFieldMessage(FieldMessage.ChangeLabelsCount);
            }
            if (countErrors > MaxErrorCount)
            {
                ShowAllMines();
            }
            else
            {
                CheckCells();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a <see cref="Sapper.Cell">cell</see> with empty cells and arounding cells if checked.
        /// </summary>
        /// <returns>
        /// Returns <see cref="Sapper.CellOpenResults">struct</see> with two integers:
        ///		<see cref="Sapper.CellOpenResults.MineCount">count of the opened mines</see>;
        ///		<see cref="Sapper.CellOpenResults.OpenedCount">count of the opened cells</see>.
        /// </returns>
        #endregion Help
        public CellOperationOpening Open(bool isWithAround)
        {
            CellOperationOpening opening = new CellOperationOpening();

            if (isWithAround)
            {
                if (!Closed && !IsMineDetonated && CheckAround())
                {
                    foreach (Cell cell in aroundCells)
                    {
                        opening += cell.Open(false);
                    }
                }
            }
            else if (CanOpened)
            {
                int counter = 0;
                if (HasMine)
                {
                    opening.MineCount = 1;
                    IsMineDetonated   = true;
                }
                DepthFirstSearch(this, ref counter);
                opening.OpenedCount = counter;
            }
            return(opening);
        }