public static bool TryParse(string notation, out Ship ship) { try { ship = Parse(notation); return true; } catch (NotAShipException) { ship = null; return false; } }
public static bool TryParse(string notation, out Ship pos) { bool result = true; pos = null; try { pos = Parse(notation); } catch (Exception) { result = false; } return result; }
public bool OverlapsWith(Ship ship) { uint xEnd = Direction == Direction.Vertical ? X : X + Length - 1; uint yEnd = Direction == Direction.Vertical ? Y + Length - 1 : Y; uint xOtherShipEnd = ship.Direction == Direction.Vertical ? ship.X : ship.X + ship.Length - 1; uint yOtherShipEnd = ship.Direction == Direction.Vertical ? ship.Y + ship.Length - 1 : ship.Y; return ((ship.X >= X - 1) && (ship.X <= xEnd + 1) && (ship.Y >= Y - 1) && (ship.Y <= yEnd + 1)) || ((xOtherShipEnd >= X - 1) && (xOtherShipEnd <= xEnd + 1) && (yOtherShipEnd >= Y - 1) && (yOtherShipEnd <= yEnd + 1)); }
protected virtual bool Equals(Ship other) { return ShipPosition.Equals(other.ShipPosition) && Length == other.Length; }
protected bool Equals(Ship other) { return this == other; }
public bool OverlapsWith(Ship otherShip) { bool result = false; for (int i = 0; i < Length; i++) { int x = (_direction == Direction.Horizontal) ? _x + i : _x; int y = (_direction == Direction.Vertiacal) ? _y + i : _y; for (int j = 0; j < otherShip.Length; j++) { int x2 = (otherShip._direction == Direction.Horizontal) ? otherShip._x + j : otherShip._x; int y2 = (otherShip._direction == Direction.Vertiacal) ? otherShip._y + j : otherShip._y; if (x == x2 && y == y2) result = true; } } int lx = (_direction == Direction.Horizontal) ? Length : 1; int ly = (_direction == Direction.Vertiacal) ? Length : 1; for (int i = _x - 1; i <= _x+lx; i++) { for (int j = _y - 1; j <= _y+ly; j++) { if ((otherShip._x == i) && (otherShip._y == j)) result = true; } } return result; }
protected bool Equals(Ship other) { return X == other.X && Y == other.Y && Direction == other.Direction; }
public bool OverlapsWith(Ship otherShip) { return (Math.Abs( (int) (EndX - otherShip.EndX)) <= 1) && (Math.Abs( (int) (EndY - otherShip.EndY)) <= 1); }