private static void MouseOrderMove(Point p1, FrameworkElement fig) { var unitPresenter = fig.Tag as UnitPresenter; var unit = unitPresenter.Unit; var pos = unit.Position; Geometry.Figures.Point newPo = new Geometry.Figures.Point(p1.X, p1.Y); newPo = Transformer.ConvertToModel(newPo); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(pos.X, pos.Y, newPo.X, newPo.Y); GameEngine.Game.SendOrder(unit, new MoveAction(unit, poly)); unitPresenter.Update(); }
/// <summary> /// Отступление /// </summary> /// <param name="enemy">Unit отступает по направлению, противоположную к направлению на противника.</param> public void Retreat(Unit enemy) { var point = new Geometry.Figures.Point(commandUnit.Position.X - enemy.Position.X, commandUnit.Position.Y - enemy.Position.Y); double t = 0; t = Math.Sqrt((commandUnit.Properties.CurSpeed * commandUnit.Properties.CurSpeed) / (point.X * point.X + point.Y * point.Y)); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(commandUnit.Position.X, commandUnit.Position.Y, commandUnit.Position.X + t * point.X, commandUnit.Position.Y + t * point.Y); if (this.commandUnit.CurrentAction != null) { this.commandUnit.CurrentAction.Completed = true; this.commandUnit.CurrentAction = null; } Reset(); GameEngine.Game.SendOrder(commandUnit, new MoveAction(commandUnit, poly)); }
public List <UnitState> Leaving(Unit enemy) { var point = new Geometry.Figures.Point(commandUnit.Position.X - enemy.Position.X, commandUnit.Position.Y - enemy.Position.Y); double t = 0; t = Math.Sqrt((commandUnit.Properties.CurSpeed * commandUnit.Properties.CurSpeed) / (point.X * point.X + point.Y * point.Y)); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(commandUnit.Position.X, commandUnit.Position.Y, commandUnit.Position.X + t * point.X, commandUnit.Position.Y + t * point.Y); //GameEngine.Game.SendOrder(adm, new MoveAction(adm, poly)); //return new UnitState return(new List <UnitState> { new UnitState(poly.Points.Last(), 0, StateAction.Move), new UnitState(poly.Points.Last(), 0, StateAction.Move) }); }
/// <summary> /// Отступление от нескольких войск противников /// </summary> /// <param name="enemy"></param> public void Retreat(List <Unit> enemy) { var ememyAveragePosition = new Geometry.Figures.Point(enemy[0].Position.X, enemy[0].Position.Y); for (int i = 1; i < enemy.Count; i++) { ememyAveragePosition = new Geometry.Figures.Point((ememyAveragePosition.X + enemy[i].Position.X) / 2, (ememyAveragePosition.Y + enemy[i].Position.Y) / 2); } double t = 0; var point = new Geometry.Figures.Point(commandUnit.Position.X - ememyAveragePosition.X, commandUnit.Position.Y - ememyAveragePosition.Y); t = Math.Sqrt((commandUnit.Properties.CurSpeed * commandUnit.Properties.CurSpeed) / (point.X * point.X + point.Y * point.Y)); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(commandUnit.Position.X, commandUnit.Position.Y, commandUnit.Position.X + t * point.X, commandUnit.Position.Y + t * point.Y); if (this.commandUnit.CurrentAction != null) { this.commandUnit.CurrentAction.Completed = true; this.commandUnit.CurrentAction = null; } Reset(); GameEngine.Game.SendOrder(commandUnit, new MoveAction(commandUnit, poly)); }
/// <summary> /// Отступление от нескольких войск противников /// </summary> /// <param name="enemy"></param> public void Retreat(List<Unit> enemy) { var ememyAveragePosition = new Geometry.Figures.Point(enemy[0].Position.X,enemy[0].Position.Y); for (int i = 1; i < enemy.Count; i++) { ememyAveragePosition = new Geometry.Figures.Point((ememyAveragePosition.X + enemy[i].Position.X) / 2, (ememyAveragePosition.Y + enemy[i].Position.Y) / 2); } double t = 0; var point = new Geometry.Figures.Point(commandUnit.Position.X - ememyAveragePosition.X, commandUnit.Position.Y - ememyAveragePosition.Y); t = Math.Sqrt((commandUnit.Properties.CurSpeed * commandUnit.Properties.CurSpeed) / (point.X * point.X + point.Y * point.Y)); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(commandUnit.Position.X, commandUnit.Position.Y, commandUnit.Position.X + t * point.X, commandUnit.Position.Y + t * point.Y); if (this.commandUnit.CurrentAction != null) { this.commandUnit.CurrentAction.Completed = true; this.commandUnit.CurrentAction = null; } Reset(); GameEngine.Game.SendOrder(commandUnit, new MoveAction(commandUnit, poly)); }
public List<UnitState> Leaving(Unit enemy) { var point = new Geometry.Figures.Point(commandUnit.Position.X - enemy.Position.X, commandUnit.Position.Y - enemy.Position.Y); double t = 0; t = Math.Sqrt((commandUnit.Properties.CurSpeed * commandUnit.Properties.CurSpeed) / (point.X * point.X + point.Y * point.Y)); Geometry.Figures.Polyline poly = new Geometry.Figures.Polyline(commandUnit.Position.X, commandUnit.Position.Y, commandUnit.Position.X + t * point.X, commandUnit.Position.Y + t * point.Y); //GameEngine.Game.SendOrder(adm, new MoveAction(adm, poly)); //return new UnitState return new List<UnitState> { new UnitState(poly.Points.Last(), 0, StateAction.Move), new UnitState(poly.Points.Last(), 0, StateAction.Move) }; }