예제 #1
0
 public RlGameContext(iRlStage stage, IList <Entity> es)
 {
     this.stage    = stage;
     this.entities = es;
     this.logic    = new RlLogic(this);
     this.evHub    = new AnyRlEvHub();
 }
예제 #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);
                }
            }
        }
예제 #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);
                    }
                }
            }
        }
예제 #4
0
 public RlGameState(AnyRlEvHub evHub, iRlActorIterator scheduler)
 {
     Force.nonNull(scheduler, "Given null as a scheduler to the game state");
     this.loop = RlGameState.gameFlow(scheduler, evHub).GetEnumerator();
 }