Ejemplo n.º 1
0
        public override TurnReportDTO PlayTurn(int x, int y)
        {
            if (_gameTurn == 0)
            {
                _gameTurn = 1;
            }

            var report = new TurnReportDTO()
            {
                GameState = GameState.InProgress,
                Player    = _playerTurn,
                GameTurn  = _gameTurn,
                Success   = false,
                x         = x,
                y         = y,
                Winner    = Guid.Empty
            };

            if (_winner != null)
            {
                report.GameState = GameState.Won;
                report.Success   = false;
                report.Player    = _winner.Id;
                report.Winner    = _winner.Id;
                return(report);
            }

            try
            {
                CalculateState(x, y);
                report.Success = true;
            }
            catch (Exception e)
            {
                report.Message = e.Message;
            }

            if (_victoryCalculator.IsGameWon(_board.GetBoard()))
            {
                _winner          = _players.Find(e => e.Id == report.Player);
                report.GameState = GameState.Won;
                report.Winner    = _winner.Id;
            }
            else
            {
                _gameTurn++;
                _playerTurn = _players.Find(e => e.Id != report.Player).Id;
            }

            return(report);
        }
Ejemplo n.º 2
0
 public void ThrowErrorOnWrongSquareType()
 {
     _squares = new DummySquare[3][];
     for (int i = 0; i < 3; i++)
     {
         _squares[i] = new DummySquare[3];
         for (int j = 0; j < 3; j++)
         {
             _squares[i][j] = new DummySquare();
         }
     }
     _victoryCalculator.IsGameWon(_squares);
 }