コード例 #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));
 }