Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DefiningClasses
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- var allTrainers = new List<Trainer>();
- string input;
- while (!(input = Console.ReadLine()).Equals("Tournament"))
- {
- var tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var trainerName = tokens[0];
- var pokemonName = tokens[1];
- var pokemonElement = tokens[2];
- var pokemonHealth = int.Parse(tokens[3]);
- if (!allTrainers.Any(p => p.GetName().Equals(trainerName)))
- {
- allTrainers.Add(new Trainer(trainerName));
- }
- allTrainers.First(p => p.GetName().Equals(trainerName))
- .AddPokemon(new Pokemon(pokemonName, pokemonElement, pokemonHealth));
- }
- while (!(input = Console.ReadLine()).Equals("End"))
- {
- foreach (var trainer in allTrainers)
- {
- if (trainer.HAsElement(input))
- {
- trainer.AddBadge();
- }
- else
- {
- trainer.DecreaseHealth();
- }
- }
- }
- allTrainers.OrderByDescending(p => p.GetBadges()).ToList().ForEach(Console.WriteLine);
- }
- }
- }
- namespace DefiningClasses
- {
- internal class Pokemon
- {
- private readonly string _name;
- private readonly string _element;
- private int _health;
- public Pokemon(string name, string element, int health)
- {
- _name = name;
- _element = element;
- Health = health;
- }
- public int Health
- {
- get => _health;
- set => _health = value;
- }
- public string GetElement()
- {
- return _element;
- }
- }
- }
- using System.Collections.Generic;
- using System.Linq;
- namespace DefiningClasses
- {
- internal class Trainer
- {
- private readonly string _name;
- private int _badges;
- private List<Pokemon> _pokemonList;
- public Trainer(string name)
- {
- _name = name;
- _badges = 0;
- _pokemonList = new List<Pokemon>();
- }
- public int GetBadges()
- {
- return _badges;
- }
- public string GetName()
- {
- return _name;
- }
- public void AddBadge()
- {
- _badges++;
- }
- public void AddPokemon(Pokemon pokemon)
- {
- _pokemonList.Add(pokemon);
- }
- public void DecreaseHealth()
- {
- _pokemonList.ForEach(p => p.Health -= 10);
- _pokemonList = _pokemonList.Where(p => p.Health > 0).ToList();
- }
- public bool HAsElement(string element)
- {
- return _pokemonList.Any(p => p.GetElement().Equals(element));
- }
- public override string ToString()
- {
- return $"{_name} {_badges} {_pokemonList.Count}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement