private static void CaseActions(string[] parts, Team team)
        {
            switch (parts[0])
            {
            case "Team":
                team.GiveName(parts[1]);
                break;

            case "Add":
                if (team.SameName(parts[1]))
                {
                    team.AddPlayers(parts);
                }
                break;

            case "Remove":
                team.RemovePlayers(parts[1], parts[2]);
                break;

            case "Rating":
                team.ShowRating(parts[1]);
                break;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                List <Team> teams   = new List <Team>();
                string      command = Console.ReadLine();
                while (command != "END")
                {
                    string[] teamInput = command.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);


                    switch (teamInput[0])
                    {
                    case "Team":
                        if (!teams.Any(t => t.Name == teamInput[1]))
                        {
                            teams.Add(new Team(teamInput[1]));
                        }
                        break;

                    case "Add":
                        try
                        {
                            Team team = teams.Where(t => t.Name == teamInput[1]).FirstOrDefault();
                            if (team == null)
                            {
                                throw new Exception($"Team {teamInput[1]} does not exist.");
                            }

                            team.AddPlayers(new Player(teamInput[2],
                                                       int.Parse(teamInput[3]),
                                                       int.Parse(teamInput[4]),
                                                       int.Parse(teamInput[5]),
                                                       int.Parse(teamInput[6]),
                                                       int.Parse(teamInput[7]))
                                            );
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        } break;

                    case "Remove":
                    {
                        try
                        {
                            Team team = teams.FirstOrDefault(t => t.Name == teamInput[1]);
                            if (team == null)
                            {
                                throw new Exception($"Team {teamInput[1]} does not exist.");
                            }
                            team.RemovePlayer(teamInput[2]);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        } break;
                    }

                    case "Rating":
                    {
                        try
                        {
                            Team team = teams.FirstOrDefault(t => t.Name == teamInput[1]);
                            if (team == null)
                            {
                                throw new Exception($"Team {teamInput[1]} does not exist.");
                            }

                            Console.WriteLine($"{team.Name} - {team.CalculateRating()}");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        } break;
                    }
                    }


                    command = Console.ReadLine();
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }