/// <summary> /// Tries to clear the <see cref="Cell"/> at (<paramref name="x"/>, <paramref name="y"/>). /// </summary> /// <param name="x">The 0-based column number of a <see cref="Cell"/></param> /// <param name="y">The 0-based row number of a <see cref="Cell"/></param> /// <param name="changedCells">The list of <see cref="Cell"/>s affected by this clear action. Data about changed <see cref="Cell"/>s is provided via <see cref="ChangedCell"/>.</param> /// <returns>true if the <see cref="Cell"/> at (<paramref name="x"/>, <paramref name="y"/>) is safe to clear (not a mine), false otherwise</returns> public static bool TryClearCell(int x, int y, ref List <ChangedCell> changedCells) { var coord = new Coordinate(x, y); if (CurrentField.Clear(coord)) { var cell = CurrentField[coord]; if (!cell.Flagged) { changedCells.Add(new ChangedCell(coord, cell.NeighboringMines)); if (cell.NeighboringMines == 0) { changedCells.AddRange(ClearLonelyNeighbors(coord)); } } CheckGameWon(); return(true); } else { timer.Stop(); GameEnd?.Invoke(false); return(false); } }
/// <summary> /// Checks if the current field has been correctly cleared. Stops timer and sets <see cref="GameWon"/> if so /// </summary> /// <remarks> /// Checks if <see cref="CurrentField"/>'s <see cref="MineField.MinesLeft()"/> == 0 and <see cref="CurrentField"/>'s <see cref="MineField.CellsLeft()"/> == 0 /// </remarks> public static void CheckGameWon() { if (CurrentField.MinesLeft() == 0 && CurrentField.CellsLeft() == 0) { timer.Stop(); GameEnd?.Invoke(true); } }