Пример #1
0
        private void Shuffle(List <PictureBlock> list)
        {
            Random random = new Random();
            int    n      = list.Count;

            while (n > 1)
            {
                n--;
                int          k     = random.Next(n + 1);
                PictureBlock value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
Пример #2
0
        private void rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (isGame)
            {
                Rectangle rectangle = sender as Rectangle;

                if (isChange)
                {
                    PictureBlock tempPictBlock = rectangle.Tag as PictureBlock;
                    rectangle.Tag        = changeRectangle.Tag;
                    rectangle.Fill       = new ImageBrush(((PictureBlock)changeRectangle.Tag).getCroppedBitmap());
                    changeRectangle.Tag  = tempPictBlock;
                    changeRectangle.Fill = new ImageBrush(tempPictBlock.getCroppedBitmap());

                    var animation1 = new ThicknessAnimation();
                    animation1.From        = new Thickness(0);
                    animation1.To          = new Thickness(50);
                    animation1.Duration    = TimeSpan.FromSeconds(1);
                    animation1.AutoReverse = true;
                    Storyboard.SetTarget(animation1, rectangle);
                    Storyboard.SetTargetProperty(animation1, new PropertyPath(MarginProperty));

                    var animation2 = new ThicknessAnimation();
                    animation2.From        = new Thickness(0);
                    animation2.To          = new Thickness(50);
                    animation2.Duration    = TimeSpan.FromSeconds(1);
                    animation2.AutoReverse = true;
                    Storyboard.SetTarget(animation2, changeRectangle);
                    Storyboard.SetTargetProperty(animation2, new PropertyPath(MarginProperty));

                    var storyboard = new Storyboard();
                    storyboard.Children = new TimelineCollection {
                        animation1, animation2
                    };

                    storyboard.Begin();
                    checkState();
                }
                else
                {
                    changeRectangle = rectangle;
                }

                isChange = !isChange;
            }
        }