コード例 #1
0
        public IEnumerator Evaluate(GameLevel gameLevel, int loopDepth, LevelLoop parentLoop)
        {
            // Main loop should always break out immediately upon finishing.
            if (!gameLevel.MainLoop.ShouldContinue(gameLevel))
            {
                gameLevel.CompleteLevel();
                yield break;
            }

            switch (this.Type)
            {
            case LoopType.Do:
                do
                {
                    yield return(EvaluateChildren(gameLevel, loopDepth, this));
                }while (ShouldContinue(gameLevel));
                yield break;

            case LoopType.For:
                for (this.Iterator = 0; ShouldContinue(gameLevel); this.Iterator++)
                {
                    yield return(EvaluateChildren(gameLevel, loopDepth, this));
                }
                yield break;

            case LoopType.While:
                while (ShouldContinue(gameLevel))
                {
                    yield return(EvaluateChildren(gameLevel, loopDepth, this));
                }
                yield break;

            case LoopType.If:
                if (ShouldContinue(gameLevel))
                {
                    yield return(EvaluateChildren(gameLevel, loopDepth, this));
                }
                yield break;

            case LoopType.None:
                yield return(EvaluateChildren(gameLevel, loopDepth, this));

                yield break;
            }

            gameLevel.UpdateLevelCode();
        }
コード例 #2
0
        private IEnumerator EvaluateChildren(GameLevel gameLevel, int loopDepth, LevelLoop parentLoop)
        {
            // Main loop should always break out immediately upon finishing.
            if (!gameLevel.MainLoop.ShouldContinue(gameLevel))
            {
                gameLevel.CompleteLevel();
                yield break;
            }

            foreach (CodeStatement statement in this.Statements)
            {
                yield return(statement.Evaluate(gameLevel));
            }

            foreach (LevelLoop nestedLoop in this.NestedLoops)
            {
                yield return(nestedLoop.Evaluate(gameLevel, loopDepth + 1, parentLoop));
            }
            gameLevel.UpdateLevelCode();
            yield return(null);
        }