Exemplo n.º 1
0
        public IShip[] RandomizeShipsPositions()
        {
            var addedShipPositions = new List <IShip>();
            var random             = new Random();

            var shipsLeft = new List <int>(_gameSettings.ShipSizes);

            while (shipsLeft.Any())
            {
                var currentShipSize = shipsLeft.Max();

                List <IShip> possiblePositions = GetPossibleShipPositions(addedShipPositions, currentShipSize);

                var chosenPossiblePosition = possiblePositions[random.Next(possiblePositions.Count)];
                addedShipPositions.Add(chosenPossiblePosition);

                shipsLeft.Remove(currentShipSize);
            }

            var resultShips = addedShipPositions.ToArray();

            _shipsGroupValidator.ValidateShips(resultShips);

            return(resultShips);
        }
Exemplo n.º 2
0
 public Board(IShip[] ships, IShipsGroupValidator shipsGroupValidator, IGameSettings gameSettings)
 {
     _gameSettings        = gameSettings;
     _shipsGroupValidator = shipsGroupValidator;
     _shipsGroupValidator.ValidateShips(ships);
     Ships  = ships;
     Fields = FillTheFields(Ships);
 }