コード例 #1
0
ファイル: TurnPlayer.cs プロジェクト: gasgiant/doevil.sh
    private IEnumerator PlayCoroutine(bool prediction)
    {
        Blocker blocker    = new Blocker();
        bool    isFinished = false;

        if (prediction)
        {
            predictedPositions.Clear();
            predictedPositions.Add(Grid.IndexToPosition(focusAgent.InitialIndex));
        }

        if (!prediction)
        {
            overrideManager.SetInteractable(false);
            foreach (var agent in agents)
            {
                agent.SetInteractable(false);
            }
        }

        while (true)
        {
            foreach (var agent in agents)
            {
                PlayAgentTurn(agent, blocker, prediction);
                while (blocker.IsBuisy)
                {
                    yield return(null);
                }
                agent.IncrementTurn(prediction);
            }

            bool allHackableDead = true;
            foreach (var agent in agents)
            {
                if (!agent.unhackable && !agent.IsDead)
                {
                    allHackableDead = false;
                }
            }

            if (allHackableDead)
            {
                if (!prediction)
                {
                    yield return(new WaitForSeconds(1.1f));

                    uiManager.ShowLoseSceen();
                }
                isFinished = true;
            }
            else
            {
                if (CheckGoals())
                {
                    if (!prediction)
                    {
                        uiManager.ShowWinScreen();
                    }
                    isFinished = true;
                }
            }

            if (prediction)
            {
                predictedPositions.Add(Grid.IndexToPosition(focusAgent.Index));
            }
            else
            {
                if (!isFinished)
                {
                    yield return(new WaitForSeconds(0.3f));
                }
            }

            if (!isFinished)
            {
                bool b = true;
                foreach (var agent in agents)
                {
                    b = b && agent.GetCommand() == null;
                }
                isFinished = b;
            }

            if (isFinished)
            {
                break;
            }
        }

        if (prediction)
        {
            predictionView.SetPredictionData(predictedPositions);
            ResetEverything();
        }

        playRoutine = null;
    }