Files
basic-computer-games/62 Mugwump/csharp/Mugwump/Grid.cs
2021-10-04 23:02:53 +11:00

41 lines
960 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Mugwump
{
internal class Grid
{
private readonly List<Mugwump> _mugwumps;
public Grid(IEnumerable<Mugwump> mugwumps)
{
_mugwumps = mugwumps.ToList();
}
public bool Check(Position guess)
{
foreach (var mugwump in _mugwumps.ToList())
{
var (found, distance) = mugwump.FindFrom(guess);
Console.WriteLine(found ? $"You have found {mugwump}" : $"You are {distance} units from {mugwump}");
if (found)
{
_mugwumps.Remove(mugwump);
}
}
return _mugwumps.Count == 0;
}
public void Reveal()
{
foreach (var mugwump in _mugwumps.ToList())
{
Console.WriteLine(mugwump.Reveal());
}
}
}
}