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
- {
- static void Main(string[] args)
- {
- List<Trainer> allTrainers = new List<Trainer>();
- string inputLines = Console.ReadLine();
- while (inputLines?.ToLower() != "tournament")
- {
- string[] inputArray = inputLines.Split(" ", StringSplitOptions.RemoveEmptyEntries);
- string trainerName = inputArray[0];
- string pokemonName = inputArray[1];
- string pokemonElement = inputArray[2];
- int pokemonHealth = int.Parse(inputArray[3]);
- if (allTrainers.Any(x => x.Name == trainerName) == false)
- {
- allTrainers.Add(new Trainer(trainerName));
- }
- Trainer currentTrainer = allTrainers.Find(t => t.Name == trainerName);
- currentTrainer.Pokemons.Add(new Pokemon(pokemonName, pokemonElement, pokemonHealth));
- inputLines = Console.ReadLine();
- }
- string command = Console.ReadLine();
- while (command?.ToLower() != "end")
- {
- foreach (Trainer trainer in allTrainers)
- {
- if (trainer.Pokemons.Any(p => p.Element == command))
- {
- trainer.NumberOfBadges += 1;
- }
- else
- {
- for (int i = 0; i < trainer.Pokemons.Count; i++)
- {
- trainer.Pokemons[i].Health -= 10;
- if (trainer.Pokemons[i].Health <= 0)
- {
- trainer.Pokemons.RemoveAt(i);
- i--;
- }
- }
- }
- }
- command = Console.ReadLine();
- }
- foreach (Trainer trainer in allTrainers.OrderByDescending(t => t.NumberOfBadges))
- {
- Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.Pokemons.Count}");
- }
- }
- }
- public class Pokemon
- {
- public Pokemon(string name, string element, int health)
- {
- this.Name = name;
- this.Element = element;
- this.Health = health;
- }
- public string Name { get; set; }
- public string Element { get; set; }
- public int Health { get; set; }
- }
- public class Trainer
- {
- public Trainer(string name)
- {
- this.Name = name;
- this.Pokemons = new List<Pokemon>();
- NumberOfBadges = 0;
- }
- public string Name { get; set; }
- public int NumberOfBadges { get; set; }
- public List<Pokemon> Pokemons { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement