Пример #1
0
        public static void Main()
        {
            string command = string.Empty;

            School school = new School();

            while ((command = Console.ReadLine()) != "Tournament")
            {
                string[] splittedCommand = command
                                           .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string trainerName    = splittedCommand[0];
                string pokemonName    = splittedCommand[1];
                string pokemonElement = splittedCommand[2];
                int    pokemonHealth  = int.Parse(splittedCommand[3]);

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                Trainer trainer = new Trainer(trainerName);

                if (!school.IsTrainerExist(trainerName))
                {
                    school.AddTrainer(trainer);
                }

                school.GetTrainer(trainerName).AddPokemon(pokemon);
            }

            while ((command = Console.ReadLine()) != "End")
            {
                List <Trainer> isContentElement    = school.GetTrainersIsContentElement(command);
                List <Trainer> isNotContentElement = school.GetTrainersIsNotContentElement(command);

                foreach (var trainer in isContentElement)
                {
                    trainer.IncreaseBadges();
                }

                foreach (var trainer in isNotContentElement)
                {
                    foreach (var pokemon in trainer.Pokemons)
                    {
                        pokemon.DecreaseHealth();
                    }

                    trainer.RemoveDeadPokemons();
                }
            }

            school.Print();
        }
Пример #2
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();
            string         command;

            while ((command = Console.ReadLine()) != "Tournament")
            {
                var tokens = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string trainerName    = tokens[0];
                string pokemonName    = tokens[1];
                string pokemonElement = tokens[2];
                int    pokemonHealth  = int.Parse(tokens[3]);

                if (!trainers.Any(t => t.Name == trainerName))
                {
                    trainers.Add(new Trainer(trainerName));
                }

                Trainer trainer = trainers.First(t => t.Name == trainerName);

                trainer.AddPokemon(new Pokemon(pokemonName, pokemonElement, pokemonHealth));
            }

            while ((command = Console.ReadLine()) != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == command))
                    {
                        trainer.IncreaseBadges();
                    }
                    else
                    {
                        trainer.ReducePokemonsHealth();
                        trainer.RemoveDead();
                    }
                }
            }

            trainers
            .OrderByDescending(t => t.Badges)
            .ToList()
            .ForEach(Console.WriteLine);
        }