Ejemplo n.º 1
0
    public static void Main()
    {
        List <Trainer> allTrainers = new List <Trainer>();

        while (true)
        {
            string[] input = Console.ReadLine().Split();

            if (input[0] == "Tournament")
            {
                break;
            }

            string trainerName    = input[0];
            string pokemonName    = input[1];
            string pokemonElement = input[2];
            int    pokemonHealth  = int.Parse(input[3]);
            var    currentPokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

            if (!allTrainers.Any(t => t.Name == trainerName))
            {
                var newTrainer = new Trainer(trainerName);
                newTrainer.AddPokemon(currentPokemon);
                allTrainers.Add(newTrainer);
            }
            else
            {
                var currentTrainer = allTrainers.FirstOrDefault(t => t.Name == trainerName);
                currentTrainer.OwnPokemons.Add(currentPokemon);
            }
        }

        while (true)
        {
            string element = Console.ReadLine();

            if (element == "End")
            {
                break;
            }

            foreach (var trainer in allTrainers)
            {
                if (trainer.OwnPokemons.Any(p => p.Element == element))
                {
                    trainer.AddBadge();
                }
                else
                {
                    trainer.ReduceAllPokemonsHealth();
                    trainer.RemoveDeadPokemons();
                }
            }
        }

        foreach (var trainer in allTrainers.OrderByDescending(t => t.BadgesCount))
        {
            Console.WriteLine(trainer);
        }
    }
    private static void SetInfoToTheData(Dictionary <string, Trainer> trainersData)
    {
        while (true)
        {
            var cmdArgs = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (cmdArgs[0] == "Tournament")
            {
                break;
            }

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

            var currentPokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

            if (trainersData.ContainsKey(trainerName))
            {
                trainersData[trainerName].AddPokemon(currentPokemon);
                continue;
            }
            var currentTrainer = new Trainer(trainerName);
            currentTrainer.AddPokemon(currentPokemon);
            trainersData[trainerName] = currentTrainer;
        }
    }
Ejemplo n.º 3
0
    private static void AddPokemonToTrainer(string[] data, Trainer trainer)
    {
        var pokemonName = data[1];
        var element     = data[2];
        var health      = int.Parse(data[3]);
        var pokemon     = new Pokemon(pokemonName, element, health);

        trainer.AddPokemon(pokemon);
    }
Ejemplo n.º 4
0
    static void Main(string[] args)
    {
        string         inputLine;
        List <Trainer> trainers = new List <Trainer>();

        while ((inputLine = Console.ReadLine()) != "Tournament")
        {
            string[] tokens = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                              .ToArray();

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

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

            if (trainers.All(t => t.Name != trainerName))
            {
                trainers.Add(trainer);
            }

            trainer = trainers.FirstOrDefault(p => p.Name == trainerName);
            trainer.AddPokemon(pokemon);
        }

        while ((inputLine = Console.ReadLine()) != "End")
        {
            string element = inputLine;

            for (int i = 0; i < trainers.Count; i++)
            {
                if (trainers[i].Pokemons.Any(p => p.Element == element))
                {
                    trainers[i].NumberOfBadges++;
                }
                else
                {
                    for (int j = 0; j < trainers[i].Pokemons.Count; j++)
                    {
                        trainers[i].Pokemons[j].Health -= 10;
                        if (trainers[i].Pokemons[j].Health <= 0)
                        {
                            trainers[i].Pokemons.RemoveAt(j);
                        }
                    }
                }
            }
        }

        foreach (var trainer in trainers.OrderByDescending(t => t.NumberOfBadges))
        {
            Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.Pokemons.Count}");
        }
    }
