Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AzerothLibrary
  8. {
  9.     public delegate void Reinforcement(object sender, SupportEventArgs e);
  10.     public class AllianceArmy
  11.     {
  12.         public event Reinforcement WeNeedReinforcement;
  13.  
  14.         List<IUnit> units;
  15.         public void Add(IUnit unit)
  16.         {
  17.             units.Add(unit);
  18.         }
  19.         public IEnumerable<IUnit> Mages()
  20.         {
  21.             foreach (var unit in units)
  22.                 if (unit is Wizard && (unit as Wizard).mana >= 20)
  23.                     yield return unit;
  24.         }
  25.         public IEnumerable<IUnit> Healthy(int hp)
  26.         {
  27.             foreach (var unit in units)
  28.                 if (unit.hp >= hp)
  29.                     yield return unit;
  30.         }
  31.         public void SendReinforcement(object sender, SupportEventArgs e)
  32.         {
  33.  
  34.         }
  35.         public void AskReinforcement(object sender, SupportEventArgs e)
  36.         {
  37.             Console.WriteLine("Asking for reinforcement...");
  38.             ReinforcementJoin(e.path, e.Count);
  39.         }
  40.         public void ReinforcementJoin(string path, int count)
  41.         {
  42.             XmlSerializer xm = new XmlSerializer(typeof(List<IUnit>));
  43.             using (FileStream fs = File.OpenRead(path))
  44.             {
  45.                 var newUnits = (List<IUnit>)xm.Deserialize(fs);
  46.  
  47.                 for (int i = 0; i < count; i++)
  48.                 {
  49.                     units.Add(newUnits[i]);
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement