45 lines
985 B
C#
45 lines
985 B
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;
|
|
_board = new TicTacTocBoard();
|
|
}
|
|
|
|
public bool NextMove(TicTacTocRequest move)
|
|
{
|
|
return _board.SetFieldValue(move.Player, 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;
|
|
|
|
}
|
|
}
|
|
} |