mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 00:57:13 -08:00
Convert Hexapawn to common library
This commit is contained in:
@@ -82,9 +82,21 @@ public interface IReadWrite
|
||||
/// <param name="value">The <see cref="float" /> to be written.</param>
|
||||
void WriteLine(float value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes an <see cref="object" /> to output.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="object" /> to be written.</param>
|
||||
void Write(object value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes an <see cref="object" /> to output.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="object" /> to be written.</param>
|
||||
void WriteLine(object value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a <see cref="Stream" /> to output.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="Stream" /> to be written.</param>
|
||||
void Write(Stream stream);
|
||||
void Write(Stream stream, bool keepOpen = false);
|
||||
}
|
||||
|
||||
@@ -95,13 +95,19 @@ public class TextIO : IReadWrite
|
||||
|
||||
public void WriteLine(float value) => _output.WriteLine(GetString(value));
|
||||
|
||||
public void Write(Stream stream)
|
||||
public void Write(object value) => _output.Write(value.ToString());
|
||||
|
||||
public void WriteLine(object value) => _output.WriteLine(value.ToString());
|
||||
|
||||
public void Write(Stream stream, bool keepOpen = false)
|
||||
{
|
||||
using var reader = new StreamReader(stream);
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
_output.WriteLine(reader.ReadLine());
|
||||
}
|
||||
|
||||
if (!keepOpen) { stream?.Dispose(); }
|
||||
}
|
||||
|
||||
private string GetString(float value) => value < 0 ? $"{value} " : $" {value} ";
|
||||
|
||||
Reference in New Issue
Block a user