Exemplo n.º 1
0
        private float CalculateHeuristik(HexagonNode node, HexagonNode destination)
        {
            var h1 = new[]
            {
                node.Position1,
                node.Position2,
                node.Position3
            };
            var h2 = new[]
            {
                destination.Position1,
                destination.Position2,
                destination.Position3
            };

            int min = int.MaxValue;

            foreach (var from in h1)
            {
                foreach (var to in h2)
                {
                    var distance = (to - from).DistanceToOrigin;
                    if (min > distance)
                    {
                        min = distance;
                    }
                }
            }
            return(min * GameplaySettings.DefaultResourceTimeBetweenNodes);
        }
Exemplo n.º 2
0
        public void AddEdge(HexagonNode from, HexagonNode to, float resourceTravelDuration = 1)
        {
            var edge = new Edge(from, to, resourceTravelDuration);

            Edges.Add(edge);
            EdgeAdded?.Invoke(this, edge);
        }
Exemplo n.º 3
0
 public HexagonNode GetElementAfter(HexagonNode nextNode)
 {
     for (int i = 0; i < AllHops.Count - 1; i++)
     {
         if (Equals(AllHops[i], nextNode))
         {
             return(AllHops[i + 1]);
         }
     }
     throw new ArgumentException("No element found/element is last entry", nameof(nextNode));
 }
Exemplo n.º 4
0
 public float GetTimeForEdge(HexagonNode from, HexagonNode to)
 {
     foreach (var edge in Edges)
     {
         if (edge.Equals(from, to))
         {
             return(edge.ResourceTravelDuration);
         }
     }
     return(1);
 }
Exemplo n.º 5
0
 public Path GetPath(HexagonNode start, HexagonNode destination)
 {
     if (PathCollection.ContainsKey(start) && PathCollection[start].ContainsKey(destination))
     {
         return(PathCollection[start][destination]);
     }
     if (PathCollection.ContainsKey(destination) && PathCollection[destination].ContainsKey(start))
     {
         return(PathCollection[destination][start].Reverse());
     }
     return(null);
 }
Exemplo n.º 6
0
        protected Structure(HexagonNode position, World world, BuildingDescription description)
        {
            World            = world;
            Description      = description;
            Position         = position;
            ResourceDirector = new ResourceDirector(this);
            var hex1 = World.HexagonManager[position.Position1];
            var hex2 = World.HexagonManager[position.Position2];
            var hex3 = World.HexagonManager[position.Position3];

            hex1.Payout += OnAdjacentHexagonProvidedResource;
            hex2.Payout += OnAdjacentHexagonProvidedResource;
            hex3.Payout += OnAdjacentHexagonProvidedResource;
        }
Exemplo n.º 7
0
        public IEnumerable <Hexagon> GetAdjacentHexagons(HexagonNode position)
        {
            var hexagon1 = GetHexagonAtPosition(position.Position1);
            var hexagon2 = GetHexagonAtPosition(position.Position2);
            var hexagon3 = GetHexagonAtPosition(position.Position3);

            if (hexagon1 != null)
            {
                yield return(hexagon1);
            }
            if (hexagon2 != null)
            {
                yield return(hexagon2);
            }
            if (hexagon3 != null)
            {
                yield return(hexagon3);
            }
        }
Exemplo n.º 8
0
 private Path(Path reversed, params HexagonNode[] nodes)
 {
     AllHops     = new ReadOnlyCollection <HexagonNode>(nodes);
     Start       = AllHops.First();
     Destination = AllHops.Last();
     if (nodes.Length < 2)
     {
         HopsInBetween = new ReadOnlyCollection <HexagonNode>(new HexagonNode[0]);
     }
     else
     {
         var hib = new HexagonNode[nodes.Length - 2];
         for (int i = 1; i < nodes.Length - 1; i++)
         {
             hib[i - 1] = nodes[i];
         }
         HopsInBetween = new ReadOnlyCollection <HexagonNode>(hib);
     }
     Reversed = reversed;
 }
Exemplo n.º 9
0
 public Path(params HexagonNode[] nodes)
 {
     AllHops     = new ReadOnlyCollection <HexagonNode>(nodes);
     Start       = AllHops.First();
     Destination = AllHops.Last();
     if (nodes.Length < 2)
     {
         HopsInBetween = new ReadOnlyCollection <HexagonNode>(new HexagonNode[0]);
     }
     else
     {
         var hib = new HexagonNode[nodes.Length - 2];
         for (int i = 1; i < nodes.Length - 1; i++)
         {
             hib[i - 1] = nodes[i];
         }
         HopsInBetween = new ReadOnlyCollection <HexagonNode>(hib);
     }
     Reversed = new Path(this, nodes.Reverse().ToArray());
 }
Exemplo n.º 10
0
 public bool HasNodeInPath(HexagonNode node)
 {
     return(AllHops.Contains(node));
 }
Exemplo n.º 11
0
 public void AddButton(Button button, HexagonNode hexagonNode)
 {
     Buttons.Add(hexagonNode, button);
     ButtonAdded?.Invoke(this, button);
     button.Position = hexagonNode.GetWorldPosition(LayoutSettings.HexagonRadius, LayoutSettings.HexagonMargin);
 }
Exemplo n.º 12
0
 public Button this[HexagonNode hexagonNode] => Buttons.ContainsKey(hexagonNode) ? Buttons[hexagonNode] : null;
Exemplo n.º 13
0
 public bool ContainsEdge(HexagonNode from, HexagonNode to)
 {
     return(Edges.Any(e => e.Equals(from, to)));
 }
Exemplo n.º 14
0
 public Structure GetStructureAtPosition(HexagonNode hexagonNode) => !Structures.ContainsKey(hexagonNode) ? null : Structures[hexagonNode];
Exemplo n.º 15
0
 public Structure this[HexagonNode hexagonNode] => GetStructureAtPosition(hexagonNode);
Exemplo n.º 16
0
 public bool Equals(HexagonNode other)
 {
     return(Position1.Equals(other.Position1) && Position2.Equals(other.Position2) && Position3.Equals(other.Position3));
 }