/// <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); } } }
/// <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); } } } }
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(); }