コード例 #1
0
ファイル: Miner.cs プロジェクト: MatiasRT/IA-TPs
    public override void ReactOn(Element objective)
    {
        if (this.gameObject == objective.gameObject)
        {
            path = null;
            OnObjectiveNotFound();
        }

        switch (objective.elementType)
        {
        case EElement.Ground:
            GetPath(objective, objective.GetComponent <Ground>().lastPositionClicked);
            break;

        case EElement.Mine:
            if (objective == mine)
            {
                return;
            }

            mine = objective.GetComponent <Mine>();
            Node mineObj = mine.GetAvailableNode();

            if (!mineObj)
            {
                OnObjectiveNotFound();
                mine = null;
                return;
            }

            mine.AddMiner(this);

            GetPath(objective, mineObj.position);
            break;

        case EElement.TownCenter:
            if (GetActualState() == (int)States.Working && mine)
            {
                mine.RemoveMiner(this);
                mine = null;
            }

            Node townCenterObj = myTownCenter.GetAvailableNode();
            if (!townCenterObj)
            {
                OnObjectiveNotFound();
                return;
            }

            GetPath(objective, townCenterObj.position);
            break;
        }
    }