public void TestCascadeFlaggedCells()
        {
            int rows = 5;
            int cols = 5;

            var mines = new List<Point>
            {
                new Point(cols - 1, rows - 1)
            };
            IPointGenerator generator = new DeterminatePointGenerator(mines);
            IGameSettings settings = new GameSettings(rows, cols, mines.Count, generator);
            IMineSearchGame game = new MineSearchGame(settings);

            var flaggedPoint = new Point(1, 0);
            game.FlagCell(flaggedPoint);

            var revealedPoint = new Point(0, 0);
            game.RevealCell(revealedPoint);
            game.CascadeCell(revealedPoint);

            var revealedCells =
                game.Cells.Where(cell => cell.Revealed).Select(cell => cell.Coordinates).ToList();

            Assert.IsFalse(revealedCells.Contains(flaggedPoint));
        }
        public void TestSimple()
        {
            int rows = 5;
            int cols = 5;

            var mines = new List<Point>
            {
                new Point(0, 0)
            };
            IPointGenerator generator = new DeterminatePointGenerator(mines);
            IGameSettings settings = new GameSettings(rows, cols, mines.Count, generator);
            IMineSearchGame game = new MineSearchGame(settings);

            var point = new Point(cols - 1, rows - 1);
            game.RevealCell(point);
            game.CascadeCell(point);

            var revealedCells = game.Cells.Count(c => c.Revealed);
            Assert.AreEqual(game.Cells.Size - 1, revealedCells);
        }
        public void TestCascade()
        {
            var mine = new List<Point>
            {
                new Point(0, 2),
                new Point(3, 2),
                new Point(4, 2),
                new Point(0, 3),
                new Point(4, 4)
            };
            var pointGenerator = new DeterminatePointGenerator(mine);
            IGameSettings gameSettings = new GameSettings(5, 5, 5, pointGenerator);
            IMineSearchGame game = new MineSearchGame(gameSettings);

            var point = new Point(0, 0);
            game.RevealCell(point);
            game.CascadeCell(point);

            var revealedSafeCells = game.Cells.Where(cell => cell is SafeCell && cell.Revealed);

            Assert.AreEqual(10, revealedSafeCells.Count());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MineCell"/> class.
        /// </summary>
        /// <param name="coordinates">Cell coordinates.</param>
        public MineCell(Point coordinates) : base(coordinates)
        {

        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SafeCell"/> class.
 /// </summary>
 /// <param name="coordinates">Cell coordinates.</param>
 public SafeCell(Point coordinates) : base(coordinates)
 {
 }
예제 #6
0
 /// <summary>
 /// Performs a cascading reveal.
 /// </summary>
 /// <param name="point">Coordinates of cell to reveal.</param>
 public void CascadeCell(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null)
     {
         var adjacentMineCount = Cells.GetAdjacentCells(cell).Count(c => c is MineCell);
         if (adjacentMineCount == 0)
         {
             var adjacent =
                 Cells.GetAdjacentCells(cell).Where(c => !c.Revealed && !c.Flagged).Select(
                     c => c.Coordinates);
             foreach (var adjacentPoint in adjacent)
             {
                 RevealCell(adjacentPoint);
                 CascadeCell(adjacentPoint);
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// Flags a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to flag.</param>
 /// <returns>True if the cell has been flagged, false otherwise.</returns>
 public bool FlagCell(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (GameOver || cell == null)
     {
         return false;
     }
     if (!cell.Revealed && !cell.Flagged)
     {
         cell.Flagged = true;
         RemainingMineCount--;
         return true;
     }
     return false;
 }
예제 #8
0
 /// <summary>
 /// Removes the questionable state from a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to remove questionable state from.</param>
 public void RemoveQuestionable(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null)
     {
         cell.Questionable = false;
     }
 }
예제 #9
0
 /// <summary>
 /// Reveals a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to reveal.</param>
 public void RevealCell(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && !cell.Revealed && !cell.Flagged)
     {
         cell.Revealed = true;
         // Is it a Mine cell?
         if (cell is MineCell)
         {
             if (!GameOver)
             {
                 var mineCell = cell as MineCell;
                 mineCell.ExplosionSource = true;
                 GameOver = true;
             }
         }
         // Otherwise must be a Safe cell
         else
         {
             _remainingCellsToReveal--;
             if (GameWon)
             {
                 GameOver = true;
             }
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Removes a flag from a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to remove flag from.</param>
 public void RemoveFlag(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && cell.Flagged)
     {
         RemainingMineCount++;
         cell.Flagged = false;
     }
 }
예제 #11
0
 /// <summary>
 /// Marks a cell as questionable.
 /// </summary>
 /// <param name="point">Coordinates of cell to mark as questionable.</param>
 public void MarkCellQuestionable(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null)
     {
         cell.Questionable = true;
     }
 }
 /// <summary>
 /// Removes the questionable state from a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to remove questionable state from.</param>
 /// <returns>True if the cell has been unmarked questionable, false otherwise.</returns>
 public bool RemoveQuestionable(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && cell.Questionable)
     {
         cell.Questionable = false;
         return true;
     }
     return false;
 }
 /// <summary>
 /// Marks a cell as questionable.
 /// </summary>
 /// <param name="point">Coordinates of cell to mark as questionable.</param>
 /// <returns>True if the cell has been marked questionable, false otherwise.</returns>
 public bool MarkCellQuestionable(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && !cell.Revealed && !cell.Questionable)
     {
         cell.Questionable = true;
         return true;
     }
     return false;
 }
 /// <summary>
 /// Removes a flag from a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to remove flag from.</param>
 /// <returns>True if the cell has been unflagged, false otherwise.</returns>
 public bool RemoveFlag(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && cell.Flagged)
     {
         RemainingMineCount++;
         cell.Flagged = false;
         return true;
     }
     return false;
 }
 /// <summary>
 /// Flags a cell.
 /// </summary>
 /// <param name="point">Coordinates of cell to flag.</param>
 /// <returns>True if the cell has been flagged, false otherwise.</returns>
 public bool FlagCell(Point point)
 {
     var cell = Cells[point.X, point.Y];
     if (cell != null && !cell.Revealed && !cell.Flagged)
     {
         // Be sure to unmark it as questionable.
         // This cell may have been in that state and then
         // automatically flagged at the end of the game.
         cell.Questionable = false;
         cell.Flagged = true;
         RemainingMineCount--;
         return true;
     }
     return false;
 }
예제 #16
0
 protected BaseCell(Point coordinates)
 {
     _coordinates = coordinates;
 }