// TODO UnitOfWork
        public async Task AddShips(ShipsCreationModel creationModel)
        {
            IReadOnlyCollection <ShipDomainModel> ships = _coordinatesParser.ParseShipsCoordinates(creationModel.Coordinates);
            GameDomainModel game = await GetActiveGame();

            ThrowIfCanNotAddShips(game, ships);

            await _gameStateRepository.AddShips(game, ships);
        }
        public void CoordinatesParserShould_ParseSeveralShipsCoords(string strCoords,
                                                                    int x1_1, int y1_1, int x1_2, int y1_2,
                                                                    int x2_1, int y2_1, int x2_2, int y2_2)
        {
            var ships = _parser.ParseShipsCoordinates(strCoords, CoordsLimit);

            Assert.AreEqual(ships.Length, 2);
            AssertShipCoordinatesAreEqual(ships[0], x1_1, y1_1, x1_2, y1_2);
            AssertShipCoordinatesAreEqual(ships[1], x2_1, y2_1, x2_2, y2_2);
        }
예제 #3
0
 public ActionResult CreateShips(ShipModel shipModel)
 {
     if (shipModel == null || string.IsNullOrEmpty(shipModel.Coordinates))
     {
         return(BadRequest());
     }
     try
     {
         var shipsCoords = _coordinatesParser.ParseShipsCoordinates(shipModel.Coordinates,
                                                                    _game.Matrix.Size);
         _creationService.CreateShips(shipsCoords);
     }
     catch (BadCoordinatesException e)
     {
         _game.ResetMatrixWithShips();
         return(BadRequest(e.ToString()));
     }
     return(Ok());
 }