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


C# RepositoryFactory.GetGoalkeeper方法代码示例

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


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

示例1: StartingLineupGenerator

 public StartingLineupGenerator()
 {
     using (var positionRepository = new RepositoryFactory().CreatePositionRepository())
      {
     _alternativePositions = new Dictionary<string, List<Position>>
     {
        { "Goalkeeper", new List<Position> {positionRepository.GetGoalkeeper()} },
        { "CentreBack", new List<Position> {positionRepository.GetWingBack(), positionRepository.GetDefensiveMidfield()} },
        { "WingBack", new List<Position> {positionRepository.GetCentreBack(), positionRepository.GetDefensiveMidfield()} },
        { "DefensiveMidfield", new List<Position> {positionRepository.GetWingBack(), positionRepository.GetCentreBack()} },
        { "CentralMidfield", new List<Position> {positionRepository.GetWideMidfield(), positionRepository.GetForwardMidfield(), positionRepository.GetDefensiveMidfield()} },
        { "WideMidfield", new List<Position> {positionRepository.GetCentralMidfield(), positionRepository.GetDefensiveMidfield(), positionRepository.GetForwardMidfield()} },
        { "ForwardMidfield", new List<Position> {positionRepository.GetCentralMidfield(), positionRepository.GetCentreForward(), positionRepository.GetWinger()} },
        { "Winger", new List<Position> {positionRepository.GetForwardMidfield(), positionRepository.GetCentreForward()} },
        { "CentreForward", new List<Position> {positionRepository.GetForwardMidfield(), positionRepository.GetStriker(), positionRepository.GetWinger()} },
        { "Striker", new List<Position> {positionRepository.GetCentreForward(), positionRepository.GetWinger(), positionRepository.GetForwardMidfield()} }
     };
      }
 }
开发者ID:bouwe77,项目名称:fmg,代码行数:19,代码来源:StartingLineupGenerator.cs

示例2: GenerateSquad

        //public void Update(Player player)
        //{
        //   using (var playerRepository = new RepositoryFactory().GetPlayerRepository())
        //   {
        //      playerRepository.Update(player);
        //   }
        //}
        //public void Delete(Player player)
        //{
        //   using (var playerRepository = new RepositoryFactory().GetPlayerRepository())
        //   {
        //      playerRepository.Delete(player);
        //   }
        //}
        public IEnumerable<Player> GenerateSquad(Team team, int averageRating)
        {
            var squad = new List<Player>();

             using (var lineRepository = new RepositoryFactory().CreateLineRepository())
             {
            // Generate 2 goalkeepers.
            int howMany = 2;
            var line = lineRepository.GetGoalkeeper();
            squad.AddRange(GeneratePlayersForLine(line, howMany, averageRating));

            // Generate between 5 and 7 defenders.
            howMany = NumberRandomizer.GetNumber(5, 7);
            line = lineRepository.GetDefence();
            squad.AddRange(GeneratePlayersForLine(line, howMany, averageRating));

            // Generate between 5 and 7 midfielders.
            howMany = NumberRandomizer.GetNumber(5, 7);
            line = lineRepository.GetMidfield();
            squad.AddRange(GeneratePlayersForLine(line, howMany, averageRating));

            // Generate between 4 and 6 attackers.
            howMany = NumberRandomizer.GetNumber(4, 6);
            line = lineRepository.GetAttack();
            squad.AddRange(GeneratePlayersForLine(line, howMany, averageRating));
             }

             int teamOrder = 0;
             foreach (var player in squad)
             {
            player.Team = team;
            player.Game = team.Game;
            player.TeamOrder = teamOrder++;
             }

             new TeamService(Game).UpdateRating(team, squad);

             return squad;
        }
开发者ID:bouwe77,项目名称:fmg,代码行数:53,代码来源:PlayerService.cs

