Add move logic

This commit is contained in:
Andrew Cooper
2022-08-16 09:01:14 +10:00
parent 35f8248b1f
commit 876c71d89b
3 changed files with 70 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ internal class Game
{
private readonly IReadWrite _io;
private readonly Board _board;
private int _moveCount;
public Game(IReadWrite io)
{
@@ -15,6 +16,31 @@ internal class Game
{
_io.Write(Streams.Introduction);
_io.WriteLine(_board);
do
{
_io.WriteLine(_board);
_io.WriteLine();
} while (PlayMove());
_io.WriteLine(Formats.Results, _moveCount, _board.Count);
}
private bool PlayMove()
{
while (true)
{
var from = (int)_io.ReadNumber(Prompts.From);
if (from == 0) { return false; }
var move = new Move { From = from, To = (int)_io.ReadNumber(Prompts.To) };
if (_board.TryMove(move))
{
_moveCount++;
return true;
}
_io.Write(Streams.IllegalMove);
}
}
}