Ejemplo n.º 5
0
    static void Main()
    {
        var line = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

        while (line[0] != "Tournament")
        {
            Pokemon pokemon = new Pokemon(line[1], line[2], double.Parse(line[3]));
            Trainer trainer = new Trainer(line[0]);

            if (trainers.ContainsKey(line[0]))
            {
                trainers[line[0]].AddPokemon(pokemon);
            }
            else
            {
                trainer.AddPokemon(pokemon);
                trainers.Add(line[0], trainer);
            }

            line = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        var  element    = Console.ReadLine();
        bool takeDamage = true;

        while (element != "End")
        {
            foreach (var trainer in trainers)
            {
                foreach (var pokemon in trainer.Value.pokemons)
                {
                    if (pokemon.element == element)
                    {
                        trainer.Value.numberOfBadges++;
                        takeDamage = false;
                    }
                }
                if (takeDamage)
                {
                    trainer.Value.pokemons.ForEach(a => a.health -= 10);
                }
                trainer.Value.pokemons.RemoveAll(a => a.health <= 0);
                takeDamage = true;
            }


            element = Console.ReadLine();
        }

        foreach (var trainer in trainers.OrderByDescending(a => a.Value.numberOfBadges))
        {
            Console.WriteLine($"{trainer.Key} {trainer.Value.numberOfBadges} {trainer.Value.pokemons.Count}");
        }
    }
Ejemplo n.º 6
0
    static void Main()
    {
        string input = "";

        List <Trainer> trainers = new List <Trainer>();

        while ((input = Console.ReadLine()) != "Tournament")
        {
            string[] data        = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            string   trainerName = data[0];
            string   name        = data[1];
            string   element     = data[2];
            int      health      = int.Parse(data[3]);

            Pokemon newPokemon = new Pokemon(name, element, health);
            Trainer trainer    = trainers.FirstOrDefault(t => t.Name == trainerName);
            if (trainer == null)
            {
                Trainer newTrainer = new Trainer(trainerName, newPokemon);
                trainers.Add(newTrainer);
            }
            else
            {
                trainer.AddPokemon(newPokemon);
            }
        }
        while ((input = Console.ReadLine()) != "End")
        {
            foreach (Trainer trainer in trainers)
            {
                if (trainer.Pokemons.Any(p => p.Element == input))
                {
                    trainer.numberOfBadges++;
                }
                else
                {
                    int count = trainer.Pokemons.Count;
                    for (int i = 0; i < count; i++)
                    {
                        trainer.Pokemons[i].Health -= 10;
                        if (trainer.Pokemons[i].Health <= 0)
                        {
                            trainer.Pokemons.RemoveAt(i);
                            count--;
                        }
                    }
                }
            }
        }
        foreach (Trainer trainer in trainers.OrderByDescending(t => t.numberOfBadges))
        {
            Console.WriteLine($"{trainer.Name} {trainer.numberOfBadges} {trainer.Pokemons.Count}");
        }
    }
Ejemplo n.º 7
0
    public static void Main()
    {
        var trainers = new List <Trainer>();

        string input;

        while ((input = Console.ReadLine()) != "Tournament")
        {
            var inputParts = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var trainerName = inputParts[0];
            var pokemonName = inputParts[1];
            var element     = inputParts[2];
            var health      = int.Parse(inputParts[3]);

            var pokemon = new Pokemon(pokemonName, element, health);

            if (!trainers.Any(t => t.Name == trainerName))
            {
                var trainer = new Trainer(trainerName);
                trainer.AddPokemon(pokemon);
                trainers.Add(trainer);
            }
            else
            {
                trainers.FirstOrDefault(t => t.Name == trainerName).AddPokemon(pokemon);
            }
        }

        while ((input = Console.ReadLine()) != "End")
        {
            foreach (var trainer in trainers)
            {
                if (trainer.Pokemons.Any(x => x.Element == input))
                {
                    trainer.Badges++;
                }
                else
                {
                    trainer.Pokemons.ForEach(p => p.Health -= 10);
                    trainer.Pokemons.RemoveAll(p => p.Health <= 0);
                }
            }
        }

        trainers = trainers.OrderByDescending(t => t.Badges).ToList();

        foreach (var trainer in trainers)
        {
            Console.WriteLine(trainer.ToString());
        }
    }
Ejemplo n.º 8
0
    static void Main()
    {
        var trainers = new List <Trainer>();

        string command;

        while ((command = Console.ReadLine()) != "Tournament")
        {
            var pokemonInfo = command.Split();
            var trainerName = pokemonInfo[0];

            var pokemon = new Pokemon(pokemonInfo[1], pokemonInfo[2], int.Parse(pokemonInfo[3]));

            var trainer = trainers.FirstOrDefault(t => t.Name == trainerName);

            if (trainer == null)
            {
                trainer      = new Trainer();
                trainer.Name = trainerName;
                trainer.AddPokemon(pokemon);
                trainers.Add(trainer);
            }
            else
            {
                trainer.AddPokemon(pokemon);
            }
        }

        while ((command = Console.ReadLine()) != "End")
        {
            switch (command)
            {
            case "Fire":
                ProceedCommand(command, trainers);
                break;

            case "Water":
                ProceedCommand(command, trainers);
                break;

            case "Electricity":
                ProceedCommand(command, trainers);
                break;

            default:
                break;
            }
        }

        PrintResult(trainers);
    }
Ejemplo n.º 9
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]);

            //pokemon = new Pokemon(tokens[1], tokens[2], int.Parse(tokens[3]));

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

            Trainer currentTrainer = trainers.First(t => t.Name == trainerName);
            Pokemon pokemon        = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
            currentTrainer.AddPokemon(pokemon);
        }

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

        var currentTrainers = trainers.OrderByDescending(t => t.Badges).ToList();

        foreach (var trainer in currentTrainers)
        {
            Console.WriteLine("{0} {1} {2}", trainer.Name, trainer.Badges, trainer.Pokemons.Count);
        }
    }
