Exemple #1
0
        private void MakeMove(HanoiMove move)
        {
            int from = move.From - 1, to = move.To - 1;
            var disc  = _movingDisc = _poles[from].Top;
            var start = GetPositionInPole(disc, from);
            var end   = GetPositionInPole(disc, to);
            var g     = FindResource("animGeometry") as PathGeometry;

            g.Figures[0].StartPoint = start;
            // update geometry
            var poly = g.Figures[0].Segments[0] as PolyLineSegment;

            poly.Points[0] = new Point(start.X, 1100);
            poly.Points[1] = new Point(end.X, 1100);
            poly.Points[2] = end;

            EventHandler completed = null;

            completed = (s, e) => {
                _animation.Completed -= completed;
                if (_vm.Moves != null)
                {
                    _poles[to].Add(disc);
                    _poles[from].Remove();
                    Canvas.SetLeft(disc, Canvas.GetLeft(disc));
                    Canvas.SetBottom(disc, Canvas.GetBottom(disc));
                    // next move
                    if (_currentMoveEnum != null)
                    {
                        if (_currentMoveEnum.MoveNext())
                        {
                            MakeMove(_currentMoveEnum.Current);
                        }
                        else
                        {
                            _vm.MovesDone();
                            CommandManager.InvalidateRequerySuggested();
                        }
                    }
                }
            };
            _animation.Completed += completed;
            _vm.MakeMove();
            // start a controllable animation
            _animation.Begin(disc, true);
        }