[Fix] Flag bug

This commit is contained in:
2026-06-07 01:17:25 +07:00
parent 5a58c9031a
commit 492c1ea9f9
2 changed files with 18 additions and 52 deletions
+14 -2
View File
@@ -251,12 +251,13 @@ namespace Minesweeper.Core
while (queue.Count > 0)
{
var cell = queue.Dequeue();
if (visited[cell.X, cell.Y] || cell.IsMine || cell.IsFlagged)
if (visited[cell.X, cell.Y] || cell.IsMine)
{
continue;
}
visited[cell.X, cell.Y] = true;
ClearFlag(cell);
OpenSafeCell(cell);
if (cell.NeighborMines != 0)
@@ -274,7 +275,7 @@ namespace Minesweeper.Core
}
var neighbor = cells[x, y];
if (!visited[x, y] && !neighbor.IsMine && !neighbor.IsFlagged && !neighbor.IsOpened)
if (!visited[x, y] && !neighbor.IsMine && !neighbor.IsOpened)
{
queue.Enqueue(neighbor);
}
@@ -295,6 +296,17 @@ namespace Minesweeper.Core
AddChangedCell(cell);
}
private void ClearFlag(CellData cell)
{
if (!cell.IsFlagged)
{
return;
}
cell.IsFlagged = false;
FlaggedCellsCount--;
}
private void AddChangedCell(CellData cell)
{
changedCells.Add(ToData(cell));