Exemplo n.º 1
0
        private IEnumerable<ILocation> buildAdjacentLocations(ILocation parent)
        {
            ILocation[] results = new ILocation[8];

            Point[] coordinates = new Point[8];
            namDirections[] directionArray = new namDirections[8];
            int adjustedSize = this.Rect.Width;   // size is distance from center to edge,
            // double to ensure we end up outside of this box

            directionArray[(int)namDirections.East] = namDirections.East;
            directionArray[(int)namDirections.North] = namDirections.North;
            directionArray[(int)namDirections.NorthEast] = namDirections.NorthEast;
            directionArray[(int)namDirections.NorthWest] = namDirections.NorthWest;
            directionArray[(int)namDirections.South] = namDirections.South;
            directionArray[(int)namDirections.SouthEast] = namDirections.SouthEast;
            directionArray[(int)namDirections.SouthWest] = namDirections.SouthWest;
            directionArray[(int)namDirections.West] = namDirections.West;

            coordinates[(int)namDirections.East] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y);
            coordinates[(int)namDirections.North] = new Point(this.Rect.Center.X, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.NorthEast] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.NorthWest] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.South] = new Point(this.Rect.Center.X, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.SouthEast] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.SouthWest] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.West] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y);

            foreach (namDirections d in directionArray)
            {
                if (IsKnown)
                {
                    results[(byte)d] = Parent.GetLocation(coordinates[(int)d]);
                }
                else
                {
                    Point center = coordinates[(int)d];

                    results[(byte)d] = new Location(this,
                        new Rectangle(center.X, center.Y,
                            this.Rect.Width, this.Rect.Height));
                }
            }

            return results;
        }
Exemplo n.º 2
0
 public ILocation GetLocation(namDirections direction)
 {
     return this.AdjacentLocations.ElementAt((int)direction);
 }