Beispiel #1
0
    public static NodeBehavior MakeMove()
    {
        boardBehavior.Wait();
        bool valid = false;

        while (!valid)
        {
            int          x    = Random.Range(0, boardBehavior.boardManager.boardSize);
            int          y    = Random.Range(0, boardBehavior.boardManager.boardSize);
            NodeBehavior node = boardBehavior.NodeBehaviors[x, y].GetComponent <NodeBehavior>();
            if (boardManager.IsValidPlacement(PlayerTurn.WHITE_PLAYER2, 4, node.node, eColor.WHITE))
            {
                valid      = true;
                node.Color = eColor.W_HOVER;
            }
        }
        return(null);
    }
    }                 // close function

    /******* CASE A *******/

    void AddNode(string pathSubstring, string[] singleFilePathArray, int directoryLevel)
    {
        // create node if it doesn't exist
        if (NodeUtility.StringExistsAsNode(pathSubstring, parent) == false)
        {
            GameObject currentNode;
            bool       isLeaf;

            if (directoryLevel == singleFilePathArray.Length - 1)
            {
                isLeaf      = true;
                currentNode = (GameObject)Instantiate(NodeLeafPrefab, new Vector3(0, 0, 0), Quaternion.identity);
            }
            else
            {
                isLeaf      = false;
                currentNode = (GameObject)Instantiate(NodeDirPrefab, new Vector3(0, 0, 0), Quaternion.identity);
            }
            currentNode = NodeUtility.PlaceNodeInScene(currentNode, parent);

            // accesses parent & adds a reference of the new node as being a child of parent & returns nodeBehavior
            NodeBehavior nodeToAddBehavior = setNodeAsChildOfParent(currentNode, pathSubstring);

            // filepath has a leaf node at the end i.e. when we're at the end of singleFilePathArray
            nodeToAddBehavior.leaf = isLeaf;

            if (!isLeaf)
            {
                parent         = currentNode;
                parentBehavior = currentNode.GetComponent <NodeBehavior>();
            }
            SetNodeText(currentNode, pathSubstring);
        }         // close if


        // else the node with substring exists and continue traversal
        else
        {
            parent         = NodeUtility.GetNodeWithGivenPath(pathSubstring, parent);     // get node GameObject
            parentBehavior = parent.GetComponent <NodeBehavior>();
        }
    }
Beispiel #3
0
    private void CreateNodeBehaviors(int size, bool isLoad = false)
    {
        //float nodeSize = ((float)boardSize - 9) / 30;
        //nodeSize = Mathf.Lerp(0.75f, 0.15f, nodeSize);
        if (!isLoad)
        {
            NodeBehaviors = new GameObject[boardSize, boardSize];
            boardManager.Init(boardSize);
        }
        float curx, cury;

        curx = 0 - (boardSize / 2 * distanceBetween);
        cury = 0 + (boardSize / 2 * distanceBetween);
        for (int x = 0; x < boardSize; x++)
        {
            for (int y = 0; y < boardSize; y++)
            {
                GameObject node = null;
                if (isLoad)
                {
                    node = NodeBehaviors[x, y];
                }
                else
                {
                    node = Instantiate(NodeBehaviorTemplate);
                }
                NodeBehavior n = node.GetComponent <NodeBehavior>();
                n.node   = boardManager.nodes[x, y];
                n.node.x = x;
                n.node.y = y;
                if (isLoad)
                {
                    n.Color = boardManager.nodes[x, y].color;
                }
                NodeBehaviors[x, y]     = node;
                node.transform.position = new Vector3(curx, cury, 0.0f);
                cury -= distanceBetween;
            }
            curx += distanceBetween;
            cury  = 0 + (boardSize / 2 * distanceBetween);
        }
    }
    public void OnNodeActivated(NodeBehavior node)
    {
        if (node.id == current_node)
        {
            node.activated             = true;
            node.spriteRenderer.sprite = node.sprite_on;
            node.GetComponent <AudioSource>().Play();
            node.gameObject.transform.Find("Particle System").gameObject.SetActive(false);
            current_node++;

            if (current_node == node_num)
            {
                gameObject.GetComponent <GameController>().LevelComplete();
            }
            else
            {
                TurnOnNextNode();
            }
        }
    }
    public NodeBehavior CreateNodeAtCoordinates(Vector2 location, Vector2 size, Faction owner, NodeType nodeType, List <Vector2Int> typeChangeList)
    {
        if (!surroundedNodes.ContainsKey(Faction.Blue))
        {
            SetupDictionary();
        }

        GameObject newNode = Instantiate(nodeTemplate, map.transform);

        newNode.GetComponent <RectTransform>().anchoredPosition = location;

        NodeBehavior behavior = newNode.GetComponent <NodeBehavior>();

        behavior.SetNodeManager(this);
        behavior.SetNodeEditor(editor);
        behavior.SetGameStateManager(gameStateManager);
        behavior.SetPlanner(planner);

        EventTrigger.Entry DragEntry = new EventTrigger.Entry();
        DragEntry.eventID = EventTriggerType.Drag;
        DragEntry.callback.AddListener(delegate { editor.MoveNode(); });
        newNode.GetComponent <EventTrigger>().triggers.Add(DragEntry);

        EventTrigger.Entry ClickEntry = new EventTrigger.Entry();
        ClickEntry.eventID = EventTriggerType.PointerDown;
        ClickEntry.callback.AddListener(delegate { behavior.SelectNode(); });
        newNode.GetComponent <EventTrigger>().triggers.Add(ClickEntry);

        newNode.GetComponent <RectTransform>().sizeDelta = size;
        behavior.SetOwner(owner);
        behavior.SetNodeType(nodeType);

        foreach (Vector2Int entry in typeChangeList)
        {
            behavior.AddTypeChangeOnTurn(entry.x, (NodeType)entry.y);
        }

        nodes.Add(newNode);

        return(behavior);
    }
