コード例 #1
0
    public void nextStep()
    {
        //right
        int  P = 0, D = 0;
        bool ifBoatSizeRight;

        if (gameStatus != "playing")
        {
            return;
        }

        if (myBoat.size == "right")
        {
            ifBoatSizeRight = true;
        }
        else
        {
            ifBoatSizeRight = false;
        }

        foreach (peopleController pctrl in peopleCtrl)
        {
            myBoat.outBoat(pctrl.getName());
            pctrl.getOffBoat(environment);
            if (pctrl.size == "left")
            {
                if (pctrl.getName() [0] == 'd')
                {
                    D++;
                }
                else
                {
                    P++;
                }
            }
        }
        node      thisNode = new node(P, D, ifBoatSizeRight);
        operation oper     = graph.getNextStep(thisNode);

        Debug.Log(thisNode.P + " " + thisNode.D);
        foreach (peopleController pctrl in peopleCtrl)
        {
            if (pctrl.size == myBoat.size && pctrl.getName()[0] == 'd' && oper.D > 0)
            {
                pctrl.getOnBoat(myBoat);
                oper.D--;
            }
            else if (pctrl.size == myBoat.size && pctrl.getName()[0] == 'p' && oper.P > 0)
            {
                pctrl.getOnBoat(myBoat);
                oper.P--;
            }
        }

        boatMove();
    }
コード例 #2
0
    public void getBoatOrGetShore(string name)      //恶魔或牧师上船或上岸的条件设置
    {
        if (myBoat.getRunningState() != "waiting")
        {
            return;
        }
        int numberOfPeople = name [name.Length - 1] - '0';

        if (peopleCtrl [numberOfPeople].getStatus() == "shore")
        {
            if (myBoat.ifHaveSeat() && myBoat.size == peopleCtrl [numberOfPeople].size)
            {
                peopleCtrl [numberOfPeople].getOnBoat(myBoat);
            }
        }
        else
        {
            if (myBoat.size == peopleCtrl [numberOfPeople].size)
            {
                peopleCtrl [numberOfPeople].getOffBoat(environment);
                myBoat.outBoat(peopleCtrl [numberOfPeople].getName());
            }
        }
    }