예제 #1
0
파일: Engine.cs 프로젝트: Ver7ebrA/Softuni
        public void AddPlayerToTeam(string teamName, Player player)
        {
            Team team = ValidateTeam(teamName);

            team.AddPlayer(player);
        }
예제 #2
0
        static void Main()
        {
            Dictionary <string, Team> teamsData = new Dictionary <string, Team>();
            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] tokens = input.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                string command = tokens[0];

                if (command == "Team")
                {
                    string teamName = tokens[1];

                    if (!teamsData.ContainsKey(teamName))
                    {
                        try
                        {
                            Team team = new Team(teamName);
                            teamsData.Add(teamName, team);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                else if (command == "Add")
                {
                    string teamName = tokens[1];

                    if (!teamsData.ContainsKey(teamName))
                    {
                        Console.WriteLine($"Team {teamName} does not exist.");
                        continue;
                    }

                    string playerName = tokens[2];
                    int    endurane   = int.Parse(tokens[3]);
                    int    sprint     = int.Parse(tokens[4]);
                    int    dribble    = int.Parse(tokens[5]);
                    int    passing    = int.Parse(tokens[6]);
                    int    shooting   = int.Parse(tokens[7]);

                    Player player = null;

                    try
                    {
                        Stats stats = new Stats(endurane, sprint, dribble, passing, shooting);
                        player = new Player(playerName, stats);

                        Team team = teamsData[teamName];
                        team.AddPlayer(player);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (command == "Remove")
                {
                    string teamName   = tokens[1];
                    string playerName = tokens[2];

                    if (teamsData.ContainsKey(teamName))
                    {
                        Team team = teamsData[teamName];
                        team.RemovePlayer(playerName);
                    }
                }
                else if (command == "Rating")
                {
                    string teamName = tokens[1];

                    if (!teamsData.ContainsKey(teamName))
                    {
                        Console.WriteLine($"Team {teamName} does not exist.");
                        continue;
                    }

                    Team team = teamsData[teamName];
                    Console.WriteLine($"{team.Name} - {Math.Round(team.Rating)}");
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            List <Team> teams = new List <Team>();

            while (true)
            {
                try
                {
                    string input = Console.ReadLine();

                    if (input == "END")
                    {
                        break;
                    }

                    List <string> inputInfo = input.Split(';').ToList();

                    string command  = inputInfo[0];
                    string teamName = inputInfo[1];

                    if (command == "Team")
                    {
                        teams.Add(new Team(teamName));
                    }
                    else if (command == "Add")
                    {
                        //"Add;{TeamName};{PlayerName};{Endurance};{Sprint};{Dribble};{Passing};{Shooting}"

                        string playerName = inputInfo[2];
                        int    endurance  = int.Parse(inputInfo[3]);
                        int    sprint     = int.Parse(inputInfo[4]);
                        int    dribble    = int.Parse(inputInfo[5]);
                        int    passing    = int.Parse(inputInfo[6]);
                        int    shooting   = int.Parse(inputInfo[7]);

                        Team foundTeam = teams.Where(x => x.Name == teamName).FirstOrDefault();

                        if (foundTeam != null)
                        {
                            Player playerToAdd = new Player(playerName, endurance, sprint, dribble, passing, shooting);

                            foundTeam.AddPlayer(playerToAdd);
                        }
                        else
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                    }
                    else if (command == "Remove")
                    {
                        string playerName = inputInfo[2];

                        Team foundTeam = teams.Where(x => x.Name == teamName).FirstOrDefault();

                        if (foundTeam != null)
                        {
                            foundTeam.RemovePlayer(playerName);
                        }
                        else
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                    }
                    else if (command == "Rating")
                    {
                        Team foundTeam = teams.Where(x => x.Name == teamName).FirstOrDefault();

                        if (foundTeam != null)
                        {
                            Console.WriteLine($"{teamName} - {foundTeam.Rating}");
                        }
                        else
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            string      command = Console.ReadLine();
            List <Team> teams   = new List <Team>();

            while (command != "END")
            {
                try
                {
                    string[] tokens = command.Split(";");

                    string action   = tokens[0];
                    string teamName = tokens[1];



                    if (action == "Team")
                    {
                        Team currentTeam = new Team(teamName);
                        teams.Add(currentTeam);
                    }
                    else if (action == "Add")
                    {
                        Team currentTeam = teams.FirstOrDefault(t => t.Name == teamName);

                        if (teams.Contains(currentTeam))
                        {
                            string player    = tokens[2];
                            int    endurance = int.Parse(tokens[3]);
                            int    sprint    = int.Parse(tokens[4]);
                            int    dribble   = int.Parse(tokens[5]);
                            int    passing   = int.Parse(tokens[6]);
                            int    shooting  = int.Parse(tokens[7]);

                            Stat   currentStat = new Stat(endurance, sprint, dribble, passing, shooting);
                            Player newPlayer   = new Player(player, currentStat);
                            if (teams.Contains(currentTeam))
                            {
                                currentTeam.AddPlayer(newPlayer);
                            }
                            //else if (!teams.Contains(currentTeam))
                            //{
                            //    teams.Add(currentTeam);
                            //    currentTeam.AddPlayer(newPlayer);
                            //}
                            else
                            {
                                throw new InvalidOperationException(string.Format(ExceptionMessages.MissingTeam, teamName));
                            }
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(ExceptionMessages.MissingTeam, teamName));
                        }
                    }
                    else if (action == "Remove")
                    {
                        string playerName = tokens[2];


                        Team teamForPlayerToRemove = teams.FirstOrDefault(t => t.Name == teamName);

                        if (teamForPlayerToRemove == null)
                        {
                            throw new InvalidOperationException(string.Format(ExceptionMessages.MissingTeam, teamName));
                        }
                        else
                        {
                            teamForPlayerToRemove.RemovePlayer(playerName);
                        }
                    }
                    else if (action == "Rating")
                    {
                        Team teamForRating = teams.FirstOrDefault(t => t.Name == teamName);

                        if (teamForRating != null)
                        {
                            Console.WriteLine($"{teamForRating.Name} - {teamForRating.Rating}");
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format(ExceptionMessages.MissingTeam, teamName));
                        }
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }


                command = Console.ReadLine();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            while (input[0] != "END")
            {
                string teamName = input[1];

                if (input[0] == "Team")
                {
                    Team team = new Team(teamName);
                    teams.Add(team);
                }
                else if (input[0] == "Add")
                {
                    string playerName = input[2];
                    int    endurance  = int.Parse(input[3]);
                    int    sprint     = int.Parse(input[4]);
                    int    dribble    = int.Parse(input[5]);
                    int    passing    = int.Parse(input[6]);
                    int    shooting   = int.Parse(input[7]);
                    try
                    {
                        Team   team   = GetTeam(teamName);
                        Player player = new Player(playerName, endurance, sprint, dribble, passing, shooting);
                        team.AddPlayer(player);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (input[0] == "Remove")
                {
                    string playerName = input[2];
                    try
                    {
                        Team team = GetTeam(teamName);
                        team.RemovePlayer(playerName);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (input[0] == "Rating")
                {
                    try
                    {
                        Team team = GetTeam(teamName);
                        Console.WriteLine(team);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                input = Console.ReadLine().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }


            Console.ReadLine();
        }
예제 #6
0
        public static void Main()
        {
            HashSet <Team> teams = new HashSet <Team>();
            string         input = Console.ReadLine();

            while (input != "END")
            {
                try
                {
                    string[] tokens  = input.Split(";", StringSplitOptions.RemoveEmptyEntries);
                    string   command = tokens[0];
                    string   name    = tokens[1];
                    if (command == "Team")
                    {
                        Team team = new Team(name);
                        teams.Add(team);
                    }
                    else if (command == "Add")
                    {
                        string playerName = tokens[2];
                        int    endurance  = int.Parse(tokens[3]);
                        int    sprint     = int.Parse(tokens[4]);
                        int    dribble    = int.Parse(tokens[5]);
                        int    passing    = int.Parse(tokens[6]);
                        int    shooting   = int.Parse(tokens[7]);
                        Team   current    = teams.FirstOrDefault(t => t.Name == name);
                        if (current == null)
                        {
                            throw new ArgumentException($"Team {name} does not exist.");
                        }

                        Player player = new Player(playerName, endurance, sprint, dribble, passing, shooting);
                        current.AddPlayer(player);
                    }
                    else if (command == "Remove")
                    {
                        string playerName = tokens[2];
                        Team   current    = teams.FirstOrDefault(t => t.Name == name);
                        if (current == null)
                        {
                            throw new ArgumentException($"Team {name} does not exist.");
                        }

                        current.RemovePlayer(playerName);
                    }
                    else if (command == "Rating")
                    {
                        Team current = teams.FirstOrDefault(t => t.Name == name);
                        if (current == null)
                        {
                            throw new ArgumentException($"Team {name} does not exist.");
                        }

                        Console.WriteLine($"{name} - {current.Rating}");
                    }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }

                input = Console.ReadLine();
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            string      input = Console.ReadLine();
            List <Team> teams = new List <Team>();


            while (input != "END")
            {
                string[] currentInput = input.Split(";", StringSplitOptions.RemoveEmptyEntries);


                if (currentInput[0] == "Team")
                {
                    Team team = new Team(currentInput[1]);
                    teams.Add(team);
                }
                else if (currentInput[0] == "Add")
                {
                    string teamName   = currentInput[1];
                    string playerName = currentInput[2];
                    double stats1     = double.Parse(currentInput[3]);
                    double stats2     = double.Parse(currentInput[4]);
                    double stats3     = double.Parse(currentInput[5]);
                    double stats4     = double.Parse(currentInput[6]);
                    double stats5     = double.Parse(currentInput[7]);
                    if (teams.Any(x => x.Name == teamName))
                    {
                        Team team = teams.FirstOrDefault(x => x.Name == teamName);

                        try
                        {
                            Stats  playerStats = new Stats(stats1, stats2, stats3, stats4, stats5);
                            Player player      = new Player(playerName, playerStats);
                            team.AddPlayer(player);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Team {teamName} does not exist.");
                    }
                }
                else if (currentInput[0] == "Remove")
                {
                    string teamName   = currentInput[1];
                    string playerName = currentInput[2];
                    if (teams.Where(x => x.Name == teamName).Count() > 0)
                    {
                        Team team = teams.FirstOrDefault(x => x.Name == teamName);

                        team.RemovePlayer(playerName);
                    }
                }
                else if (currentInput[0] == "Rating")
                {
                    string teamName = currentInput[1];
                    if (teams.Any(x => x.Name == teamName))
                    {
                        if (teams.Where(x => x.Name == teamName).Count() > 0)
                        {
                            Team team = teams.FirstOrDefault(x => x.Name == teamName);
                            Console.WriteLine($"{team.Name} - {team.Rating:f0}");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Team {teamName} does not exist.");
                    }
                }

                input = Console.ReadLine();
            }
        }