public System.Collections.Generic.IEnumerable <MapPoint> GetAdjacentCells(Func <short, bool> predicate) { MapPoint mapPoint = new MapPoint(this.m_x + 1, this.m_y); if (MapPoint.IsInMap(mapPoint.X, mapPoint.Y) && predicate(mapPoint.CellId)) { yield return(mapPoint); } MapPoint mapPoint2 = new MapPoint(this.m_x, this.m_y - 1); if (MapPoint.IsInMap(mapPoint2.X, mapPoint2.Y) && predicate(mapPoint2.CellId)) { yield return(mapPoint2); } MapPoint mapPoint3 = new MapPoint(this.m_x, this.m_y + 1); if (MapPoint.IsInMap(mapPoint3.X, mapPoint3.Y) && predicate(mapPoint3.CellId)) { yield return(mapPoint3); } MapPoint mapPoint4 = new MapPoint(this.m_x - 1, this.m_y); if (MapPoint.IsInMap(mapPoint4.X, mapPoint4.Y) && predicate(mapPoint4.CellId)) { yield return(mapPoint4); } yield break; }
public static void AddCellIfValid(int x, int y, MapRecord map, IList <short> container) { if (MapPoint.IsInMap(x, y)) { container.Add((short)MapPoint.CoordToCellId(x, y)); } }
public MapPoint GetCellInDirection(DirectionsEnum direction, short step) { MapPoint mapPoint = null; switch (direction) { case DirectionsEnum.DIRECTION_EAST: mapPoint = MapPoint.GetPoint(this.m_x + (int)step, this.m_y + (int)step); break; case DirectionsEnum.DIRECTION_SOUTH_EAST: mapPoint = MapPoint.GetPoint(this.m_x + (int)step, this.m_y); break; case DirectionsEnum.DIRECTION_SOUTH: mapPoint = MapPoint.GetPoint(this.m_x + (int)step, this.m_y - (int)step); break; case DirectionsEnum.DIRECTION_SOUTH_WEST: mapPoint = MapPoint.GetPoint(this.m_x, this.m_y - (int)step); break; case DirectionsEnum.DIRECTION_WEST: mapPoint = MapPoint.GetPoint(this.m_x - (int)step, this.m_y - (int)step); break; case DirectionsEnum.DIRECTION_NORTH_WEST: mapPoint = MapPoint.GetPoint(this.m_x - (int)step, this.m_y); break; case DirectionsEnum.DIRECTION_NORTH: mapPoint = MapPoint.GetPoint(this.m_x - (int)step, this.m_y + (int)step); break; case DirectionsEnum.DIRECTION_NORTH_EAST: mapPoint = MapPoint.GetPoint(this.m_x, this.m_y + (int)step); break; } MapPoint result; if (mapPoint != null) { if (MapPoint.IsInMap(mapPoint.X, mapPoint.Y)) { result = mapPoint; } else { result = null; } } else { result = null; } return(result); }