コード例 #1
0
 public void PlaceAllShips(Board board)
 {
     foreach (var shipPlacement in GetAllShips())
     {
         board.Occupy(shipPlacement.Ship, shipPlacement.Orientation, shipPlacement.GridReference);
     }
 }
コード例 #2
0
        public void PlaceAllShips(Board board)
        {
            var ships = new List<Ship>();

            ships.Add(new Ship("Patrol boat"));
            ships.Add(new Ship("Destroyer"));
            ships.Add(new Ship("Submarine"));
            ships.Add(new Ship("Battleship"));
            ships.Add(new Ship("Carrier"));

            foreach (var ship in ships)
            {
                bool shipIsNotPlaced = true;
                while (shipIsNotPlaced)
                {
                    try
                    {
                        board.Occupy(ship, Orientationgenerator.Create(), GridReferenceGenerator.Create());
                        shipIsNotPlaced = false;
                    }
                    catch (Exception)
                    {
                        shipIsNotPlaced = true;
                    }
                }
            }
        }