ProjectGrid/Logic/TicTacTocManager.cs

50 lines
1.0 KiB
C#

using ProjectGrid;
using ProjectGrid.Data;
using ProjectGrid.Models;
using System;
namespace ProjectGrid
{
public interface ITicTacTocManager
{
public bool NextMove(TicTacTocRequest move);
public TicTacTocResponse GetResponse(int player = 0);
}
public class TicTacTocManager : ITicTacTocManager
{
//private ITicTacToctRepository _repo;
private TicTacTocBoard _board;
public TicTacTocBoard Board => _board;
public TicTacTocManager(/*ITicTacToctRepository repo*/)
{
//_repo = repo;
Restart();
}
public bool NextMove(TicTacTocRequest move)
{
return _board.SetFieldValue(move.Player, move.Field); //move.PosX, move.PosY);
}
public TicTacTocResponse GetResponse(int player = 0)
{
TicTacTocResponse response = new TicTacTocResponse();
if (player > 0 && _board.ValueWon(player))
response.PlayerWon = player;
response.Board = _board.Field;
return response;
}
public void Restart()
{
_board = new TicTacTocBoard();
}
}
}