mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 00:57:13 -08:00
32 lines
792 B
C#
32 lines
792 B
C#
namespace Salvo.Targetting;
|
|
|
|
internal class HumanShotSelector : ShotSelector
|
|
{
|
|
public HumanShotSelector(Grid source, Grid target)
|
|
: base(source, target)
|
|
{
|
|
}
|
|
|
|
public IEnumerable<Position> GetShots(IReadWrite io)
|
|
{
|
|
var shots = new Position[GetShotCount()];
|
|
|
|
for (var i = 0; i < shots.Length; i++)
|
|
{
|
|
while (true)
|
|
{
|
|
var position = io.ReadValidPosition();
|
|
if (Target.WasTargetedAt(position, out var turnTargeted))
|
|
{
|
|
io.WriteLine($"YOU SHOT THERE BEFORE ON TURN {turnTargeted}");
|
|
continue;
|
|
}
|
|
shots[i] = position;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return shots;
|
|
}
|
|
}
|