コード例 #1
0
ファイル: PathFinder.cs プロジェクト: EikeStein/HexMex
        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);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: Path.cs プロジェクト: EikeStein/HexMex
 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));
 }
コード例 #4
0
 public float GetTimeForEdge(HexagonNode from, HexagonNode to)
 {
     foreach (var edge in Edges)
     {
         if (edge.Equals(from, to))
         {
             return(edge.ResourceTravelDuration);
         }
     }
     return(1);
 }
コード例 #5
0
ファイル: PathFinder.cs プロジェクト: EikeStein/HexMex
 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);
 }
コード例 #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;
        }
コード例 #7
0
ファイル: HexagonManager.cs プロジェクト: EikeStein/HexMex
        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);
            }
        }
コード例 #8
0
ファイル: Path.cs プロジェクト: EikeStein/HexMex
 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;
 }
コード例 #9
0
ファイル: Path.cs プロジェクト: EikeStein/HexMex
 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());
 }
コード例 #10
0
ファイル: Path.cs プロジェクト: EikeStein/HexMex
 public bool HasNodeInPath(HexagonNode node)
 {
     return(AllHops.Contains(node));
 }
コード例 #11
0
ファイル: ButtonManager.cs プロジェクト: EikeStein/HexMex
 public void AddButton(Button button, HexagonNode hexagonNode)
 {
     Buttons.Add(hexagonNode, button);
     ButtonAdded?.Invoke(this, button);
     button.Position = hexagonNode.GetWorldPosition(LayoutSettings.HexagonRadius, LayoutSettings.HexagonMargin);
 }
コード例 #12
0
ファイル: ButtonManager.cs プロジェクト: EikeStein/HexMex
 public Button this[HexagonNode hexagonNode] => Buttons.ContainsKey(hexagonNode) ? Buttons[hexagonNode] : null;
コード例 #13
0
 public bool ContainsEdge(HexagonNode from, HexagonNode to)
 {
     return(Edges.Any(e => e.Equals(from, to)));
 }
コード例 #14
0
 public Structure GetStructureAtPosition(HexagonNode hexagonNode) => !Structures.ContainsKey(hexagonNode) ? null : Structures[hexagonNode];
コード例 #15
0
 public Structure this[HexagonNode hexagonNode] => GetStructureAtPosition(hexagonNode);
コード例 #16
0
ファイル: HexagonNode.cs プロジェクト: EikeStein/HexMex
 public bool Equals(HexagonNode other)
 {
     return(Position1.Equals(other.Position1) && Position2.Equals(other.Position2) && Position3.Equals(other.Position3));
 }