Ejemplo n.º 1
0
        public static bool TryParsePlayer(string playerInfo, Team team, Tournament tournament)
        {
            var   pattern = new Regex("(?<name>.*) (?<age>\\d+) (?<sex>(male|female)) (?<weight>\\d+) (?<height>\\d+)");
            Match match   = pattern.Match(playerInfo);

            if (match.Success)
            {
                if (!tournament.PlayerExists(match.Groups["name"].Value))
                {
                    Sex sex       = (match.Groups["sex"].Value == "male") ? Sex.Male : Sex.Female;
                    var newPlayer = new Player(match.Groups["name"].Value, int.Parse(match.Groups["age"].Value), sex, int.Parse(match.Groups["weight"].Value), int.Parse(match.Groups["height"].Value), team.Name);
                    tournament.AddPlayer(newPlayer);
                    team.AddPlayer(newPlayer);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public async Task AddPlayersFromFile()
        {
            string categoryName = StaticMethods.GetCategoryName(tournament, "Write name of category where you want to add player:");

            string path;

            while (true)
            {
                Console.WriteLine("'0' - Back");
                Console.WriteLine("Write file name in JSON (ex. CuncaMuzi.json): ");

                lineToRead = Console.ReadLine();

                if (lineToRead.Length != 0)
                {
                    if (lineToRead == "0")
                    {
                        return;
                    }
                    else
                    {
                        path = @"..\..\\InputData\" + lineToRead;
                        if (File.Exists(path))
                        {
                            break;
                        }
                        Console.WriteLine("File name does not exist!");
                    }
                }
            }
            var teams = await Task.Run(() => JsonConvert.DeserializeObject <List <Team> >(File.ReadAllText(path)));

            foreach (var team in teams)
            {
                tournament.AddTeamToCategory(team, categoryName);
                foreach (var player in team.players)
                {
                    tournament.AddPlayer(player);
                }
            }

            Console.WriteLine("Adding players from file was successful!");
        }