Beispiel #1
0
 //Checks if the game is won, and does something if it is, starting at the given node
 public void checkForCompletion(LightPuzzleNode lpn)
 {
     if (this.puzzleStarted && lpn.checkForCompletion())
     {
         Debug.Log("WIN (Put something here lol)");
     }
 }
Beispiel #2
0
    //Creates a given number of nodes around the given node, without overlapping existing nodes.
    //Queues any created nodes to the given queue and returns the number of nodes not created.
    private int createRandomNodesAround(LightPuzzleNode lpn, int count, Queue <LightPuzzleNode> q)
    {
        Vector2        gridPos         = lpn.getGridPos();
        List <Vector2> unpickedGridPos = new List <Vector2>
        {
            new Vector2(1, 0) + gridPos,
            new Vector2(0, 1) + gridPos,
            new Vector2(-1, 0) + gridPos,
            new Vector2(0, -1) + gridPos,
        };

        while (count > 0 && unpickedGridPos.Count > 0)
        {
            int     i  = Random.Range(0, unpickedGridPos.Count);
            Vector2 gp = unpickedGridPos[i];
            unpickedGridPos.RemoveAt(i);

            if (!this.nodeExistsAt(gp) && Mathf.Abs(gp.x) <= 2 && Mathf.Abs(gp.y) <= 2)
            {
                count--;
                LightPuzzleNode node = this.newNode(gp);
                q.Enqueue(node);
            }
        }

        return(count);
    }
Beispiel #3
0
 public void onLightPuzzleSwitch(LightPuzzleNode lpn)
 {
     if (onLightPuzzleSwitchEvent != null)
     {
         onLightPuzzleSwitchEvent(lpn);
     }
 }
Beispiel #4
0
 private void makeNeighborsIfExists(LightPuzzleNode lpn, Vector2 atPos)
 {
     if (this.nodeExistsAt(atPos))
     {
         lpn.makeNeighborsWith(this.getNodeAt(atPos));
     }
 }
    //Creates a lightPuzzleNode at the given grid position
    public LightPuzzleNode newNode(Vector2 gridPos)
    {
        GameObject      g   = Object.Instantiate(this.lightPrefab);
        LightPuzzleNode lpn = g.GetComponent <LightPuzzleNode>();

        lpn.setGridPos(gridPos);
        return(lpn);
    }
Beispiel #6
0
    private LightPuzzleNode newNode(Vector2 gridPos)
    {
        LightPuzzleNode lpn = LightPuzzleGen.instance.newNode(gridPos);

        this.nodes.Add(lpn);
        lpn.transform.SetParent(this.transform);
        lpn.transform.localEulerAngles = new Vector3(0, 0, 0);
        lpn.transform.localScale       = new Vector3(1, 1, 1);
        return(lpn);
    }
Beispiel #7
0
 private bool containsNode(List <LightPuzzleNode> list, LightPuzzleNode lpn)
 {
     foreach (LightPuzzleNode other in list)
     {
         if (lpn.sameNode(other))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #8
0
    public bool neighborsWith(LightPuzzleNode lpn)
    {
        foreach (LightPuzzleNode neighbor in this.neighbors)
        {
            if (lpn.sameNode(neighbor))
            {
                return(true);
            }
        }

        return(this.sameNode(lpn));
    }
Beispiel #9
0
    public void changeRandomly(int nodeCount)
    {
        List <LightPuzzleNode> unpickedNodes = new List <LightPuzzleNode>(this.nodes);

        while (nodeCount > 0)
        {
            int             i   = Random.Range(0, unpickedNodes.Count);
            LightPuzzleNode lpn = unpickedNodes[i];
            unpickedNodes.RemoveAt(i);
            lpn.change();
            if (nodeCount != 1 || !lpn.checkForCompletion())
            {
                nodeCount--;
            }
        }
    }
Beispiel #10
0
    //Initializes the nodes in a list
    private void initNodes(int nodeCount)
    {
        nodeCount = nodeCount < 3 ? 3 : nodeCount;
        Queue <LightPuzzleNode> workList = new Queue <LightPuzzleNode>();

        workList.Enqueue(this.newNode(new Vector2(0, 0)));
        int nodesLeft = nodeCount - 1;

        while (nodesLeft > 0 && workList.Count > 0)
        {
            LightPuzzleNode current = workList.Dequeue();

            int maxNodes      = nodesLeft < 4 ? nodesLeft : 4;
            int nodesToCreate = Random.Range(0, maxNodes) + 1;
            nodesLeft -= nodesToCreate - this.createRandomNodesAround(current, nodesToCreate, workList);
        }
    }
Beispiel #11
0
 public bool sameNode(LightPuzzleNode lpn)
 {
     return(this.gridPos.Equals(lpn.gridPos));
 }
Beispiel #12
0
 //Adds the given lpn as a neighbor to this one ONLY
 public void makeNeighborsWith(LightPuzzleNode lpn)
 {
     this.neighbors.Add(lpn);
 }