Beispiel #6
0
    //a function that will recursivly add up the distance that the dino has until getting to the finish line
    private float AddUpDistance(NodeBehavior _previousNode, NodeBehavior _nextNode /*,int _index*/, float _dist)
    {
        NodeBehavior prevNodeScript = _previousNode.GetComponent <NodeBehavior>();
        NodeBehavior nextNodeScript = _nextNode.GetComponent <NodeBehavior>();

        //Debug.Log("previous node " + _previousNode);
        //Debug.Log("next node " + _nextNode);

        float tempNum = _dist + Vector3.Distance(_nextNode.gameObject.transform.position, _previousNode.gameObject.transform.position);

        //Debug.Log(nextNodeScript.isFinishLine == true);
        //Debug.Log(prevNodeScript == lastNode.GetComponent<NodeBehavior>());

        if (nextNodeScript.isFinishLine == true && prevNodeScript == lastNode.GetComponent <NodeBehavior>())
        {
            return(_dist + tempNum);
        }

        int i = 0;

        foreach (GameObject n in _nextNode.previousNodes)
        {
            //Debug.Log("looking for next node");

            if (n.GetComponent <NodeBehavior>() == _previousNode)
            {
                //Debug.Log(n + " matches with " + _previousNode);

                //Debug.Log(nodeScript.NextNodes[i].name + " is the new next node");

                //Debug.Log("tempNum " + tempNum);

                return(AddUpDistance(_nextNode, _nextNode.NextNodes[i].GetComponent <NodeBehavior>() /*, _index*/, tempNum));
            }

            i++;
        }

        return(_dist);
    }
