当前位置: 首页>>代码示例>>C#>>正文


C# Randomizer.GetRandomBoolean方法代码示例

本文整理汇总了C#中Randomizer.GetRandomBoolean方法的典型用法代码示例。如果您正苦于以下问题:C# Randomizer.GetRandomBoolean方法的具体用法?C# Randomizer.GetRandomBoolean怎么用?C# Randomizer.GetRandomBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Randomizer的用法示例。


在下文中一共展示了Randomizer.GetRandomBoolean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateLeagueTable

        public void UpdateLeagueTable(LeagueTable leagueTable, IEnumerable<Match> matches)
        {
            foreach (var match in matches)
             {
            // Determine the home and away team.
            var homeTeam = leagueTable.LeagueTablePositions.First(pos => pos.Team.Equals(match.HomeTeam));
            var awayTeam = leagueTable.LeagueTablePositions.First(pos => pos.Team.Equals(match.AwayTeam));

            // Increment number of played matches.
            homeTeam.Matches++;
            awayTeam.Matches++;

            // Calculate goals scored, conceded and differential for both teams.
            homeTeam.GoalsScored += match.HomeScore;
            homeTeam.GoalsConceded += match.AwayScore;
            homeTeam.GoalDifference = homeTeam.GoalsScored - homeTeam.GoalsConceded;
            awayTeam.GoalsScored += match.AwayScore;
            awayTeam.GoalsConceded += match.HomeScore;
            awayTeam.GoalDifference = awayTeam.GoalsScored - awayTeam.GoalsConceded;

            // Determine the number of points for both teams.
            // Increment the number of wins, losses and/or draws for both teams.
            int homePoints = 1;
            int awayPoints = 1;
            if (match.HomeScore == match.AwayScore)
            {
               homeTeam.Draws++;
               awayTeam.Draws++;
            }
            else
            {
               bool homeTeamWins = match.HomeScore > match.AwayScore;
               bool awayTeamWins = match.AwayScore > match.HomeScore;
               if (homeTeamWins)
               {
                  homePoints = 3;
                  awayPoints = 0;
                  homeTeam.Wins++;
                  awayTeam.Losses++;
               }
               else if (awayTeamWins)
               {
                  homePoints = 0;
                  awayPoints = 3;
                  homeTeam.Losses++;
                  awayTeam.Wins++;
               }
            }

            homeTeam.Points += homePoints;
            awayTeam.Points += awayPoints;
             }

             // Sort the league table.
             leagueTable.LeagueTablePositions.Sort((x, y) =>
             {
            // Points will be sorted ascending, hence Y followed by X.
            int result = y.Points.CompareTo(x.Points);

            // If necessary, matches will be sorted descending, hence X followed by Y.
            if (result == 0)
            {
               result = x.Matches.CompareTo(y.Matches);
            }

            // If necessary, goal difference will be sorted.
            if (result == 0)
            {
               result = y.GoalDifference.CompareTo(x.GoalDifference);
            }

            // If necessary, goals scored will be sorted.
            if (result == 0)
            {
               result = y.GoalsScored.CompareTo(x.GoalsScored);
            }

            //TODO Eigenlijk moet er gekeken worden naar onderling resultaat, maar we doen het eerst maar random...
            if (result == 0)
            {
               var randomizer = new Randomizer();
               bool randomBoolean = randomizer.GetRandomBoolean();
               if (randomBoolean)
               {
                  result = 1;
               }
            }

            return result;
             });

             // Update position numbers, starting with 1.
             int position = 1;
             foreach (var leagueTablePosition in leagueTable.LeagueTablePositions)
             {
            leagueTablePosition.Position = position;
            leagueTablePosition.Team.CurrentLeaguePosition = position;
            position++;
             }
        }
开发者ID:bouwe77,项目名称:fmg,代码行数:100,代码来源:LeagueTableManager.cs


注:本文中的Randomizer.GetRandomBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。