Beispiel #1
0
    /**
     * This method destroys all the prior objects from the previous level such as nodes and edges of the dfa
     * it increases the timer by 1.5 seconds each level from the base of 30 seconds
     * it generates by calling the generate level function, which is given the level number and the amount of mutations per level
     * it sets the start node to the 0th node
     * it sets the end node to the 6th node
     * it sets the end node to color red to signify it is the end node
     * it calculates the edges based on a minimal path to traverse the DFA
     * and then it instantiates new wires to go along the new level
     * then it gives the lcd controller the new start time
     * @param  none
     */
    public void NextLevel()
    {
        uiManager.SwitchGame();
        currMaxVelocity = initMaxVelocity;

        levelNumber++;
        levelStartTime = Mathf.Min(99, 30 + 1.5f * (levelNumber - 1));
        timer          = 0;

        foreach (var node in allNodes)
        {
            Destroy(node.gameObject);
        }
        allNodes.Clear();

        foreach (var edge in allEdges)
        {
            Destroy(edge.gameObject);
        }
        allEdges.Clear();

        GenerateLevel(levelNumber, mutationsPerLevel);

        startNode           = allNodes[0];
        startNode.IsCurrent = true;
        currentPosition     = startNode;
        endNode             = allNodes[6];
        endNode.gameObject.GetComponent <Image>().color = Color.red;

        var edges = FindMinPath();

        edges = edges.OrderBy(x => UnityEngine.Random.Range(0, edges.Count - 1)).ToList();
        for (int i = 0; i < edges.Count; i++)
        {
            var newWire = Instantiate(possibleWires[i], bomb.transform);
            newWire.GetComponent <Renderer>().material.color = edges[i].GetColor();
            newWire.GetComponent <BombWire>().color          = edges[i].GetColorStr();
            wires.Add(newWire);
        }

        lcdController.SetTimer(levelStartTime);
    }