Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _08.PokemonTrainer
- {
- public class PokemonTrainer
- {
- public static void Main(string[] args)
- {
- List<Trainer> pokemonTrainers = new List<Trainer>();
- string inputLine = Console.ReadLine();
- while (inputLine != "Tournament")
- {
- string[] tokens = inputLine
- .Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
- string trainerName = tokens[0];
- string pokemonName = tokens[1];
- string pokemonType = tokens[2];
- int pokemonHealth = int.Parse(tokens[3]);
- Trainer currentTrainer = new Trainer(trainerName);
- Pokemon currentPokemon = new Pokemon(pokemonName, pokemonType, pokemonHealth);
- currentTrainer.Pokemons.Add(currentPokemon);
- bool wasAdded = false;
- foreach (var trainer in pokemonTrainers)
- {
- if (trainer.Name == trainerName)
- {
- trainer.Pokemons.Add(currentPokemon);
- wasAdded = true;
- break;
- }
- }
- if (!wasAdded)
- pokemonTrainers.Add(currentTrainer);
- inputLine = Console.ReadLine();
- }
- inputLine = Console.ReadLine();
- while (inputLine != "End")
- {
- string type = inputLine;
- for (int i = 0; i < pokemonTrainers.Count; i++)
- {
- Trainer currentTrainer = pokemonTrainers[i];
- if (currentTrainer.ContainsType(type))
- currentTrainer.NumberOfBadges++;
- else
- {
- currentTrainer.DecreaseHealth();
- currentTrainer.RemoveDeadPokemons();
- }
- }
- inputLine = Console.ReadLine();
- }
- pokemonTrainers = pokemonTrainers.OrderByDescending(trainer => trainer.NumberOfBadges).ToList();
- foreach (var trainer in pokemonTrainers)
- {
- trainer.PrintTrainerInfo();
- }
- }
- }
- public class Pokemon
- {
- public string Name;
- public string Type;
- public int Health;
- public Pokemon(string name, string type, int health)
- {
- Name = name;
- Type = type;
- Health = health;
- }
- }
- public class Trainer
- {
- public string Name;
- public int NumberOfBadges;
- public List<Pokemon> Pokemons;
- public Trainer(string name)
- {
- Name = name;
- NumberOfBadges = 0;
- Pokemons = new List<Pokemon>();
- }
- public bool ContainsType(string type)
- {
- foreach (var pokemon in Pokemons)
- {
- if (pokemon.Type == type)
- {
- return true;
- }
- }
- return false;
- }
- public void DecreaseHealth()
- {
- for (int i = 0; i < Pokemons.Count; i++)
- {
- Pokemons[i].Health -= 10;
- }
- }
- public void RemoveDeadPokemons()
- {
- Pokemons = Pokemons.Where(pokemon => pokemon.Health > 0).ToList();
- }
- public void PrintTrainerInfo()
- {
- Console.WriteLine("{0} {1} {2}", Name, NumberOfBadges, Pokemons.Count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement