public override void Use(List <Field> targets, double coeficient) { foreach (Field Field in targets) { Field.Register(ObserverFactory.GetInstance().RequestObserver(TrapSkill, Field.x, Field.y), false); } }
public static ObserverFactory GetInstance() { if (Instance == null) { Instance = new ObserverFactory(); } return(Instance); }
public BattleController(Battlefield Battlefield) { this.Over = false; ObserverFactory.GetInstance().Init(this); this.Battlefield = Battlefield; this.CommandStackNormal = new Stack <BattlefieldMemento>(); this.CommandStackReverse = new Stack <BattlefieldMemento>(); this.RefreshBattleField = false; this.KeepRenderingBattleField(); }
public void AddHero(HeroInterface Hero, int x, int y) { Field Field = GetField(x, y); if (Field != null) { this.Heroes.Add(Hero); Field.SetHero(Hero); List <Skill> PassiveSkills = Hero.GetAllPasiveSkills(); foreach (Skill Skill in PassiveSkills) { Hero.GetHealthStat().Register(ObserverFactory.GetInstance().RequestObserver(Skill, Hero), false); } Hero.GetHealthStat().Register(ObserverFactory.GetInstance().RequestObserver(Hero), true); } }
private void ReceiveCommands() { this.HeroQueue = this.Battlefield.GetAllHeroes(); this.CommandStackNormal.Push(this.Battlefield.CreateMemento()); this.RenderBattleField(); String CommandInput; String[] Tokens; while (true) { CommandInput = Console.ReadLine(); Tokens = CommandInput.Split(' '); switch (Tokens[0]) { case "move": if (Tokens.Length != 2) { Console.WriteLine("Invalid syntax"); continue; } List <(int, int)> Coordinates = new List <(int, int)>(); int start_x = this.HeroQueue.First().GetCoordinates()[0]; int start_y = this.HeroQueue.First().GetCoordinates()[1]; if (Tokens[1].Split(',').Count() != 2) { Console.WriteLine("Invalid syntax"); continue; } int end_x = int.Parse(Tokens[1].Split(',')[0]); int end_y = int.Parse(Tokens[1].Split(',')[1]); int x_incerement = start_x < end_x ? 1 : -1; int y_incerement = start_y < end_y ? 1 : -1; int i = start_x; int j = start_y; while (i != end_x) { Coordinates.Add((i, j)); i += x_incerement; } while (j != end_y) { Coordinates.Add((i, j)); j += y_incerement; } Coordinates.Add((i, j)); Console.WriteLine(Coordinates.Count + " coordinates"); Command MoveCommand = new CommandMove(Coordinates); lock (Refreshlock) { RefreshBattleField = true; Monitor.PulseAll(Refreshlock); } this.ExecuteCommand(MoveCommand); lock (Refreshlock) { RefreshBattleField = false; } Thread.Sleep(500); this.RenderBattleField(); break; case "skill": if (Tokens.Length != 3) { Console.WriteLine("Invalid syntax - need 3 params"); continue; } int SkillID = -1; if (!int.TryParse(Tokens[1], out SkillID)) { Console.WriteLine("Invalid syntax - param 1 must be integer"); continue; } Skill Skill = HeroQueue.First().GetSkill(SkillID); if (Skill == null) { Console.WriteLine("Skill with id " + SkillID + " does not exist"); continue; } if (Skill.Passive) { Console.WriteLine("Cannot actively use passive skill"); continue; } ITriggerBehaviour TargetingStrategy = null; switch (Tokens[2]) { case "one": TargetingStrategy = SelectOneTarget.GetInstance(); break; case "auto": TargetingStrategy = SelectAutoTarget.GetInstance(); break; case "area": TargetingStrategy = SelectArea.GetInstance(); break; case "self": TargetingStrategy = SelectSelf.GetInstance(); break; default: break; } if (TargetingStrategy == null) { Console.WriteLine("Invalid target strategy option"); continue; } Command UseSkillCommand = new CommandUseSkill(Skill, Battlefield.GetField(HeroQueue.First().GetCoordinates()[0], HeroQueue.First().GetCoordinates()[1]), TargetingStrategy); this.ExecuteCommand(UseSkillCommand); this.RenderBattleField(); break; case "gather": Command GatherCommand = new CommandGather(this.HeroQueue.First()); this.ExecuteCommand(GatherCommand); this.RenderBattleField(); break; case "end": this.CommandStackNormal.Clear(); this.CommandStackNormal.Push(this.Battlefield.CreateMemento()); this.CommandStackReverse.Clear(); HeroInterface Temp = this.HeroQueue.First(); Temp.RestoreTurn(); this.HeroQueue.RemoveFirst(); this.HeroQueue.AddLast(Temp); this.RenderBattleField(); break; case "undo": if (this.CommandStackNormal.Count > 1) { this.CommandStackReverse.Push(this.CommandStackNormal.Pop()); this.Battlefield.Restore(this.CommandStackNormal.Peek()); this.RenderBattleField(); } break; case "redo": if (this.CommandStackReverse.Any()) { this.CommandStackNormal.Push(this.CommandStackReverse.Pop()); this.Battlefield.Restore(this.CommandStackNormal.Peek()); this.RenderBattleField(); } break; case "refresh": this.RenderBattleField(); break; case "exit": this.Over = true; break; default: Console.WriteLine("Unknown command"); break; } if (Over) { lock (Refreshlock) { Monitor.PulseAll(Refreshlock); } break; } } ObserverFactory.GetInstance().Finish(); }