Beispiel #1
0
        public bool OverlapsWith(Ship ship)
        {
            if (Equals(ship))
            {
                return true;
            }

            var widthRange = Enumerable.Range(X, EndX - X + 1 + Board.GAP);
            var heightRange = Enumerable.Range(Y, EndY - Y + 1 + Board.GAP);

            var widthShipRange = Enumerable.Range(ship.X, ship.EndX - ship.X + 1 + Board.GAP);
            var heightShipRange = Enumerable.Range(ship.Y, ship.EndY - ship.Y + 1 + Board.GAP);

            return widthRange.Intersect(widthShipRange).Count() > 0 && heightRange.Intersect(heightShipRange).Count() > 0;
        }
Beispiel #2
0
 public static bool TryParse(string notation, out Ship ship)
 {
     try
     {
         ship = Parse(notation);
         return true;
     }
     catch (NotAShipException)
     {
         ship = null;
         return false;
     }
 }