Beispiel #1
0
        /// <summary>
        /// Recursively opens all adjacent cells of a cell which has no neighbors with mines.
        /// </summary>
        /// <param name="cellPos">The current cell.</param>
        private void OpenEmptyCellsRecursive(ICellPosition cellPos)
        {
            // All neighbors must not have mines.
            Debug.Assert(this.AllNeighborMines[cellPos.Row, cellPos.Col] == 0, "All neighbors must not have mines!");

            for (int row = -1; row < 2; row++)
            {
                for (int col = -1; col < 2; col++)
                {
                    if (col == 0 && row == 0)
                    {
                        continue;
                    }

                    if (this.IsInsideMatrix(cellPos.Row + row, cellPos.Col + col))
                    {
                        CellPos neighborCellPos = new CellPos(cellPos.Row + row, cellPos.Col + col);
                        int currentIndex = this.GetIndex(neighborCellPos);

                        if (this.Cells[currentIndex].IsOpened)
                        {
                            continue;
                        }

                        this.Cells[currentIndex].OpenCell();
                        this.OpenedCellsCount += 1;

                        if (this.AllNeighborMines[neighborCellPos.Row, neighborCellPos.Col] == 0)
                        {
                            this.OpenEmptyCellsRecursive(neighborCellPos);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIManager"/> class.
        /// </summary>
        /// <param name="renderer">The renderer which is going to be used by the UIManager.</param>
        /// <param name="inputReader">The input reader which UIManager is going to use.</param>
        public UIManager(IRenderer renderer, IUserInputReader inputReader)
        {
            this.Renderer = renderer;            
            this.InputReader = inputReader;

            this.cmdLineRow = CmdLineRowDefault;
            this.minefieldTopLeft = new CellPos(3, 0);
            this.boardGenerator = new BoardDrawer(renderer);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmdFlagCell"/> class.
        /// </summary>
        /// <param name="game">The <see cref="MinesweeperGame"/> object on which the action will be invoked.</param>
        /// <param name="targetCell">The position of the cell on which the action will be invoked.</param>
        public CmdFlagCell(MinesweeperGame game, CellPos targetCell)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            this.game = game;
            this.targetCell = targetCell;
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmdOpenCell"/> class.
        /// </summary>
        /// <param name="game">The <see cref="MinesweeperGame"/> object on which the action will be invoked.</param>
        /// <param name="cellToOpen">The position of the cell on which the action will be invoked.</param>
        public CmdOpenCell(MinesweeperGame game, CellPos cellToOpen)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            this.game = game;
            this.cellToOpen = cellToOpen;
        }
Beispiel #5
0
 public void TestInitialize()
 {
     int row = 1;
     int col = 1;
     cell = new CellPos(row, col);
 }