コード例 #1
0
ファイル: Randomizer.cs プロジェクト: goguul/random11
        public Team GenerateTeam()
        {
            var team = new Team();

            try
            {
                team.AddPlayers(_playingStrategy.GetPlayers(_players));
                team.SetCaptain(_playingStrategy.GetCaptain(team.Players));
                team.SetViceCaptain(_playingStrategy.GetViceCaptain(team.Players));

                if (team.Players.GroupBy(x => x.Team).Any(y => y.Count() > 7))
                {
                    throw new MaxPlayerExceededException("Max player exceeded from particular team");
                }
            }
            catch (Exception ex)
            {
                if (_retryCount == 0)
                {
                    throw ex;
                }
                if (ex is MaxPlayerExceededException || ex is CreditNotAvailableException)
                {
                    GenerateTeam();
                    _retryCount--;
                }
            }

            return(team);
        }