예제 #1
0
        private static void AddPlayer(string[] cmdLine, List <Team> teams)
        {
            var teamName   = cmdLine[1];
            var playerName = cmdLine[2];

            if (!teams.Exists(t => t.Name == teamName))
            {
                Console.WriteLine($"Team {teamName} does not exist.");
            }
            try
            {
                var  stats     = new List <Stat>();
                Stat endurance = new Endurance(int.Parse(cmdLine[3]));
                stats.Add(endurance);
                Stat sprint = new Sprint(int.Parse(cmdLine[4]));
                stats.Add(sprint);
                Stat dribble = new Dribble(int.Parse(cmdLine[5]));
                stats.Add(dribble);
                Stat passing = new Passing(int.Parse(cmdLine[6]));
                stats.Add(passing);
                Stat shooting = new Shooting(int.Parse(cmdLine[7]));
                stats.Add(shooting);

                Player player = new Player(playerName);
                player.Stats = stats;

                teams.FirstOrDefault(t => t.Name == teamName).AddPlayer(player);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        public Player(string playerName, Endurance endurance, Sprint sprint, Dribble dribble, Passing passing, Shooting shooting)
        {
            Name      = playerName;
            Endurance = endurance;
            Sprint    = sprint;
            Dribble   = dribble;
            Passing   = passing;
            Shooting  = shooting;

            skillLevel = (Endurance.Level + Sprint.Level + Dribble.Level + Passing.Level + Shooting.Level) / 5;

            SkillLevel = skillLevel;
        }
예제 #3
0
        private static void CreateAndAddPlayer(List <Team> teams, string[] data)
        {
            var player   = new Player(data[2]);
            var currTeam = teams.FirstOrDefault(t => t.Name == data[1]);

            if (currTeam == null)
            {
                throw new ArgumentException($"Team {data[1]} does not exist.");
            }
            IStat endurance = new Endurance(int.Parse(data[3]));
            IStat sprint    = new Sprint(int.Parse(data[4]));
            IStat dribble   = new Dribble(int.Parse(data[5]));
            IStat passing   = new Passing(int.Parse(data[6]));
            IStat shooting  = new Shooting(int.Parse(data[7]));

            player.AddStats(endurance, sprint, dribble, passing, shooting);
            currTeam.AddPlayer(player);
        }
예제 #4
0
        static void Main(string[] args)
        {
            List <Team> teams = new List <Team>();

            string input = Console.ReadLine();

            while (input != "END")
            {
                string[] arrInput = input.Split(";");

                string teamName = arrInput[1];

                try
                {
                    switch (arrInput[0])
                    {
                    case "Team":
                        teams.Add(new Team(teamName));
                        break;

                    case "Add":
                        string    playerName = arrInput[2];
                        Endurance endurance  = new Endurance(byte.Parse(arrInput[3]));
                        Sprint    sprint     = new Sprint(byte.Parse(arrInput[4]));
                        Dribble   dribble    = new Dribble(byte.Parse(arrInput[5]));
                        Passing   passing    = new Passing(byte.Parse(arrInput[6]));
                        Shooting  shooting   = new Shooting(byte.Parse(arrInput[7]));

                        int counter = 0;

                        foreach (var team in teams)
                        {
                            if (team.Name == teamName)
                            {
                                Player player = new Player(playerName, endurance, sprint, dribble, passing, shooting);

                                team.AddPlayer(player);
                                counter++;
                            }
                        }
                        if (counter == 0)
                        {
                            Console.WriteLine($"Team {teamName} does not exist.");
                        }
                        break;

                    case "Remove":
                        string playerNamee = arrInput[2];
                        int    counterr    = 0;
                        foreach (var team in teams)
                        {
                            if (team.Name == teamName)
                            {
                                foreach (var player in team.players)
                                {
                                    if (player.Name == playerNamee)
                                    {
                                        team.RemovePlayer(player);
                                        counterr++;
                                        break;
                                    }
                                }
                                if (counterr == 0)
                                {
                                    Console.WriteLine($"Player {playerNamee} is not in {team.Name} team.");
                                }
                            }
                        }
                        break;

                    case "Rating":
                        int counterrr = 0;

                        foreach (var team in teams)
                        {
                            if (team.Name == teamName)
                            {
                                Console.WriteLine($"{team.Name} - {team.Rating}");
                                counterrr++;
                                break;
                            }
                        }

                        if (counterrr == 0)
                        {
                            Console.WriteLine($"Team {teamName} does not exist.");
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();
            }
        }