Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Xml.Serialization;
- using System.IO;
- using System.Threading.Tasks;
- namespace AzerothLibrary
- {
- public delegate void Reinforcement(object sender, SupportEventArgs e);
- public class AllianceArmy
- {
- public event Reinforcement WeNeedReinforcement;
- List<IUnit> units;
- public void Add(IUnit unit)
- {
- units.Add(unit);
- }
- public IEnumerable<IUnit> Mages()
- {
- foreach (var unit in units)
- if (unit is Wizard && (unit as Wizard).mana >= 20)
- yield return unit;
- }
- public IEnumerable<IUnit> Healthy(int hp)
- {
- foreach (var unit in units)
- if (unit.hp >= hp)
- yield return unit;
- }
- public void SendReinforcement(object sender, SupportEventArgs e)
- {
- }
- public void AskReinforcement(object sender, SupportEventArgs e)
- {
- Console.WriteLine("Asking for reinforcement...");
- ReinforcementJoin(e.path, e.Count);
- }
- public void ReinforcementJoin(string path, int count)
- {
- XmlSerializer xm = new XmlSerializer(typeof(List<IUnit>));
- using (FileStream fs = File.OpenRead(path))
- {
- var newUnits = (List<IUnit>)xm.Deserialize(fs);
- for (int i = 0; i < count; i++)
- {
- units.Add(newUnits[i]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement