private static Ship GetShip(RandomShipLocation randomShipLocation) { if (randomShipLocation.IsVertical) { return(PlaceShipVerticalOnMap(randomShipLocation)); } return(PlaceShipHorizontalOnMap(randomShipLocation)); }
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) }); }
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); } } }
private static Ship PlaceShipHorizontalOnMap(RandomShipLocation randomShipLocation) { return(CreateHorizontalShip(randomShipLocation)); }
private static Ship PlaceShipVerticalOnMap(RandomShipLocation randomShipLocation) { return(CreateVerticalShip(randomShipLocation)); }