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 int _currentPlayer; private TicTacTocBoard _board; public TicTacTocBoard Board => _board; public TicTacTocManager(/*ITicTacToctRepository repo*/) { //_repo = repo; _currentPlayer = 1; Restart(); } public bool NextMove(TicTacTocRequest move) { var result = _board.SetFieldValue(_currentPlayer, move.Field); //move.PosX, move.PosY); // switch between 1 and 2 _currentPlayer = 3 - _currentPlayer; return result; } 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() { _currentPlayer = new Random().Next(1, 2); _board = new TicTacTocBoard(); } } }