Exemple #1
0
 private static Ship GetShip(RandomShipLocation randomShipLocation)
 {
     if (randomShipLocation.IsVertical)
     {
         return(PlaceShipVerticalOnMap(randomShipLocation));
     }
     return(PlaceShipHorizontalOnMap(randomShipLocation));
 }
Exemple #2
0
 private static Ship CreateVerticalShip(RandomShipLocation randomShipLocation)
 {
     return(new Ship
     {
         ShipFront = Coordinate.FromIndex(randomShipLocation.StartShepPoint, randomShipLocation.ConstantRowOrColumn),
         ShipBack = Coordinate.FromIndex(randomShipLocation.StartShepPoint + randomShipLocation.ShipSize - 1,
                                         randomShipLocation.ConstantRowOrColumn)
     });
 }
Exemple #3
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);
         }
     }
 }
Exemple #4
0
 private static Ship PlaceShipHorizontalOnMap(RandomShipLocation randomShipLocation)
 {
     return(CreateHorizontalShip(randomShipLocation));
 }
Exemple #5
0
 private static Ship PlaceShipVerticalOnMap(RandomShipLocation randomShipLocation)
 {
     return(CreateVerticalShip(randomShipLocation));
 }