예제 #1
0
 private static Ship GetShip(RandomShipLocation randomShipLocation)
 {
     if (randomShipLocation.IsVertical)
     {
         return(PlaceShipVerticalOnMap(randomShipLocation));
     }
     return(PlaceShipHorizontalOnMap(randomShipLocation));
 }
예제 #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)
     });
 }
예제 #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);
         }
     }
 }
예제 #4
0
 private static Ship PlaceShipHorizontalOnMap(RandomShipLocation randomShipLocation)
 {
     return(CreateHorizontalShip(randomShipLocation));
 }
예제 #5
0
 private static Ship PlaceShipVerticalOnMap(RandomShipLocation randomShipLocation)
 {
     return(CreateVerticalShip(randomShipLocation));
 }