elena1234

PokemonTrainer - class Trainer

Feb 9th, 2021 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3.  
  4. namespace PokemonTrainer
  5. {
  6.     class Trainer
  7.     {
  8.         public Trainer(string name)
  9.         {
  10.             this.Name = name;
  11.             this.NumberOfBadges = 0;
  12.             this.CollectionOfPokemon = new List<Pokemon>();
  13.         }
  14.  
  15.         public Trainer(string name, List<Pokemon> collectionOfPokemon)
  16.             :this(name)
  17.         {
  18.             this.NumberOfBadges = 0;
  19.             this.CollectionOfPokemon = collectionOfPokemon;
  20.         }
  21.  
  22.         public string Name { get; set; }
  23.         public int NumberOfBadges { get; set; }
  24.         public List<Pokemon> CollectionOfPokemon { get; set; }
  25.  
  26.         public void AddPokemon(Pokemon pokemon)
  27.         {                    
  28.             this.CollectionOfPokemon.Add(pokemon);
  29.         }
  30.  
  31.         public void CheckTrainerForAddBadge(string element)
  32.         {
  33.             if (this.CollectionOfPokemon.Any(p => p.Element == element))
  34.             {
  35.                 this.NumberOfBadges++;
  36.             }
  37.         }
  38.        
  39.         public void CheckTrainerForReduceHealth(string element)
  40.         {
  41.             if (!this.CollectionOfPokemon.Any(p => p.Element == element))
  42.             {
  43.                 foreach (Pokemon pokemon in this.CollectionOfPokemon)
  44.                 {
  45.                     pokemon.Health -= 10;
  46.                 }
  47.             }
  48.         }
  49.  
  50.         public void CheckTrainerForDeadPokemons()
  51.         {
  52.             this.CollectionOfPokemon = this.CollectionOfPokemon.Where(pokemon => pokemon.Health > 0).ToList();
  53.         }
  54.     }
  55. }
  56.  
Add Comment
Please, Sign In to add comment