Exemple #1
0
        public StarSystemConnection ConnectToClosest(List <StarSystem> starSystems)
        {
            float      distance    = int.MaxValue;
            StarSystem destination = null;

            foreach (StarSystem starSystem in starSystems)
            {
                if (this == starSystem)
                {
                    continue;
                }

                float calculatedDistance = this.DistanceTo(starSystem);
                ClosestSystems.Add(starSystem, calculatedDistance);

                if (this.IsIntersecting(starSystem, starSystems))
                {
                    continue;
                }

                if (calculatedDistance < distance)
                {
                    if (starSystem.IsConnectedTo(this))
                    {
                        continue;
                    }
                    else
                    {
                        distance    = calculatedDistance;
                        destination = starSystem;
                    }
                }
            }
            ClosestSystems = ClosestSystems.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
            return(destination != null ? new StarSystemConnection(this, destination) : null);
        }
 public bool IsIntersectableBy(StarSystem origin, StarSystem destination)
 {
     return(Utility.LineIntesection(this.StarSystems[0].Position, this.StarSystems[1].Position, origin.Position, destination.Position));
 }
 public bool IsConnecting(StarSystem system)
 {
     return(Array.IndexOf(StarSystems, system) >= 0);
 }
Exemple #4
0
 public float DistanceTo(StarSystem system)
 {
     return(Vector2.Distance(this.Position, system.Position));
 }
Exemple #5
0
        public bool IsConnectedTo(StarSystem system)
        {
            List <StarSystem> neighbours = this.GetConnectedNeighbours();

            return(neighbours?.Contains(system) == true ? true : false);
        }