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; }
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); }
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(); } }