// Update adjacency private void UpdateAdjacency(GameObject vertex1, GameObject vertex2) { HexEntity vertexEnt1 = vertex1.GetComponent<HexEntity>(); HexEntity vertexEnt2 = vertex2.GetComponent<HexEntity>(); if (vertexEnt1.Adjacent(vertexEnt2)) { if (!adjacencyMap.ContainsKey(vertex1)) adjacencyMap[vertex1] = new List<GameObject>(); if (!adjacencyMap.ContainsKey(vertex2)) adjacencyMap[vertex2] = new List<GameObject>(); adjacencyMap[vertex1].Add(vertex2); adjacencyMap[vertex2].Add(vertex1); } }
public bool IsConnected() { if (hexEntities.Count < 2) { return(false); } for (int i = 1; i < hexEntities.Count; i++) { HexEntity last = hexEntities[i - 1].GetComponent <HexEntity>(); HexEntity next = hexEntities[i].GetComponent <HexEntity>(); if (!last.Adjacent(next)) { return(false); } } return(true); }
/// <summary> /// Moves this army to another tile. /// </summary> /// <param name="targetTile"></param> public void Move(GameObject targetTile) { // Add logic to check what the other is, and attempt to create a path to that location. HexEntity TargetHex = targetTile.GetComponent <HexEntity>(); // Verify the action should be taken. // Did you know C# thinks & has higher priority then | ? Rediculous! if (TargetHex == null || hasMoved) { // Do nothing. } else { // checks to see if the tile can be moved to. HexEntity myHex = Global.MapFlyWeight.hexMap[Position].GetComponent <HexEntity>(); if (TargetHex.Adjacent(myHex)) { Vector3Int direction = TargetHex.Position - myHex.Position; MoveAction(direction); hasMoved = true; } } }