Example #1
0
        Geometry.Figures.Point target; //точка цели

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Конструктор текущего действия (движения)
        /// </summary>
        /// <param name="a">Действие</param>
        /// <param name="curPoint">Текущее положение отряда</param>
        public OrderPresenter(AbstractGameEngine.Action a, Geometry.Figures.Point curPoint)
        {
            double ratio = Transformer.Ratio;
            this.origin = curPoint;
            this.target = (a as GameEngine.Characters.MoveAction).Destination;
            OrderOrigin = new Point(curPoint.X * ratio, curPoint.Y * ratio);
            OrderTarget = new Point(target.X * ratio, target.Y * ratio);
            this.OrderType = 0;

            VisibleWayAim = Visibility.Visible;
            this.TurnsToComplete = (a as GameEngine.Characters.MoveAction).TurnsToComplete;

            double dX=0;//смещение значка цели перемещения относительно положения отряда по оси X
            double dY=0;//смещение значка цели перемещения относительно положения отряда по оси Y

            if ((target.X - origin.X) < 0) dX = 2 * (target.X - origin.X) * ratio;//если отряд двигается влево
            else dX = (target.X - origin.X) * ratio - 12.5;//если отряд двигается вправо
            if ((origin.Y - target.Y) < 0) dY = 2 * (origin.Y - target.Y) * ratio;//если отряд двигается вверх
            else dY = (origin.Y - target.Y) * ratio - 12.5;//если отряд двигается вниз
            this.Margin = new Thickness(dX, dY, 0, 0);

            DeltaHorisontal = (target.X - origin.X) * ratio;
            DeltaVertical = (origin.Y - target.Y) * ratio;

            this.WayLine = new System.Windows.Media.PointCollection();
            Point aimPos = new Point(dX, dY);//получение точки цели перемещения отряда
            this.WayLine.Add(new Point(0, 0));//точка нахождения отряда относительно отряда
            this.WayLine.Add(new Point((target.X - origin.X) * ratio, (origin.Y - target.Y) * ratio));
        }
Example #2
0
        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)
            });
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value is OrderPresenter)
     {
         var action = value as OrderPresenter;
         var p0 = action.OrderOrigin;
         var p1 = action.OrderTarget;
         Geometry.Figures.Point orig = new Geometry.Figures.Point(p0.X, p0.Y);
         Geometry.Figures.Point targ =  new Geometry.Figures.Point(p1.X, p1.Y);
         var v = Geometry.Vector.BetweenPoints(orig, targ);
         var radians = Geometry.Measures.AngleFromXOrto(v);
         var degrees = Geometry.Measures.ToDegrees(-radians); // Rotate transform eats angles CLOCKWISE and in degrees
         return degrees;
     }
     else return 0;
 }
Example #6
0
        Geometry.Figures.Point target;            //точка цели

        #endregion

        #region Constructors

        /// <summary>
        /// Конструктор текущего действия (движения)
        /// </summary>
        /// <param name="a">Действие</param>
        /// <param name="curPoint">Текущее положение отряда</param>
        public OrderPresenter(AbstractGameEngine.Action a, Geometry.Figures.Point curPoint)
        {
            double ratio = Transformer.Ratio;

            this.origin    = curPoint;
            this.target    = (a as GameEngine.Characters.MoveAction).Destination;
            OrderOrigin    = new Point(curPoint.X * ratio, curPoint.Y * ratio);
            OrderTarget    = new Point(target.X * ratio, target.Y * ratio);
            this.OrderType = 0;

            VisibleWayAim        = Visibility.Visible;
            this.TurnsToComplete = (a as GameEngine.Characters.MoveAction).TurnsToComplete;

            double dX = 0; //смещение значка цели перемещения относительно положения отряда по оси X
            double dY = 0; //смещение значка цели перемещения относительно положения отряда по оси Y

            if ((target.X - origin.X) < 0)
            {
                dX = 2 * (target.X - origin.X) * ratio;                           //если отряд двигается влево
            }
            else
            {
                dX = (target.X - origin.X) * ratio - 12.5; //если отряд двигается вправо
            }
            if ((origin.Y - target.Y) < 0)
            {
                dY = 2 * (origin.Y - target.Y) * ratio;                           //если отряд двигается вверх
            }
            else
            {
                dY = (origin.Y - target.Y) * ratio - 12.5; //если отряд двигается вниз
            }
            this.Margin = new Thickness(dX, dY, 0, 0);

            DeltaHorisontal = (target.X - origin.X) * ratio;
            DeltaVertical   = (origin.Y - target.Y) * ratio;

            this.WayLine = new System.Windows.Media.PointCollection();
            Point aimPos = new Point(dX, dY);  //получение точки цели перемещения отряда

            this.WayLine.Add(new Point(0, 0)); //точка нахождения отряда относительно отряда
            this.WayLine.Add(new Point((target.X - origin.X) * ratio, (origin.Y - target.Y) * ratio));
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value is OrderPresenter)
     {
         var action = value as OrderPresenter;
         var p0     = action.OrderOrigin;
         var p1     = action.OrderTarget;
         Geometry.Figures.Point orig = new Geometry.Figures.Point(p0.X, p0.Y);
         Geometry.Figures.Point targ = new Geometry.Figures.Point(p1.X, p1.Y);
         var v       = Geometry.Vector.BetweenPoints(orig, targ);
         var radians = Geometry.Measures.AngleFromXOrto(v);
         var degrees = Geometry.Measures.ToDegrees(-radians); // Rotate transform eats angles CLOCKWISE and in degrees
         return(degrees);
     }
     else
     {
         return(0);
     }
 }
        /// <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));
        }
Example #9
0
        /// <summary>
        /// Пересчёт координат при движении мыши
        /// </summary>
        private void MouseEnterHandler(object sender, MouseEventArgs e)
        {
            Point point = e.GetPosition(this);

            if (!MainWindow.GameWindow.IsActive)
            {
                return;
            }
            if (e.OriginalSource is Shape)
            {
                var info = UI.GetInfo((Shape)e.OriginalSource);
                Geometry.Figures.Point MapPoint = Transformer.ConvertToModel(point.X, point.Y);
                if (info.Count > 1)
                {
                    MousePosition.Content = String.Format("X: {0}, Y: {1}", MapPoint.X, MapPoint.Y) + " " + info[0];
                }
                else
                {
                    MousePosition.Content = String.Format("X: {0}, Y: {1}", MapPoint.X, MapPoint.Y) + " " + info[0];
                }
            }
        }
 /// <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">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) };
        }
Example #13
0
        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();
        }