public PointDetail GetPoint(int x, int y) { if (x < MinX) { throw new Exception($"Cannot get point where {nameof(x)} is less than {nameof(MinX)} {MinX}"); } if (y < MinY) { throw new Exception($"Cannot get point where {nameof(y)} is less than {nameof(MinY)} {MinY}"); } if (x > MaxX) { throw new Exception($"Cannot get point where {nameof(x)} is greater than {nameof(MaxX)} {MaxX}"); } if (y > MaxY) { throw new Exception($"Cannot get point where {nameof(y)} is greater than {nameof(MaxY)} {MaxY}"); } var point = new PointDetail(x, y); // find all the path intersections foreach (var path in Paths) { var intersect = point.GetPathIntersect(path); if (intersect != null) { point.AddPathIntersect(intersect); } } // find all background intersections point.AddBackgroundItem(BackgroundItems.Where(i => i.TopLeftX <= x && (i.TopLeftX + i.Width - 1) >= x && i.TopLeftY <= y && (i.TopLeftY + i.Height - 1) >= y)); // find all points of interest point.AddPointOfInterest(PointOfInterests.Where(i => i.X == x && i.Y == y)); // is this point shrouded? point.IsShrouded = ShroudActive && !ShroudRevealedPoints.Contains(point); return(point); }
public Junction(PointDetail pointDetail) { Guard.NotNull(pointDetail, nameof(pointDetail)); _pointDetail = pointDetail; if (_pointDetail.PathIntersects.Count != 2) { throw new Exception($"A junction can only be created on a point which has 2 path intersections, but the point {_pointDetail} has {_pointDetail.PathIntersects.Count}"); } var details = GetJunctionDetails(); Type = details.Item1; FromDirection = details.Item2; }
public Point Move(Directions direction) { if (CanMove(direction)) { var newPoint = Map.GetRelativePoint(_currentPointDetail, direction); _currentPointDetail = newPoint; LastMoveDateTime = DateTime.Now; MovesMade++; return(_currentPointDetail); } else { throw new Exception($"Cannot move player in direction {direction}"); } }
public PointDetail GetRelativePoint(PointDetail pointDetail, Directions direction, int positions = 1) { switch (direction) { case Directions.North: return(GetPoint(pointDetail.X, pointDetail.Y - positions)); case Directions.South: return(GetPoint(pointDetail.X, pointDetail.Y + positions)); case Directions.West: return(GetPoint(pointDetail.X - positions, pointDetail.Y)); case Directions.East: return(GetPoint(pointDetail.X + positions, pointDetail.Y)); } throw new Exception($"Unknown direction {direction}"); }
public void AddToMap(Map map, PointDetail pointDetail) { Map = map; _currentPointDetail = pointDetail; }