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); }
public void AddEdge(HexagonNode from, HexagonNode to, float resourceTravelDuration = 1) { var edge = new Edge(from, to, resourceTravelDuration); Edges.Add(edge); EdgeAdded?.Invoke(this, edge); }
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)); }
public float GetTimeForEdge(HexagonNode from, HexagonNode to) { foreach (var edge in Edges) { if (edge.Equals(from, to)) { return(edge.ResourceTravelDuration); } } return(1); }
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); }
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; }
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); } }
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; }
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()); }
public bool HasNodeInPath(HexagonNode node) { return(AllHops.Contains(node)); }
public void AddButton(Button button, HexagonNode hexagonNode) { Buttons.Add(hexagonNode, button); ButtonAdded?.Invoke(this, button); button.Position = hexagonNode.GetWorldPosition(LayoutSettings.HexagonRadius, LayoutSettings.HexagonMargin); }
public Button this[HexagonNode hexagonNode] => Buttons.ContainsKey(hexagonNode) ? Buttons[hexagonNode] : null;
public bool ContainsEdge(HexagonNode from, HexagonNode to) { return(Edges.Any(e => e.Equals(from, to))); }
public Structure GetStructureAtPosition(HexagonNode hexagonNode) => !Structures.ContainsKey(hexagonNode) ? null : Structures[hexagonNode];
public Structure this[HexagonNode hexagonNode] => GetStructureAtPosition(hexagonNode);
public bool Equals(HexagonNode other) { return(Position1.Equals(other.Position1) && Position2.Equals(other.Position2) && Position3.Equals(other.Position3)); }