Ejemplo n.º 10
0
    static void Main(string[] args)
    {
        List <Trainer> trainers = new List <Trainer>();

        string lines;

        while ((lines = Console.ReadLine()) != "Tournament")
        {
            string[] tokens = lines.Split(new char[] { ' ' }, 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) == false)
            {
                Trainer trainerInfo = new Trainer(trainerName);
                trainers.Add(trainerInfo);
            }

            Trainer trainer     = trainers.First(t => t.Name == trainerName);
            Pokemon pokemonInfo = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
            trainer.AddPokemon(pokemonInfo);
        }

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

        foreach (var trainer in trainers.OrderByDescending(t => t.Badges))
        {
            Console.WriteLine(trainer);
        }
    }
    static void Main(string[] args)
    {
        var    trainers = new List <Trainer>();
        string input;

        while ((input = Console.ReadLine()) != "Tournament")
        {
            var lineParts      = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            var trainerName    = lineParts[0];
            var pokemonName    = lineParts[1];
            var pokemonElement = lineParts[2];
            var pokemonHealth  = int.Parse(lineParts[3]);

            var newPokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

            if (!trainers.Any(x => x.name == trainerName))
            {
                var newTrainer = new Trainer(trainerName);
                newTrainer.AddPokemon(newPokemon);
                trainers.Add(newTrainer);
            }
            else
            {
                trainers.FirstOrDefault(x => x.name == trainerName).AddPokemon(newPokemon);
            }
        }

        string command;

        while ((command = Console.ReadLine()) != "End")
        {
            var currentElement = command;

            foreach (var trainer in trainers)
            {
                if (trainer.CheckForPokemon(currentElement))
                {
                    trainer.AddBadge();
                }
                else
                {
                    trainer.DecreaseHealth();
                }
            }
        }

        Console.WriteLine(string.Join(Environment.NewLine, trainers.OrderByDescending(x => x.badges)));
    }
Ejemplo n.º 12
0
    static void Main(string[] args)
    {
        var            input    = Console.ReadLine();
        List <Trainer> trainers = new List <Trainer>();

        while (input != "Tournament")
        {
            var tokens         = input.Split();
            var trainer        = tokens[0];
            var pokemonName    = tokens[1];
            var pokemonElement = tokens[2];
            var pokemonHealth  = int.Parse(tokens[3]);
            if (!trainers.Any(t => t.Name == trainer))
            {
                trainers.Add(new Trainer(trainer));
            }
            Pokemon pokemon     = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
            Trainer trainerName = trainers.First(t => t.Name == trainer);
            trainerName.AddPokemon(pokemon);
            input = Console.ReadLine();
        }

        var command = Console.ReadLine();

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

        foreach (var trainer in trainers.OrderByDescending(b => b.Badges))
        {
            Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemon.Count}");
        }
    }
