コード例 #1
0
    //checks if the puzzle is complete and updates each layer in the process
    bool IsComplete(ComboLayerWithSymbol currentLayer)
    {
        List <PowerLinkWithRunes> poweredNodes = new List <PowerLinkWithRunes>();

        //find all of the powered downNodes in this layer
        foreach (PowerLinkWithRunes node in currentLayer.GetRecieverNodes())
        {
            if (node.IsPowered())
            {
                poweredNodes.Add(node);
            }
        }


        ComboLayerWithSymbol nextLayer = currentLayer.GetNextLayer();

        //this part implies that the final layer needs only one node to be powered, or that the layer has only one node
        //this section could be modified so that a set of nodes needs to be powered instead.
        if (poweredNodes.Count > 0 && nextLayer == null)
        {
            return(true);
        }

        if (nextLayer == null)
        {
            return(false);
        }

        //turn off all the downNodes in the next layer
        foreach (PowerLinkWithRunes node in nextLayer.GetRecieverNodes())
        {
            node.SetPower(false);
        }

        //if there are no powered nodes here, then this cannot be the solution
        if (poweredNodes.Count == 0)
        {
            IsComplete(nextLayer);              //this has to be done in order to turn off all the nodes on the layers above
            return(false);
        }


        //for each powered upNode in this layer, find and turn on each corresponding downNode in the next layer
        foreach (PowerLinkWithRunes node in poweredNodes)
        {
            foreach (GameObject upNode in node.GetAttachedOutNodes())
            {
                foreach (PowerLinkWithRunes downNode in nextLayer.GetRecieverNodes())
                {
                    if (NodesInLine(upNode, downNode))
                    {
                        downNode.SetPower(true);
                    }
                }
            }
        }

        //do recursion onto the next layer
        return(IsComplete(nextLayer));
    }
コード例 #2
0
 public void UpdatePuzzle()
 {
     baseLayer.GetRecieverNodes()[0].SetPower(true);
     if (IsComplete(baseLayer))
     {
         cc.Complete();
         this.enabled = false;
     }
 }
コード例 #3
0
    void TurnOffLayer(ComboLayerWithSymbol currentLayer)
    {
        if (currentLayer == null)
        {
            return;
        }

        //find all of the powered downNodes in this layer
        foreach (PowerLinkWithRunes node in currentLayer.GetRecieverNodes())
        {
            node.SetPower(false);
        }

        TurnOffLayer(currentLayer.GetNextLayer());
    }