// Advances the game state forward in time public bool Update(Func <ActionResult> inputAction) { if (inputAction == null && !Player.HasNextStep) { return(false); } var characters = CurrentFloor.Entities.OfType <Character>().ToArray(); Ticks++; if (Ticks % RegenRate == 0) { foreach (var character in characters) { character.Regenerate(); } } Player.PendingAction = inputAction; Player.Update(this); NextQueue.Enqueue(Player, -Player.Sequence); if (CurrentQueue.Count == 0) { foreach (var character in CurrentFloor.Entities.OfType <Character>()) { CurrentQueue.Enqueue(character, -character.Sequence); } } while (CurrentQueue.Count != 0) { var current = CurrentQueue.Dequeue(); if (current is Player) { return(true); } var actionResult = current.Update(this); Log.LogActionResult(actionResult); NextQueue.Enqueue(current, -current.Sequence); } var tempQueue = CurrentQueue; CurrentQueue = NextQueue; NextQueue = tempQueue; NextQueue.Clear(); return(true); }
/** Push element x onto stack. */ public void Push(int x) { Discriminator = (Discriminator + 1) % 2; CurrentQueue.Enqueue(x); if (OldQueue.Count != 0) { int oldQueueCount = OldQueue.Count; for (int i = 0; i < oldQueueCount; i++) { CurrentQueue.Enqueue(OldQueue.Dequeue()); } } }
public void Enqueue(ISimpleTask task) { if (_standbyEvent != null) { _eventStack.Push(_standbyEvent.Value); _standbyEvent = null; _eventCreated = true; } CurrentQueue.Enqueue(task); _game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "TaskQueue", !_game.Logging ? "" : $"{task.GetType().Name} is Enqueued in {_eventStack.Count}th stack"); }
public void Enqueue(ISimpleTask task) { if (_eventFlag) // flag = true means Event starts and no tasks queue yet { if (CurrentQueue.Count != 0) // Check if an ongoing event exists { _eventStack.Push(new Queue <ISimpleTask>()); } _eventFlag = false; } CurrentQueue.Enqueue(task); //_game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "TaskQueue", // !_game.Logging ? "" : $"{task.GetType().Name} is Enqueued in {_eventStack.Count}th stack"); }