Exemplo n.º 1
0
Arquivo: TeamData.cs Projeto: srog/FMS
        private static void ValidateTeamFormation(Team team)
        {
            var players = PlayerData.GetPlayersByTeamId(team.Id)
                          .Where(p => p.Contract > 0 && p.Status == PlayerStatusEnum.Active);

            // check if formation is valid, if not then change formation
            // TODO , if not valid then play players out of position
            while (true)
            {
                if ((team.Formation.Defenders > players.Count(p => p.Position == PlayerPositionsEnum.Defender)) ||
                    (team.Formation.Midfielders > players.Count(p => p.Position == PlayerPositionsEnum.Midfielder)) ||
                    (team.Formation.Strikers > players.Count(p => p.Position == PlayerPositionsEnum.Striker)))
                {
                    team.Formation = FormationData.GetRandomFormation();
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public static Formation GetRandomFormation()
 {
     return(FormationData.GetById(rnd.Next(1, FormationData.GetFormations().Count() + 1)));
 }