Ejemplo n.º 13
0
    static void Main(string[] args)
    {
        var trainers = new List <Trainer>();

        string input;

        while ((input = Console.ReadLine()) != "Tournament")
        {
            var tokens = input.Split();

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

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

            Pokemon pokemon = new Pokemon(pokemonName, pokemontElement, pokemonHealth);
            Trainer trainer = trainers.First(t => t.Name == trainerName);
            trainer.AddPokemon(pokemon);
        }

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

        foreach (var trainer in trainers.OrderByDescending(t => t.Badges))
        {
            Console.WriteLine(trainer);
        }
    }
Ejemplo n.º 14
0
 public void ConfirmAdd()
 {
     trainer.AddPokemon(pokemon);
     opponent.AddPokemon(1 - pokemon);
 }
Ejemplo n.º 15
0
    static void Main(string[] args)
    {
        var input = Console.ReadLine();

        var trainers = new List <Trainer>();

        while (input != "Tournament")
        {
            var tokens = input
                         .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var name = tokens[0];

            Trainer currentTrainer;
            var     currentPokemon = new Pokemon(tokens[1], tokens[2],
                                                 double.Parse(tokens[3]));

            if (trainers.Any(t => t.Name == name))
            {
                currentTrainer = trainers.First(t => t.Name == name);
                currentTrainer.AddPokemon(currentPokemon);
            }
            else
            {
                currentTrainer = new Trainer(name);
                currentTrainer.AddPokemon(currentPokemon);
                trainers.Add(currentTrainer);
            }

            input = Console.ReadLine();
        }

        var command = Console.ReadLine();

        while (command != "End")
        {
            for (int i = 0; i < trainers.Count; i++)
            {
                var trainer = trainers[i];

                if (trainer.Pokemons.Any(p => p.Element == command))
                {
                    trainer.Badgets += 1;
                }
                else
                {
                    for (int j = 0; j < trainer.Pokemons.Count; j++)
                    {
                        var currentPokemon = trainer.Pokemons[j];

                        if (currentPokemon.Health - 10 <= 0)
                        {
                            trainer.Pokemons.RemoveAt(j);
                        }
                        else
                        {
                            trainer.Pokemons[j].Health -= 10;
                        }
                    }
                }
            }

            command = Console.ReadLine();
        }

        trainers = trainers
                   .OrderByDescending(t => t.Badgets)
                   .ToList();

        foreach (var trainer in trainers)
        {
            Console.WriteLine(trainer);
        }
    }
        public static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainersByName = new Dictionary <string, Trainer> {
            };

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                string[] partitions = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                //this is unique!
                string trainerName = partitions[0];
                string pokeName    = partitions[1];
                string pokeElement = partitions[2];
                int    pokeHealth  = int.Parse(partitions[3]);


                Pokemon currentPoke = new Pokemon(pokeName, pokeElement, pokeHealth);



                if (!trainersByName.ContainsKey(trainerName))
                {
                    Trainer trainer = new Trainer(trainerName);
                    trainer.AddPokemon(currentPoke);

                    trainersByName.Add(trainer.Name, trainer);
                }

                else
                {
                    var currentTrainer = trainersByName.Select(t => t.Value).FirstOrDefault(t => t.Name == trainerName);

                    if (!currentTrainer.Pokemons.Any(p => p.Name == currentPoke.Name))
                    {
                        currentTrainer.AddPokemon(currentPoke);
                    }
                }

                input = Console.ReadLine();
            }

            string element = Console.ReadLine();

            while (element != "End")
            {
                foreach (var kvp in trainersByName)
                {
                    var trainer = kvp.Value;

                    if (trainer.HasAnyPokemonsWithElement(element))
                    {
                        trainer.RecieveBadge();
                    }
                    else
                    {
                        trainer.PokemonesLoseHP();
                        trainer.ClearDeadPokemons();
                    }
                }

                element = Console.ReadLine();
            }

            List <Trainer> trainers = trainersByName.Select(t => t.Value).OrderByDescending(t => t.NumberOfBadges).ToList();

            foreach (var trainer in trainers)
            {
                Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.Pokemons.Count}");
            }
        }