示例3: GenerateStartingLineup

        public List<Player> GenerateStartingLineup(List<Player> players, Formation formation)
        {
            // Sort the players on rating and then on name.
             players.Sort(delegate (Player p1, Player p2)
             {
            int ratingDiff = p1.Rating.CompareTo(p2.Rating);
            if (ratingDiff != 0) return ratingDiff;
            return string.Compare(p1.Name, p2.Name, StringComparison.OrdinalIgnoreCase);
             });

             var newPlayers = new Player[players.Count];
             int teamOrder = 0;

             // Split the players into three lists: the goalkeepers, the best 10 and the rest.
             Position goalkeeperPosition;
             using (var positionRepository = new RepositoryFactory().CreatePositionRepository())
             {
            goalkeeperPosition = positionRepository.GetGoalkeeper();
             }

             var goalkeepers = players.Where(player => player.PreferredPosition.Equals(goalkeeperPosition)).ToList();
             var bestFieldPlayers = players.Where(player => !player.PreferredPosition.Equals(goalkeeperPosition)).Take(10).ToList();
             var otherFieldPlayers = players.Where(player => !player.PreferredPosition.Equals(goalkeeperPosition)).Skip(10).ToList();

             // Pick the best goalkeeper.
             var bestGoalkeeper = goalkeepers.First();
             goalkeepers.Remove(bestGoalkeeper);
             bestGoalkeeper.CurrentPosition = goalkeeperPosition;
             bestGoalkeeper.TeamOrder = teamOrder;
             newPlayers[teamOrder] = bestGoalkeeper;
             teamOrder++;

             // Put the 10 best field players on their preferred position if possible.
             while (teamOrder < 11)
             {
            var positionWeNeed = formation.Positions[teamOrder];
            var playerForPos = bestFieldPlayers.FirstOrDefault(player => player.PreferredPosition.Equals(positionWeNeed));
            if (playerForPos != null)
            {
               playerForPos.CurrentPosition = positionWeNeed;
               playerForPos.TeamOrder = teamOrder;
               newPlayers[teamOrder] = playerForPos;
               bestFieldPlayers.Remove(playerForPos);
            }

            teamOrder++;
             }

             // Check whether the starting eleven has positions without a player and pick players for these positions.
             for (int i = 0; i < 11; i++)
             {
            if (newPlayers[i] == null)
            {
               Player playerForPos = null;
               var positionWeNeed = formation.Positions[i];

               // 1) Get a player from the best 10 players (if any left) that has an alternative for this position.
               var alternativePositions = GetAlternativePositions(positionWeNeed);
               foreach (var alternativePosition in alternativePositions)
               {
                  playerForPos = bestFieldPlayers.FirstOrDefault(player => player.PreferredPosition.Equals(alternativePosition));
                  if (playerForPos != null)
                  {
                     playerForPos.CurrentPosition = positionWeNeed;
                     playerForPos.TeamOrder = i;
                     newPlayers[i] = playerForPos;
                     bestFieldPlayers.Remove(playerForPos);
                     break;
                  }
               }

               // 2) If not found, get one of the remaining players that has this position
               if (playerForPos == null)
               {
                  playerForPos = otherFieldPlayers.FirstOrDefault(player => player.PreferredPosition.Equals(positionWeNeed));
                  if (playerForPos != null)
                  {
                     playerForPos.CurrentPosition = positionWeNeed;
                     playerForPos.TeamOrder = i;
                     newPlayers[i] = playerForPos;
                     otherFieldPlayers.Remove(playerForPos);
                  }
               }

               // 3) If not found, get one of the remaining players that has an alternative for this position.
               if (playerForPos == null)
               {
                  foreach (var alternativePosition in alternativePositions)
                  {
                     playerForPos = otherFieldPlayers.FirstOrDefault(player => player.PreferredPosition.Equals(alternativePosition));
                     if (playerForPos != null)
                     {
                        playerForPos.CurrentPosition = positionWeNeed;
                        playerForPos.TeamOrder = i;
                        newPlayers[i] = playerForPos;
                        otherFieldPlayers.Remove(playerForPos);
                        break;
                     }
                  }
               }
//.........这里部分代码省略.........
开发者ID:bouwe77,项目名称:fmg,代码行数:101,代码来源:StartingLineupGenerator.cs


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