Esempio n. 1
0
 public void Add(Ship ship)
 {
     if (!ship.FitsInSquare(ship.X + ship.Length, ship.Y + ship.Length)) throw new ArgumentOutOfRangeException();
     if (!_ships.Any())
         _ships.Add(ship);
     else
     {
         for (int i = 0; i<_ships.Count; i++)
         {
             if (_ships[i].OverlapsWith(ship))
                 throw new ShipOverlapException($"Ship {_ships[i].ToString()} - overlaps with {ship.ToString()}");
             _ships.Add(ship);
         }
     }
 }