Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Robot rob = new Robot();

            MoveDel[] traceArr = new MoveDel[10]; // Массив делегатов, представляет перемещение робота на плоскости

            MoveDel trace = null;                 // Многоадресный делегат, представляет перемещение робота на плоскости

            for (int i = 0; i < 10; i++)
            {
                switch (rnd.Next(4))
                { // Заполняем массив, дублируя методы в многоадресный делегат
                case 0:
                    traceArr[i] = new MoveDel(rob.Forward);
                    trace      += rob.Forward; // Можно добавлять несколько раз один и тот же метод к делегату
                    break;

                case 1:
                    traceArr[i] = new MoveDel(rob.Backward);
                    trace      += rob.Backward;
                    break;

                case 2:
                    traceArr[i] = new MoveDel(rob.Left);
                    trace      += rob.Left;
                    break;

                case 3:
                    traceArr[i] = new MoveDel(rob.Right);
                    trace      += rob.Right;
                    break;
                }
            }

            Console.WriteLine("Массив делегатов:");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Method={0}, Target={1}", traceArr[i].Method, traceArr[i].Target);
                Console.WriteLine(traceArr[i]());
                Console.WriteLine();
            }

            rob.Reset();

            Console.WriteLine("=============");
            Console.WriteLine("Многоадресный делегат:");
            Console.WriteLine(trace()); // Обратите внимание, что выполняюся все делегаты, но возвращается значение только последнего

            Console.Read();
        }
Ejemplo n.º 2
0
        private void Right()
        {
            if (_bPause)
            {
                return;
            }

            if (!this.InvokeRequired)
            {
                button_right.Visible = false;
                Thread.Sleep(20);
                button_right.Visible = true;
                if (CheckCubeCanMove(_curCube, Direction.Right))
                {
                    List <Node> tempNodes = CommonHelper.DeepCloneNodeList(_curCube.Nodes);
                    _curCube?.Right();
                    List <Node> diffNodes = CommonHelper.CompareToFindNodeList(tempNodes, _curCube.Nodes);
                    _historyCubeNodeList.Add(CommonHelper.ResetNodeAttr(diffNodes));
                    RefreshCubeInMapOccupy(_curCube.Nodes, diffNodes, _curCube.BackColor);
                    RefreshMapShow();
                }
            }
            else
            {
                MoveDel RightDel = new MoveDel(Right);
                this.Invoke(RightDel);
            }
        }
Ejemplo n.º 3
0
 // changes color of drawables as they move
 public void ChangeColor(MoveDel action, Color endColor, float d)
 {
     tweenerColorR = new Tweener(attributes.color.R, endColor.R, d, action);
     tweenerColorG = new Tweener(attributes.color.G, endColor.G, d, action);
     tweenerColorB = new Tweener(attributes.color.B, endColor.B, d, action);
     tweenerA      = new Tweener(attributes.color.A, endColor.A, d, action);
 }
Ejemplo n.º 4
0
 // changes color of drawables as they move
 public void ChangeColor(MoveDel action, Color endColor, float d)
 {
     tweenerColorR = new Tweener(attributes.color.R, endColor.R, d, action);
     tweenerColorG = new Tweener(attributes.color.G, endColor.G, d, action);
     tweenerColorB = new Tweener(attributes.color.B, endColor.B, d, action);
     tweenerA = new Tweener(attributes.color.A, endColor.A, d, action);
 }
Ejemplo n.º 5
0
 // moves drawables with a delay
 public void Move(MoveDel action, Vector2 endPosition, float d, float delay)
 {
     isMoving        = true;
     tweenerX        = new Tweener(attributes.position.X, endPosition.X, delay, d, action);
     tweenerY        = new Tweener(attributes.position.Y, endPosition.Y, delay, d, action);
     tweenerX.Ended += delegate() { this.isMoving = false; tweenerX = null; };
     tweenerY.Ended += delegate() { tweenerY = null; };
 }
Ejemplo n.º 6
0
 // constructor for tweener
 public Tweener(float from, float to, float duration, MoveDel tweeningFunction)
 {
     _from = from;
     _position = from;
     _change = to - from;
     _tweeningFunction = tweeningFunction;
     _duration = duration;
 }
Ejemplo n.º 7
0
 // constructor for tweener
 public Tweener(float from, float to, float duration, MoveDel tweeningFunction)
 {
     _from             = from;
     _position         = from;
     _change           = to - from;
     _tweeningFunction = tweeningFunction;
     _duration         = duration;
 }
