mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-19 00:06:04 -08:00
Split classes to files
This commit is contained in:
27
77_Salvo/csharp/Extensions/IOExtensions.cs
Normal file
27
77_Salvo/csharp/Extensions/IOExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace Games.Common.IO;
|
||||
|
||||
internal static class IOExtensions
|
||||
{
|
||||
internal static Position ReadPosition(this IReadWrite io) => Position.Create(io.Read2Numbers(""));
|
||||
|
||||
internal static Position ReadValidPosition(this IReadWrite io)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (Position.TryCreateValid(io.Read2Numbers(""), out var position))
|
||||
{
|
||||
return position;
|
||||
}
|
||||
io.WriteLine("ILLEGAL, ENTER AGAIN.");
|
||||
}
|
||||
}
|
||||
|
||||
internal static IEnumerable<Position> ReadPositions(this IReadWrite io, string shipName, int shipSize)
|
||||
{
|
||||
io.WriteLine(shipName);
|
||||
for (var i = 0; i < shipSize; i++)
|
||||
{
|
||||
yield return io.ReadPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user