Example #1
0
        /// <summary> Advances the game for "one step", which can be observed & visualized externally </summary>
        public RlGameProgress tick()
        {
            if (this.loop == null)
            {
                return(RlGameProgress.error("Somehow the game loop is null!"));
            }
            if (this.loop.MoveNext() == false)
            {
                return(RlGameProgress.error("The game loop is finished, it must not!"));
            }

            return(this.loop.Current);
        }
Example #2
0
        /// <summary> The nestable <c>RlEvent</c> handling </summary>
        static IEnumerable <RlGameProgress> processEvent(AnyRlEvHub evHub, RlEvent ev)
        {
            yield return(RlGameProgress.event_(ev));

            foreach (var evNested in evHub.handleAbs(ev))
            {
                // nest events enabled
                foreach (var report in RlGameState.processEvent(evHub, evNested))
                {
                    if (report == null)
                    {
                        continue;
                    }
                    yield return(report);
                }
            }
        }
Example #3
0
        /// <summary> A turn-based game flow </summary>
        /// <remarks> Becomes an infinite loop if there's no event to process. </remarks>
        static IEnumerable <RlGameProgress> gameFlow(iRlActorIterator scheduler, AnyRlEvHub evHub)
        {
            while (true)
            {
                var actor = scheduler.next();
                if (actor == null)
                {
                    yield return(RlGameProgress.error("Given null as an actor in RlGameState.flow()"));

                    continue;
                }

                foreach (var ev in actor.takeTurn().Where(e => e != null))
                {
                    foreach (var report in RlGameState.processEvent(evHub, ev).Where(e => e != null))
                    {
                        yield return(report);
                    }
                }
            }
        }