Exemplo n.º 1
0
        /// <summary>
        /// Generate ship location data
        /// </summary>
        /// <param name="locationModel"><see cref="LocationModel"/></param>
        /// <returns><see cref="ShipModel"/></returns>
        private ShipModel GenerateShipModel(LocationModel locationModel)
        {
            var shipModel = new ShipModel(locationModel.SquareSize);

            do
            {
                locationModel.StartHorizontalPositionIndex = _random.Next(0, locationModel.BoardSize - 1);
                locationModel.StartVerticalLocationIndex   = _random.Next(1, locationModel.BoardSize);

                locationModel = GetStartPosition(locationModel);
            }while (!_shipService.TryToGenerateShipModel(locationModel, ref shipModel));

            return(shipModel);
        }