Beispiel #7
0
    public void SpawnEnemiesAtHelis(List <GameObject> nodes, Faction faction)
    {
        foreach (GameObject nodeObject in nodes)
        {
            NodeBehavior node = nodeObject.GetComponent <NodeBehavior>();
            if (GetEchelonAtNode(node) == null)
            {
                if (node.GetOwner() == faction)
                {
                    if (node.GetNodeType() == NodeType.Helipad || node.GetNodeType() == NodeType.HeavyHelipad)
                    {
                        GameObject newEchelon = Instantiate(enemySpawn, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                        if (faction == Faction.Red)
                        {
                            newEchelon.GetComponent <Image>().sprite = redSpawnPreview.GetComponentsInChildren <Image>()[1].sprite;
                        }
                        else if (faction == Faction.Yellow)
                        {
                            newEchelon.GetComponent <Image>().sprite = yellowSpawnPreview.GetComponentsInChildren <Image>()[1].sprite;
                        }

                        EchelonBehavior behavior = newEchelon.GetComponent <EchelonBehavior>();
                        enemies.Add(behavior);

                        behavior.SetFaction(faction);
                        behavior.SetNode(node);
                        allEchelons.Add(behavior);

                        newEchelon.transform.localScale = new Vector3(node.GetComponent <RectTransform>().rect.width / 200, node.GetComponent <RectTransform>().rect.height / 200, 1);

                        EventTrigger.Entry ClickEntry = new EventTrigger.Entry();
                        ClickEntry.eventID = EventTriggerType.PointerClick;
                        ClickEntry.callback.AddListener(delegate { SelectEchelon(behavior); });
                        newEchelon.GetComponent <EventTrigger>().triggers.Add(ClickEntry);
                    }
                }
            }
        }
    }
    /******* CASE D *******/

    void DeleteNode(string pathSubstring, int directoryLevel)
    {
        GameObject   nodeToDelete         = NodeUtility.GetNodeWithGivenPath(pathSubstring, parent);
        NodeBehavior nodeToDeleteBehavior = nodeToDelete.GetComponent <NodeBehavior>();

        if (nodeToDeleteBehavior.leaf)
        {
            // myKids is read-only so put it into a usable variable
            int parentKidsCount = parent.GetComponent <NodeBehavior>().myKids.Count;

            // this doesn't decrement the parentBehavior's myKids.Count so using parentKidsCount...
            NodeUtility.RemoveNode(nodeToDelete, this);

            // using parentKidsCount to check if a parent directory will be empty after node deletions
            parentKidsCount--;

            // git doesn't allow empty directories - it considers them implicitly deleted
            if (parentKidsCount < 1)
            {
                NodeUtility.RemoveNode(parent, this);
            }
        }
        parent = nodeToDelete;
    }
    public int GetAPFromNodes()
    {
        int APFromNodes = 0;

        foreach (GameObject gameObject in nodes)
        {
            NodeBehavior node = gameObject.GetComponent <NodeBehavior>();
            switch (node.GetNodeType())
            {
            case NodeType.HQ:
            case NodeType.Helipad:
            case NodeType.HeavyHelipad:
            case NodeType.ClosedHeli:
            case NodeType.ClosedHeavyHeli:
                if (node.GetOwner() == Faction.Blue)
                {
                    APFromNodes++;
                }
                break;
            }
        }

        return(APFromNodes);
    }
Beispiel #10
0
    public bool MoveEcheToNode(NodeBehavior node)
    {
        if (selectedEchelon != null)
        {
            if (selectedEchelon.GetNode().GetConnectedNodes().Contains(node))
            {
                EchelonBehavior blockingEchelon = GetEchelonAtNode(node);
                if (blockingEchelon == null)
                {
                    if ((selectedEchelon.GetFaction() == Faction.Blue && planner.GetAP() > 0) || NPCs.Contains(selectedEchelon) || selectedEchelon.GetFaction() != Faction.Blue)
                    {
                        selectedEchelon.SetNode(node);
                        selectedEchelon.gameObject.transform.position = node.gameObject.transform.position;

                        if (selectedEchelon.GetFaction() == Faction.Blue && !NPCs.Contains(selectedEchelon))
                        {
                            planner.AdjustAP(-1);
                        }

                        DeselectEchelon();
                        return(true);
                    }
                }
                else
                {
                    if (blockingEchelon.GetFaction() != selectedEchelon.GetFaction())
                    {
                        if (selectedEchelon as HOCBehavior == null)
                        {
                            if ((selectedEchelon.GetFaction() == Faction.Blue && planner.GetAP() > 0) ||
                                NPCs.Contains(selectedEchelon) || selectedEchelon.GetFaction() != Faction.Blue)
                            {
                                if (selectedEchelon.GetFaction() == Faction.Blue && !NPCs.Contains(selectedEchelon))
                                {
                                    if (selectedEchelon.GetSupply().x > 0 && selectedEchelon.GetSupply().y > 0)
                                    {
                                        UseCombatSupply(selectedEchelon);
                                        planner.AdjustAP(-1);
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }

                                if (blockingEchelon as HOCBehavior != null ||
                                    ((regularEchelons.Contains(blockingEchelon) || blockingEchelon as ParachuteBehavior != null) &&
                                     (blockingEchelon.GetSupply().x == 0 || blockingEchelon.GetSupply().y == 0)))
                                {
                                    selectedEchelon.SetNode(node);
                                    selectedEchelon.gameObject.transform.position = node.gameObject.transform.position;
                                    RemoveEchelon(blockingEchelon);
                                }
                                else
                                {
                                    if (blockingEchelon.GetFaction() == Faction.Blue || selectedEchelon.GetFaction() == Faction.Blue)
                                    {
                                        foreach (HOCBehavior HOC in HOCs)
                                        {
                                            if (HOC.IsNodeInRange(blockingEchelon.GetNode()))
                                            {
                                                HOC.UseSupply(new Vector2Int(1, 2));
                                            }
                                        }
                                    }

                                    StartCoroutine(DetermineCombat(blockingEchelon));
                                }
                                return(true);
                            }
                        }
                    }
                    else if (selectedEchelon.GetFaction() == Faction.Blue)
                    {
                        blockingEchelon.SetNode(selectedEchelon.GetNode());
                        blockingEchelon.gameObject.transform.position = selectedEchelon.GetNode().gameObject.transform.position;
                        selectedEchelon.SetNode(node);
                        selectedEchelon.gameObject.transform.position = node.gameObject.transform.position;

                        DeselectEchelon();
                        return(true);
                    }
                }
            }
            else if (selectedEchelon as ParachuteBehavior != null)
            {
                ParachuteBehavior para = selectedEchelon as ParachuteBehavior;
                if (para.GetCooldown() == 0)
                {
                    if (GetEchelonAtNode(node) == null && (node.GetNodeType() == NodeType.Helipad || node.GetNodeType() == NodeType.HeavyHelipad ||
                                                           node.GetNodeType() == NodeType.ClosedHeli || node.GetNodeType() == NodeType.ClosedHeavyHeli))
                    {
                        para.UsePara();
                        selectedEchelon.SetNode(node);
                        selectedEchelon.gameObject.transform.position = node.gameObject.transform.position;

                        DeselectEchelon();
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Beispiel #11
0
 public void Commit(NodeBehavior behavior)
 {
     fieldInfo.SetValue(behavior, editorField.value);
 }
Beispiel #12
0
 public void Restore(NodeBehavior behavior)
 {
     editorField.value = (K)fieldInfo.GetValue(behavior);
 }
Beispiel #13
0
    public void CheckBoard(NodeBehavior last)
    {
        TurnManager turnManager = TurnManager.Instance;

        if (boardManager.WonGame(last.node))
        {
            print(last.Color + " WON!");
            eyeCandy.Notify(last.transform.position, last.Color + " WON!", 60, 1, Vector2.up * 1, winColor);
            SceneManager.LoadScene("UIProto");
            return;
        }
        List <Node> captures = boardManager.FindCaptures(last.node);

        if (captures.Count > 0)
        {
            eyeCandy.Notify(last.transform.position, "Capture!", 30, 1, Vector2.up * 2, captureColor);
        }
        foreach (Node capture in captures)
        {
            capture.color = eColor.EMPTY;
            switch (turnManager.playerTurn)
            {
            case PlayerTurn.BLACK_PLAYER1:
                turnManager.p1.captureCount++;
                break;

            case PlayerTurn.WHITE_PLAYER2:
                turnManager.p2.captureCount++;
                break;
            }
        }
        switch (turnManager.playerTurn)
        {
        case PlayerTurn.BLACK_PLAYER1:
            if (turnManager.p1.captureCount >= 10)
            {
                eyeCandy.Notify(last.transform.position, last.Color + " WON!", 60, 1, Vector2.up * 1, winColor);
                SceneManager.LoadScene("UIProto");
            }
            break;

        case PlayerTurn.WHITE_PLAYER2:
            if (turnManager.p2.captureCount >= 10)
            {
                eyeCandy.Notify(last.transform.position, last.Color + " WON!", 60, 1, Vector2.up * 1, winColor);
                SceneManager.LoadScene("UIProto");
            }
            break;
        }
        if (boardManager.TesseraCreated(last.node))
        {
            print("TESSERA!");
            eyeCandy.Notify(last.transform.position, "Tessera!", 40, 2, Vector2.up * 3, tesseraColor);
        }
        else if (boardManager.TriaCreated(last.node))
        {
            print("TRIA!");
            eyeCandy.Notify(last.transform.position, "Tria!", 30, 1, Vector2.up * 2, triaColor);
        }

        for (int i = 0; i < boardSize; ++i)
        {
            for (int j = 0; j < boardSize; ++j)
            {
                NodeBehaviors[i, j].GetComponent <NodeBehavior>().UpdateNode();
            }
        }
    }
Beispiel #14
0
 public EdgePair(NodeBehavior nodeBehavior, Port parentOutputPort)
 {
     NodeBehavior     = nodeBehavior;
     ParentOutputPort = parentOutputPort;
 }
 public void MarkNodeForSurround(NodeBehavior node, Faction surroundingFaction)
 {
     surroundedNodes[surroundingFaction].Add(node);
 }
Beispiel #16
0
    public void AddEchelon(EchelonType type, NodeBehavior node)
    {
        bool valid = false;

        if (type == EchelonType.Enemy || type == EchelonType.NPC)
        {
            valid = true;
        }
        else if (node.GetOwner() == Faction.Blue)
        {
            if (node.GetNodeType() == NodeType.HeavyHelipad)
            {
                valid = true;
            }
            else if (type != EchelonType.HOC)
            {
                if (node.GetNodeType() == NodeType.HQ || node.GetNodeType() == NodeType.Helipad)
                {
                    valid = true;
                }
            }
        }

        if (valid)
        {
            GameObject newEchelon = null;
            switch (type)
            {
            case EchelonType.RegularGriffin:
                newEchelon = Instantiate(regularEcheTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                regularEchelons.Add(newEchelon.GetComponent <EchelonBehavior>());
                planner.AddEchelon();
                makingHOC = false;
                StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>()));
                break;

            case EchelonType.Parachute:
                newEchelon = Instantiate(parachuteTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                parachuteEchelons.Add(newEchelon.GetComponent <ParachuteBehavior>());
                planner.AddEchelon();
                makingHOC = false;
                StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>()));
                break;

            case EchelonType.HOC:
                newEchelon = Instantiate(HOCTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                HOCs.Add(newEchelon.GetComponent <HOCBehavior>());
                planner.AddHOC();
                makingHOC = true;
                StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>()));
                break;

            case EchelonType.NPC:
                newEchelon = Instantiate(NPCTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                NPCs.Add(newEchelon.GetComponent <EchelonBehavior>());
                break;

            case EchelonType.Enemy:
                newEchelon = Instantiate(regularEnemyTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform);
                enemies.Add(newEchelon.GetComponent <EchelonBehavior>());
                StartCoroutine(InputEnemyAttributes(newEchelon.GetComponent <EchelonBehavior>()));
                break;
            }
            EchelonBehavior behavior = newEchelon.GetComponent <EchelonBehavior>();
            behavior.SetNode(node);
            allEchelons.Add(behavior);

            if (type == EchelonType.RegularGriffin || type == EchelonType.Parachute)
            {
                if (retreatedEchelons.Count > 0)
                {
                    behavior.SetID(retreatedEchelons.Dequeue());
                }
                else
                {
                    behavior.SetID(regularEchelons.Count + parachuteEchelons.Count);
                }
            }
            else if (type == EchelonType.HOC)
            {
                if (retreatedHOCs.Count > 0)
                {
                    behavior.SetID(retreatedHOCs.Dequeue());
                }
                else
                {
                    behavior.SetID(HOCs.Count);
                }
            }

            if (gameStateManager.factionMoving == FactionTurn.Blue)
            {
                if (behavior.GetFaction() == Faction.Blue)
                {
                    if (type != EchelonType.NPC)
                    {
                        planner.AdjustAP(-1);
                    }
                }
            }

            newEchelon.transform.localScale = new Vector3(node.GetComponent <RectTransform>().rect.width / 200, node.GetComponent <RectTransform>().rect.height / 200, 1);

            EventTrigger.Entry ClickEntry = new EventTrigger.Entry();
            ClickEntry.eventID = EventTriggerType.PointerClick;
            ClickEntry.callback.AddListener(delegate { SelectEchelon(behavior); });
            newEchelon.GetComponent <EventTrigger>().triggers.Add(ClickEntry);
        }
    }
Beispiel #17
0
    private void UpdateSpecificDino(GameObject _node, int _index)
    {
        NodeBehavior nodeScript = _node.GetComponent <NodeBehavior>();

        if (currentNodes[_index] != null)
        {
            //if the player runs into the start node while currently on the last node
            if (nodeScript.isFinishLine == true && currentNodes[_index] == lastNode.GetComponent <NodeBehavior>())
            {
                int lapTest = 0;

                //increase the lap count
                lapCount[_index]++;

                //set the current node to the start node
                currentNodes[_index] = startNode.GetComponent <NodeBehavior>();
                nextNodes[_index]    = currentNodes[_index].NextNodes[0].GetComponent <NodeBehavior>();

                if (lapCount[_index] >= maxLap)
                {
                    var d  = dinos[_index];
                    var uc = d.GetComponent <UserControl>();
                    var ac = d.GetComponent <AIControl>();
                    uc.enabled = false;
                    ac.enabled = true;
                }

                //test to see how many player dinos have completed all of the laps
                for (int i = 0; i < dinos.Length; i++)
                {
                    if (lapCount[i] >= maxLap && dinos[i].tag == "Dino")
                    {
                        lapTest++;
                    }
                }

                //if all player dinos have completed all of the laps end the race
                if (lapTest >= connectedPlayers)
                {
                    hudScript.ShowFinish();
                    hudScript.EndRace();
                }

                if (lapCount[playerNum] > maxLap)
                {
                    hudScript.ShowFinish();
                }

                //Debug.Log("player " + _index + " current node " + currentNodes[_index]);
            }
            //if the player runs into a normal node
            else
            {
                /*Debug.Log("-------------------------");
                 * Debug.Log("you hit " + _node.name);
                 * Debug.Log("the next node is " + nextNodes[_index]);
                 * Debug.Log("the current node is " + currentNodes[_index]);
                 * Debug.Log(nodeScript == nextNodes[_index]);*/

                int j = 0;

                if (nodeScript == nextNodes[_index])
                {
                    //Debug.Log(_node.name + " is the right node");

                    foreach (GameObject n in nodeScript.previousNodes)
                    {
                        //Debug.Log("previous node " + n);
                        //Debug.Log("current node " + currentNodes[_index]);

                        if (n.GetComponent <NodeBehavior>() == currentNodes[_index])
                        {
                            //Debug.Log(nodeScript.NextNodes[j].name + " is the new next node");
                            nextNodes[_index] = nodeScript.NextNodes[j].GetComponent <NodeBehavior>();
                            //currentNodes[_index] = _node.GetComponent<NodeBehavior>();
                            currentNodes[_index] = nodeScript;
                        }

                        j++;
                    }
                }

                //calculate the distance to the finish line
                if (currentNodes[_index].NextNodes.Length != 0)
                {
                    /*Debug.Log(nextNodes[_index] + " is the new next node");
                     * Debug.Log(currentNodes[_index] + " is the new current node");*/

                    finishDist[_index] = AddUpDistance(currentNodes[_index].GetComponent <NodeBehavior>(), nextNodes[_index].GetComponent <NodeBehavior>() /*, i*/, 0);
                }
            }
        }
    }
    private bool CheckAdjacentNodes(List <NodeBehavior> checkedNodes, int distance, NodeBehavior baseNode, NodeBehavior nodeToFind)
    {
        List <NodeBehavior> newNodes     = new List <NodeBehavior>();
        List <NodeBehavior> nodesToCheck = baseNode.GetConnectedNodes();

        if (nodesToCheck.Contains(nodeToFind))
        {
            return(true);
        }
        else if (distance > 1)
        {
            foreach (NodeBehavior node in nodesToCheck)
            {
                if (!checkedNodes.Contains(node))
                {
                    newNodes.Add(node);
                    checkedNodes.Add(node);
                }
            }
        }
        else
        {
            return(false);
        }

        while (distance > 1)
        {
            List <NodeBehavior> nextNodeLayer = new List <NodeBehavior>();
            foreach (NodeBehavior node in newNodes)
            {
                if (node.GetConnectedNodes().Contains(nodeToFind))
                {
                    return(true);
                }

                foreach (NodeBehavior adjacent in node.GetConnectedNodes())
                {
                    if (!checkedNodes.Contains(adjacent))
                    {
                        nextNodeLayer.Add(adjacent);
                        checkedNodes.Add(adjacent);
                    }
                }
            }

            newNodes = nextNodeLayer;
            distance--;
        }
        return(false);
    }
 public void SetConnectedNode(NodeBehavior connectedNode)
 {
     connectedNodes.Add(connectedNode);
     adjacentFactionsCount[(int)connectedNode.GetOwner()]++;
 }
Beispiel #20
0
 public void SetNode(NodeBehavior node)
 {
     attachedNode = node;
 }
Beispiel #21
0
 private Status HandleStatus(Status status, NodeBehavior updated)
 {
     runningNode = status == Status.Running ? updated : null;
     return(status);
 }