mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 04:15:45 -08:00
35 lines
846 B
C#
35 lines
846 B
C#
namespace Salvo.Targetting;
|
|
|
|
internal class HumanShotSelector : ShotSelector
|
|
{
|
|
private readonly IReadWrite _io;
|
|
|
|
internal HumanShotSelector(Fleet source, IReadWrite io)
|
|
: base(source)
|
|
{
|
|
_io = io;
|
|
}
|
|
|
|
protected override IEnumerable<Position> GetShots()
|
|
{
|
|
var shots = new Position[NumberOfShots];
|
|
|
|
for (var i = 0; i < shots.Length; i++)
|
|
{
|
|
while (true)
|
|
{
|
|
var position = _io.ReadValidPosition();
|
|
if (WasSelectedPreviously(position, out var turnTargeted))
|
|
{
|
|
_io.WriteLine($"YOU SHOT THERE BEFORE ON TURN {turnTargeted}");
|
|
continue;
|
|
}
|
|
shots[i] = position;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return shots;
|
|
}
|
|
}
|