Exemplo n.º 1
0
        private IEnumerator PlayerTurn(IGenerator self)
        {
            CurrentPlayerModel.StartTurn();

            ResetTurnTimer();

            // player can make as many valid actions as he can during his turn
            while (true)
            {
                if (GameState.Value == EGameState.Completed)
                {
                    self.Complete();
                    yield break;
                }

                Assert.IsTrue(self.Active);

                var future = CurrentPlayerAgent.Value.NextRequest(_timeOut);
                Assert.IsNotNull(future);

                yield return(self.ResumeAfter(future));

                if (future.HasTimedOut)
                {
                    Warn($"{CurrentPlayerModel} timed-out");
                    yield return(self.ResumeAfter(New.Coroutine(PlayerTimedOut)));

                    continue;
                }
                if (!future.Available)
                {
                    Warn($"{CurrentPlayerModel} didn't make a request");
                }

                // do the arbitration before we test for time out
                var request  = future.Value.Request as IGameRequest;
                var response = Model.Arbitrate(request);
                response.Request = request;
                future.Value.Responder?.Invoke(response);

                if (response.Failed)
                {
                    Warn($"{request} failed for {CurrentPlayerModel}");
                }

                var now = Kernel.Time.Now;
                var dt  = (float)(now - _timeStart).TotalSeconds;

                _timeStart = now;
                _timeOut  -= dt;

                if (request is TurnEnd && response.Success)
                {
                    ResetTurnTimer();
                }
            }
        }
Exemplo n.º 2
0
        IEnumerator <bool> ConditionCoro(IGenerator self, Func <bool> pred)
        {
            while (pred())
            {
                yield return(true);
            }

            yield return(false);

            self.Complete();
        }