예제 #1
0
    // Use this for initialization
    void Start()
    {
        nodePrefab = transform.GetComponentInChildren <NodeController>();
        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }
        nodePrefab.enabled = true;
        nodePrefab.GetComponent <BoxCollider2D>().enabled = true;
        for (int i = 0; i < size; ++i)
        {
            nodeGrid[i] = Instantiate(nodePrefab, transform);
            nodeGrid[i].transform.localPosition = new Vector3(
                i % width - (width - 1) / 2f,
                i / width - (width - 1) / 2f, 0);
            nodeGrid[i].name           = "Node (" + i % width + ", " + i / width + ")";
            nodeGrid[i].delta_pressure = 0.1f;
        }
        nodeGrid[0].delta_pressure = 1f;
        int j = 0;

        for (int y = 0; y < width; ++y)
        {
            for (int x = 0; x < width - 1; ++x)
            {
                connections[j++] = new NodeConnection(nodeGrid[x + y * width], nodeGrid[(x + 1) + y * width], new Vector2(1, 0));
                connections[j++] = new NodeConnection(nodeGrid[y + x * width], nodeGrid[y + (1 + x) * width], new Vector2(0, 1));
            }
        }
        transform.Translate(new Vector3(0, 0, width - 4));
    }
예제 #2
0
    void newCallTuto(NodeController HostHomme, NodeController HostFemme)
    {
        NodeController caller = HostHomme;

        caller.status = NodeController.Status.calling;

        NodeController reciever = HostFemme;

        reciever.status = NodeController.Status.waitingCall;

        Call call = new Call(true);//true = chrono infini

        caller.GetComponent <SpriteRenderer>().color   = GetColorFromId(call.id);
        reciever.GetComponent <SpriteRenderer>().color = GetColorFromId(call.id);
        callsInTransmission.Add(call);

        caller.call   = call;
        reciever.call = call;
        call.caller   = caller;
        call.reciever = reciever;

        caller.DisplayMessageBox(true);

        call.status = Call.Status.calling;
    }
예제 #3
0
    void step()
    {
        NodeController villeCourante = sousGraphe[curseur].GetComponent <NodeController>();

        Voisin[] voisinsCourant = villeCourante.voisins;
        for (int i = 0; i < voisinsCourant.Length; i++)
        {
            int nouvelleValeur = villeCourante.valeur + voisinsCourant[i].distance;
            if (nouvelleValeur < voisinsCourant[i].voisin.GetComponent <NodeController>().valeur)
            {
                voisinsCourant[i].voisin.GetComponent <NodeController>().valeur = nouvelleValeur;
                pred.Remove(voisinsCourant[i].voisin);
                pred.Add(voisinsCourant[i].voisin, villeCourante.gameObject);
            }
        }
        villeCourante.GetComponent <Renderer>().material.color = Color.grey;
        GameObject min = minimalHorsSousGraphe();

        sousGraphe.Add(min);
        if (min == arrivee)
        {
            victoire();
        }
        else
        {
            nodes.Remove(min);
            curseur++;
        }
    }
예제 #4
0
    private KeyValuePair <Vector3, bool> getEdgeCoords(NodeController node1, NodeController node2)
    {
        Vector3 vec1       = node1.GetComponent <NodeController>().transform.position;
        Vector3 vec2       = node2.GetComponent <NodeController>().transform.position;
        Vector3 edgeCoords = Vector3.zero;
        KeyValuePair <Vector3, bool> pair;

        if (vec1.y == vec2.y) //this means that the edge has to be vertical
        {
            edgeCoords.x = (vec1.x + vec2.x) / 2;
            edgeCoords.y = vec1.y;
            pair         = new KeyValuePair <Vector3, bool>(edgeCoords, true);
        }
        else // this means that the edge has to be horizontal
        {
            edgeCoords.x = vec1.x;
            edgeCoords.y = (vec1.y + vec2.y) / 2;
            pair         = new KeyValuePair <Vector3, bool>(edgeCoords, false);
        }
        return(pair);
    }
예제 #5
0
    private void StartingCall()
    {
        /*if(score<10)
         *  timerBeforeNextCall = Random.Range(10,20);
         * if(score<50)
         *  timerBeforeNextCall = Random.Range(8,14);
         * else
         *  timerBeforeNextCall = Random.Range(7,10);*/

        /*if(score<10)
         *  timerBeforeNextCall = Random.Range(10,20);
         * if(score<50)
         *  timerBeforeNextCall = Random.Range(7,12);
         * else
         *  timerBeforeNextCall = Random.Range(5,7);*/

        //Balancing Calls
        timerBeforeNextCall = Call.durationBetweenCall(score);

        if (availableHosts.Count >= 2 && callsInTransmission.Count < maxCalls)
        {
            Debug.Log("Au moins 2 travaillent");

            int randomCaller = Random.Range(0, availableHosts.Count);

            NodeController caller = availableHosts[randomCaller];
            availableHosts.Remove(caller);
            unavailableHosts.Add(caller);
            caller.status = NodeController.Status.calling;

            int randomReciever = Random.Range(0, availableHosts.Count);

            NodeController reciever = availableHosts[randomReciever];
            availableHosts.Remove(reciever);
            unavailableHosts.Add(reciever);
            reciever.status = NodeController.Status.waitingCall;

            Debug.Log(caller.name + " is calling " + reciever.name);


            Call call = new Call();
            if (level == 3)
            {
                call.node_obligatory = randomNode();
                if (call.node_obligatory != null)
                {
                    call.node_obligatory.GetComponent <SpriteRenderer>().color = GetColorFromId(call.id);
                    call.node_obligatory.call   = call;
                    call.node_obligatory.isUsed = false;
                }
            }

            caller.GetComponent <SpriteRenderer>().color   = GetColorFromId(call.id);
            reciever.GetComponent <SpriteRenderer>().color = GetColorFromId(call.id);

            callsInTransmission.Add(call);

            caller.call   = call;
            reciever.call = call;
            call.caller   = caller;
            call.reciever = reciever;

            caller.DisplayMessageBox(true);

            call.status = Call.Status.calling;
        }
    }