BattleshipUtility.Ship.AdjacentPositions C# (CSharp) Méthode

AdjacentPositions() public méthode

List of positions adjacent to a ship
public AdjacentPositions ( int width, int height ) : IEnumerable
width int
height int
Résultat IEnumerable
        public IEnumerable<Position> AdjacentPositions(int width, int height)
        {
            if (Orientation == Orientation.Vertical)
            {
                if (Position.Row > 0)
                    yield return new Position(Position.Row - 1, Position.Column);
                if (Position.Row + Size < height)
                    yield return new Position(Position.Row + 1, Position.Column);
                for (var i = 0; i < Size; ++i)
                {
                    if (Position.Column > 0)
                        yield return new Position(Position.Row, Position.Column - 1);
                    if (Position.Column + Size < width)
                        yield return new Position(Position.Row, Position.Column + 1);
                }
            }
            else
            {
                if (Position.Column > 0)
                    yield return new Position(Position.Row, Position.Column - 1);
                if (Position.Column + Size < width)
                    yield return new Position(Position.Row, Position.Column + 1);
                for (var i = 0; i < Size; ++i)
                {
                    if (Position.Row > 0)
                        yield return new Position(Position.Row - 1, Position.Column);
                    if (Position.Row + Size < height)
                        yield return new Position(Position.Row + 1, Position.Column);
                }
            }
        }