Esempio n. 1
0
        private Coordinate GetNextRandom()
        {
            while (true)
            {
                var randomRow    = _shipDataGenerator.GetRand0To9();
                var randomColumn = _shipDataGenerator.GetRand0To9();

                if (!_alreadyGeneratedCoordinates.Select(x => x.Key)
                    .Contains(Coordinate.FromIndex(randomRow, randomColumn)))
                {
                    return(Coordinate.FromIndex(randomRow, randomColumn));
                }
            }
        }
Esempio n. 2
0
 private Ship GetUniqueShip(int shipSize, List <Ship> insertedShips)
 {
     while (true)
     {
         var randomShipLocation = new RandomShipLocation
         {
             ShipSize            = shipSize,
             IsVertical          = _randomShipDataGenerator.GetIsVertical(),
             ConstantRowOrColumn = _randomShipDataGenerator.GetRand0To9(),
             StartShepPoint      = _randomShipDataGenerator.GetStartShipPoint(shipSize)
         };
         var shipForInsert = GetShip(randomShipLocation);
         if (CanInsertShip(insertedShips, shipForInsert))
         {
             return(shipForInsert);
         }
     }
 }