Example #1
0
        private Round.Round GetNextRound()
        {
            if (_scores.Values.Any(s => s >= WinningScore))
            {
                return(null);
            }

            var deck = Shuffle();

            int playerIndex;

            if (CurrentRound == null)
            {
                var maxPlayerIndex = Players.Count() - 1;
                playerIndex = _randomService.GetInclusive(0, maxPlayerIndex);
            }
            else
            {
                var playerId = CurrentRound.GetWinningPlayerId().Value;
                _scores[playerId] = _scores[playerId] + 1;
                playerIndex       = Players
                                    .SelectMany((value, index) => value.Id == playerId ? new[] { index } : Enumerable.Empty <int>())
                                    .DefaultIfEmpty(-1).First();

                CurrentRound.Cleanup();
            }

            var players = Players.Skip(playerIndex).Concat(Players.Take(playerIndex));

            CurrentRound = new Round.Round(players, deck);
            return(CurrentRound);
        }