Ejemplo n.º 8
0
 public void SetMove(Vector3 value, bool isRun)  // isRun = true(running) or isrun = false(walk)
 {
     WalkVec = value;
     if (!isRun)
     {
         MoveFunction = Walk;
     }
     else
     {
         MoveFunction = Run;
     }
 }
 //Simple logic to handle the timer and what to do when it's still going or done
 protected float TimerFunc(float timer, MoveDel ifGoing, MoveDel ifDone)
 {
     if (timer > 0)
     {
         timer -= Time.deltaTime;
         ifGoing();
     }
     else if (timer <= 0)
     {
         timer = 0;
         ifDone();
     }
     return(timer);
 }
Ejemplo n.º 10
0
 private void Down()
 {
     if (_bPause)
     {
         return;
     }
     if (!this.InvokeRequired)
     {
         button_down.Visible = false;
         Thread.Sleep(20);
         button_down.Visible = true;
         _bAccelerate        = true;
     }
     else
     {
         MoveDel DownDel = new MoveDel(Down);
         this.Invoke(DownDel);
     }
 }
Ejemplo n.º 11
0
 private void Up()
 {
     if (!this.InvokeRequired)
     {
         button_up.Visible = false;
         Thread.Sleep(20);
         button_up.Visible = true;
         _bPause           = !_bPause;
         if (_bPause)
         {
             label_showPause.Text = "继续";
         }
         else
         {
             label_showPause.Text = "暂停";
         }
     }
     else
     {
         MoveDel UpDel = new MoveDel(Up);
         this.Invoke(UpDel);
     }
 }
Ejemplo n.º 12
0
 // rescales drawables with a delay
 // not needed
 public void Scale(MoveDel action, Vector2 endScale, float d, float delay)
 {
     tweenerScaleX = new Tweener(attributes.scale.X, endScale.X, delay, d, action);
     tweenerScaleY = new Tweener(attributes.scale.Y, endScale.Y, delay, d, action);
 }
Ejemplo n.º 13
0
 // moves drawables with a delay
 public void Move(MoveDel action, Vector2 endPosition, float d, float delay)
 {
     isMoving = true;
     tweenerX = new Tweener(attributes.position.X, endPosition.X, delay, d, action);
     tweenerY = new Tweener(attributes.position.Y, endPosition.Y, delay, d, action);
     tweenerX.Ended += delegate() { this.isMoving = false; tweenerX = null;};
     tweenerY.Ended += delegate() { tweenerY = null; };
 }
Ejemplo n.º 14
0
 // rotates drawables
 public void Rotate(MoveDel action, float endRotation, float d)
 {
     tweenerRotate = new Tweener(attributes.rotation, endRotation, d, action);
 }
Ejemplo n.º 15
0
 public Tweener(float from, float to, TimeSpan duration, MoveDel tweeningFunction)
     : this(from, to, (float)duration.TotalSeconds, tweeningFunction)
 {
 }
Ejemplo n.º 16
0
 // flips drawables with delay
 public void Flip(MoveDel action, float d, float delay)
 {
     this.Scale(action, new Vector2(0, attributes.scale.Y), d, delay);
 }
Ejemplo n.º 17
0
 public Form1()
 {
     move = new MoveDel(Moution);
     r    = new Random();
     InitializeComponent();
 }
Ejemplo n.º 18
0
 // changes depth of drawables w delay
 public void ChangeDepth(MoveDel action, float endDepth, float d, float delay)
 {
     tweenerDepth = new Tweener(attributes.depth, endDepth, delay, d, action);
 }
Ejemplo n.º 19
0
 // flips drawables with delay
 public void Flip(MoveDel action, float d, float delay)
 {
     this.Scale(action, new Vector2(0, attributes.scale.Y), d, delay);
 }
Ejemplo n.º 20
0
 // rescales drawables with a delay
 // not needed
 public void Scale(MoveDel action, Vector2 endScale, float d, float delay)
 {
     tweenerScaleX = new Tweener(attributes.scale.X, endScale.X, delay, d, action);
     tweenerScaleY = new Tweener(attributes.scale.Y, endScale.Y, delay, d, action);
 }
Ejemplo n.º 21
0
 public Tweener(float from, float to, TimeSpan duration, MoveDel tweeningFunction)
     : this(from, to, (float)duration.TotalSeconds, tweeningFunction)
 {
 }
Ejemplo n.º 22
0
 // changes depth of drawables w delay
 public void ChangeDepth(MoveDel action, float endDepth, float d, float delay)
 {
     tweenerDepth = new Tweener(attributes.depth, endDepth, delay, d, action);
 }
Ejemplo n.º 23
0
 // rotates drawables
 public void Rotate(MoveDel action, float endRotation, float d)
 {
     tweenerRotate = new Tweener(attributes.rotation, endRotation, d, action);
 }