Guest User

Pokemon

a guest
Jun 14th, 2020
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09.PokemonTrainer
  6. {
  7. public class StartUp
  8. {
  9. static void Main(string[] args)
  10. {
  11. string trainerInput = Console.ReadLine();
  12. Dictionary<string, Trainer> trainers = new Dictionary<string, Trainer>();
  13.  
  14. while (trainerInput != "Tournament")
  15. {
  16. string[] tokens = trainerInput.Split();
  17. string trainerName = tokens[0];
  18. string pokemonName = tokens[1];
  19. string pokemonElement = tokens[2];
  20. int pokemonHealth = int.Parse(tokens[3]);
  21. Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
  22.  
  23. if (!trainers.ContainsKey(trainerName))
  24. {
  25. Trainer trainer = new Trainer(trainerName);
  26. trainers.Add(trainerName, trainer);
  27. }
  28. trainers[trainerName].Pokemons.Add(pokemon);
  29.  
  30. trainerInput = Console.ReadLine();
  31. }
  32.  
  33. string elementInput = Console.ReadLine();
  34.  
  35.  
  36. while (elementInput != "End")
  37. {
  38. foreach ((string trainerName, Trainer trainer) in trainers)
  39. {
  40. if (trainer.Pokemons.Any(p => p.Element == elementInput))
  41. {
  42. trainer.NumberOfBadges++;
  43. }
  44. else
  45. {
  46. int count = trainer.Pokemons.Count;
  47. for (int i = 0; i < count; i++)
  48. {
  49. Pokemon pokemon = trainer.Pokemons[i];
  50. pokemon.Health -= 10;
  51.  
  52. if (pokemon.Health <= 0)
  53. {
  54. trainer.Pokemons.Remove(pokemon);
  55. // i--;
  56. }
  57.  
  58. }
  59. }
  60. }
  61.  
  62.  
  63. elementInput = Console.ReadLine();
  64. }
  65.  
  66. trainers = trainers.OrderByDescending(t => t.Value.NumberOfBadges)
  67. .ToDictionary(k => k.Key, v => v.Value);
  68.  
  69. foreach (var currentTrainer in trainers.OrderByDescending(x => x.Value.NumberOfBadges))
  70. {
  71. Console.WriteLine($"{currentTrainer.Value.Name} {currentTrainer.Value.NumberOfBadges} {currentTrainer.Value.Pokemons.Count}");
  72. }
  73. }
  74. }
  75. }
RAW Paste Data