Auto marking unmarked mines when win

This commit is contained in:
Masahiko AMANO 2022-03-11 19:04:45 +03:00
parent 2445155e93
commit b3e3b50d64
2 changed files with 11 additions and 9 deletions

View File

@ -151,7 +151,7 @@
}
return false;
}
public void OpenAll()
public void OpenAll(bool automark)
{
for (int i = 0; i < size; i++)
{
@ -159,8 +159,14 @@
opened.Add(cells[i]);
if (cells[i].IsMarked && !cells[i].IsMine)
cells[i].SetWrong();
if (automark && cells[i].IsMine)
{
cells[i].Mark();
nmines = 0;
}
}
this.Draw();
}
public void Mark(int y, int x)
{
if (!opened.Contains(cells[y * width + x]))

12
Game.cs
View File

@ -14,11 +14,12 @@
while (true)
{
Console.Clear();
field.Draw();
if (field.Check())
{
field.OpenAll(true);
return true;
}
field.Draw();
Console.Write("Enter your command: ");
try
{
@ -29,7 +30,8 @@
int y = command[0].First() - 'A';
if (field.Open(y, x))
{
this.Finish();
Console.Clear();
field.OpenAll(false);
return false;
}
}
@ -55,11 +57,5 @@
}
}
}
private void Finish()
{
field.OpenAll();
Console.Clear();
field.Draw();
}
}
}