BattleshipUtility.Ship.AtOrAdjacent C# (CSharp) Method

AtOrAdjacent() public method

Creates a 1-space border around a ship and checks if a position is within this border
public AtOrAdjacent ( Position p ) : bool
p Position Position to check
return bool
        public bool AtOrAdjacent(Position p)
        {
            if (Orientation == Orientation.Horizontal)
            {
                return ((Math.Abs(Position.Row - p.Row) < 2) && (Position.Column <= p.Column) && (Position.Column + Size > p.Column))
                    || ((Position.Row == p.Row) && (Position.Column <= p.Column + 1) && (Position.Column + Size >= p.Column));
            }
            else
            {
                return ((Math.Abs(Position.Column - p.Column) < 2) && (Position.Row <= p.Row) && (Position.Row + Size > p.Row))
                    || ((Position.Column == p.Column) && (Position.Row <= p.Row + 1) && (Position.Row + Size >= p.Row));
            }
        }