public static Direction ToDirection(this Bomberman.Api.Point for_, Bomberman.Api.Point to, params Bomberman.Api.Element[] preset) { if (to.IsElementAs(preset)) { return(for_.ToDirection(to)); } return(Direction.Stop); }
public static IEnumerable <Bomberman.Api.Point> GetNear(this Bomberman.Api.Point point, params Bomberman.Api.Element[] preset) { foreach (var near in point.GetNear()) { if (near.IsElementAs(preset)) { yield return(near); } } }
// лево, верх, право, низ public static IEnumerable <Bomberman.Api.Point> GetNear(this Bomberman.Api.Point point) { yield return(point.ShiftLeft()); yield return(point.ShiftTop()); yield return(point.ShiftRight()); yield return(point.ShiftBottom()); }
public static Direction ToDirectionOrStop(this Bomberman.Api.Point for_, Bomberman.Api.Point to) { if (for_ == to) { return(Direction.Stop); } else { return(for_.ToDirection(to)); } }
// Не проверено public static IEnumerable <Bomberman.Api.Point> GetNearOfRadius(this Bomberman.Api.Point point, int radius, bool isKrest, params Bomberman.Api.Element[] preset) { for (var i = point.Y - radius; i < point.Y + radius; i++) { var endJ = 2 * radius - Math.Abs(point.X - i); for (var j = Math.Abs(point.X - i); j < endJ; j++) { yield return(new Bomberman.Api.Point(j, i)); } } }
public static Bomberman.Api.Point Shift(this Bomberman.Api.Point point, Direction direction, int delta = 1) { switch (direction) { case Direction.Left: return(point.ShiftLeft(delta)); case Direction.Up: return(point.ShiftTop(delta)); case Direction.Right: return(point.ShiftRight(delta)); case Direction.Down: return(point.ShiftBottom(delta)); } throw new ArgumentException("Передано неверное направление"); }
// Можно прямо здесь зашить невозможность создать направление в стенку. public static Direction ToDirection(this Bomberman.Api.Point for_, Bomberman.Api.Point to) { if (for_.ShiftLeft() == to) { return(Direction.Left); } if (for_.ShiftTop() == to) { return(Direction.Up); } if (for_.ShiftRight() == to) { return(Direction.Right); } if (for_.ShiftBottom() == to) { return(Direction.Down); } return(Direction.Stop); }
public static bool IsElementAs(this Bomberman.Api.Point point, params Bomberman.Api.Element[] preset) => preset.Contains(point.ToElement());