我用c#窗体java编写窗体程序了一个拼图游戏,可是我不知道如何判断是否拼图成功

最近在学习C#WPF,边学习边写了一个拼图的小游戏
MainWindow.xaml.cs
using System.Collections.G
using System.L
using System.T
using System.W
using System.Windows.C
using System.Windows.D
using System.Windows.D
using System.Windows.I
using System.Windows.M
using System.Windows.Media.I
using System.Windows.N
using System.Windows.S
using System.D
using System.Drawing.I
using System.IO;
namespace JigsawGame
&&& /// &summary&
&&& /// MainWindow.xaml 的交互逻辑
&&& /// &/summary&
&&& public partial class MainWindow : Window
&&&&&&& private string currentImageF
&&&&&&& private static double jigsawWidthMax = 450.0;
&&&&&&& private double jigsawH
&&&&&&& private L
&&&&&&& private Jigsaw currentJ
&&&&&&& public MainWindow()
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& layout = new Layout(2, 2);
&&&&&&&&&&& currentImageFile = &image/leaf.jpg&;
&&&&&&&&&&& ImageZoom igZoom = new ImageZoom(currentImageFile);
&&&&&&&&&&& igZoom.ZoomOutTo(jigsawWidthMax, ImageFormat.Jpeg, &tmp.jpg&);
&&&&&&&&&&& string currentImageFileTmp = &tmp.jpg&;
&&&&&&&&&&& Stream imageStreamSource = new FileStream(currentImageFileTmp, FileMode.Open, FileAccess.Read, FileShare.Read);
&&&&&&&&&&& JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
&&&&&&&&&&& BitmapSource bitmapSource = decoder.Frames[0];
&&&&&&&&&&& imagePuzzle.Source = bitmapS
&&&&&&&&&&& Bitmap bitmap = new Bitmap(imageStreamSource);
&&&&&&&&&&& imageStreamSource.Close();
&&&&&&&&&&& File.Delete(currentImageFileTmp);
&&&&&&&&&&& Jigsaw js = new Jigsaw(
&&&&&&&&&&&&&&& bitmapSource,
&&&&&&&&&&&&&&& new System.Windows.Point(200, 15),
&&&&&&&&&&&&&&& new System.Windows.Size(ScreenUnitConverter.GetScreenWindth() - 230, ScreenUnitConverter.GetScreenHeight() - 130),
&&&&&&&&&&&&&&& new System.Windows.Point(100, 100),
&&&&&&&&&&&&&&& new System.Windows.Size(jigsawWidthMax, ScreenUnitConverter.PixelToInch(bitmap.Height)),
&&&&&&&&&&&&&&& layout);
&&&&&&&&&&& contentGrid.Children.Add(js);
&&&&&&&&&&& currentJigsaw =
&&&&&&&&&&& jigsawHeight = ScreenUnitConverter.PixelToInch(bitmap.Height);
&&&&&&&&&&& textBox1.Visibility = System.Windows.Visibility.H
&&&&&&& private void ImageChanged(object sender, MouseButtonEventArgs e)
&&&&&&&&&&& Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
&&&&&&&&&&& dlg.Filter = &Image Files|*.*.*.T*.Png&;
&&&&&&&&&&& if (dlg.ShowDialog() == true)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& currentImageFile = dlg.FileN
&&&&&&&&&&& }
&&&&&&&&&&& ImageZoom igZoom = new ImageZoom(currentImageFile);
&&&&&&&&&&& igZoom.ZoomOutTo(jigsawWidthMax, ImageFormat.Jpeg, &tmp.jpg&);
&&&&&&&&&&& string currentImageFileTmp = &tmp.jpg&;
&&&&&&&&&&& Stream imageStreamSource = new FileStream(currentImageFileTmp, FileMode.Open, FileAccess.Read, FileShare.Read);
&&&&&&&&&&& JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
&&&&&&&&&&& BitmapSource bitmapSource = decoder.Frames[0];
&&&&&&&&&&& imageStreamSource.Close();
&&&&&&&&&&& File.Delete(currentImageFileTmp);
&&&&&&&&&&& imagePuzzle.Source = bitmapS
&&&&&&&&&&& currentJigsaw.Image = bitmapS
&&&&&&& private void LayoutChanged(object sender, RoutedEventArgs e)
&&&&&&&&&&& if (currentJigsaw != null)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& RadioButton rdb = (RadioButton)
&&&&&&&&&&&&&&& if (e.Source is RadioButton && rdb != other)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& string sss = rdb.Content.ToString();
&&&&&&&&&&&&&&&&&&& layout.RowCount = Convert.ToInt32(sss.Substring(0, sss.LastIndexOf(&x&)));
&&&&&&&&&&&&&&&&&&& layout.ColCount = Convert.ToInt32(sss.Substring(sss.LastIndexOf(&x&) + 1, sss.Length - sss.IndexOf(&x&) - 1));
&&&&&&&&&&&&&&&&&&& currentJigsaw.Layout =
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& if (e.Source is RadioButton && rdb == other)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& string row = tbxLayoutRow.T
&&&&&&&&&&&&&&&&&&& string col = tbxLayoutCol.T
&&&&&&&&&&&&&&&&&&& layout.RowCount = Convert.ToInt32(row);
&&&&&&&&&&&&&&&&&&& layout.ColCount = Convert.ToInt32(col);
&&&&&&&&&&&&&&&&&&& currentJigsaw.Layout =
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& private void GroupChanged(object sender, RoutedEventArgs e)
&&&&&&&&&&& if (currentJigsaw != null)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& RadioButton rdb = (RadioButton)
&&&&&&&&&&&&&&& if (e.Source is RadioButton)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& string sss = rdb.Content.ToString();
&&&&&&&&&&&&&&&&&&& if (sss == &组&& 合&)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& currentJigsaw.Group =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& currentJigsaw.Group =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& private void buttonStart_Click(object sender, RoutedEventArgs e)
&&&&&&&&&&& if ((string)(buttonStart.Content) == &开& 始&)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& imagePuzzle.IsEnabled =
&&&&&&&&&&&&&&& radioButton2.IsEnabled =
&&&&&&&&&&&&&&& radioButton3.IsEnabled =
&&&&&&&&&&&&&&& radioButton4.IsEnabled =
&&&&&&&&&&&&&&& radioButton5.IsEnabled =
&&&&&&&&&&&&&&& radioButton6.IsEnabled =
&&&&&&&&&&&&&&& other.IsEnabled =
&&&&&&&&&&&&&&& rBNGroup.IsEnabled =
&&&&&&&&&&&&&&& rBNNoGroup.IsEnabled =
&&&&&&&&&&&&&&& buttonStart.Content = &结& 束&;
&&&&&&&&&&&&&&& currentJigsaw.Spread();
&&&&&&&&&&& }
&&&&&&&&&&& else
&&&&&&&&&&& {
&&&&&&&&&&&&&&& imagePuzzle.IsEnabled =
&&&&&&&&&&&&&&& radioButton2.IsEnabled =
&&&&&&&&&&&&&&& radioButton3.IsEnabled =
&&&&&&&&&&&&&&& radioButton4.IsEnabled =
&&&&&&&&&&&&&&& radioButton5.IsEnabled =
&&&&&&&&&&&&&&& radioButton6.IsEnabled =
&&&&&&&&&&&&&&& other.IsEnabled =
&&&&&&&&&&&&&&& rBNGroup.IsEnabled =
&&&&&&&&&&&&&&& rBNNoGroup.IsEnabled =
&&&&&&&&&&&&&&& buttonStart.Content = &开& 始&;
&&&&&&&&&&&&&&& currentJigsaw.Reset();
&&&&&&&&&&& }
Jigsaw.xaml.cs
using System.Collections.G
using System.L
using System.T
using System.W
using System.Windows.C
using System.Windows.D
using System.Windows.D
using System.Windows.I
using System.Windows.M
using System.Windows.Media.I
using System.Windows.N
using System.Windows.S
using System.Windows.Media.E
namespace JigsawGame
&&& public class Layout
&&&&&&& public int RowC
&&&&&&& public int ColC
&&&&&&& public Layout()
&&&&&&&&&&& RowCount = 2;
&&&&&&&&&&& ColCount = 2;
&&&&&&& public Layout(int rowCount, int colCount)
&&&&&&&&&&& RowCount = rowC
&&&&&&&&&&& ColCount = colC
&&& /// &summary&
&&& /// Jigsaw.xaml 的交互逻辑
&&& /// &/summary&
&&& public partial class Jigsaw : UserControl
&&&&&&& private BitmapS
&&&&&&& private L
&&&&&&& private P
&&&&&&& private S
&&&&&&& private bool isG
&&&&&&& private SetOfSets&PieceOfJigsaw&
&&&&&&& private List&PieceOfJigsaw& availbleC
&&&&&&& private Random random = new Random();
&&&&&&& public Jigsaw(
&&&&&&&&&&& BitmapSource&&& bitmapSource,
&&&&&&&&&&& Point&& motherBoardPosition,
&&&&&&&&&&& Size&&& motherBoardSize,
&&&&&&&&&&& Point&& jigsawPosition,
&&&&&&&&&&& Size&&& jigsawSize,
&&&&&&&&&&& Layout lay)
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& image = bitmapS
&&&&&&&&&&& Width = motherBoardSize.W
&&&&&&&&&&& Height = motherBoardSize.H
&&&&&&&&&&& HorizontalAlignment = HorizontalAlignment.L
&&&&&&&&&&& VerticalAlignment = VerticalAlignment.T
&&&&&&&&&&& Margin = new Thickness(motherBoardPosition.X, motherBoardPosition.Y, 0, 0);
&&&&&&&&&&& position = jigsawP
&&&&&&&&&&& size = jigsawS
&&&&&&&&&&& layout =
&&&&&&&&&&& isGroup =
&&&&&&&&&&& children = new SetOfSets&PieceOfJigsaw&(new CanGroup(isNeighbourhood));
&&&&&&&&&&& availbleChildren = new List&PieceOfJigsaw&();
&&&&&&&&&&& for (int i = 0; i & layout.RowC i++)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& for (int j = 0; j & layout.ColC j++)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& ID id = new ID(i, j);
&&&&&&&&&&&&&&&&&&& PieceOfJigsaw pOJ = new PieceOfJigsaw(
&&&&&&&&&&&&&&&&&&&&&&& getPOJImage(i,j),
&&&&&&&&&&&&&&&&&&&&&&& new Point(position.X + j * (pOJWidth), position.Y + i * (pOJHeight)),
&&&&&&&&&&&&&&&&&&&&&&& new Size(pOJWidth, pOJHeight),
&&&&&&&&&&&&&&&&&&&&&&& id);
&&&&&&&&&&&&&&&&&&& contentGrid.Children.Add(pOJ);
&&&&&&&&&&&&&&&&&&& children.AddElemet(pOJ);
&&&&&&&&&&&&&&&&&&& availbleChildren.Add(pOJ);
&&&&&&&&&&&&&&&&&&& pOJ.IsRotated += new IsRotatedHandler(rotatePieceOfJigsawSet);
&&&&&&&&&&&&&&&&&&& pOJ.IsTranslated += new IsTranslatedHandler(translatePieceOfJigsawSet);
&&&&&&&&&&&&&&&&&&& pOJ.IsClicked += new IsClickedHandler(topPieceOfJigsawSet);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& textBox1.Visibility = System.Windows.Visibility.H
&&&&&&& public BitmapSource Image
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& image =
&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in children.Elements)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& pOJ.Image = getPOJImage(pOJ.Id.RowIndex, pOJ.Id.ColIndex);
&&&&&&&&&&&&&&&&&&& pOJ.Reset();
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& Group = isG
&&&&&&&&&&& }
&&&&&&& public Layout Layout
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& layout =
&&&&&&&&&&&&&&& if (children != null)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in children.Elements)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& contentGrid.Children.Remove(pOJ);
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& children.Clear();
&&&&&&&&&&&&&&&&&&& for (int i = availbleChildren.C i & layout.ColCount * layout.RowC i++)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& PieceOfJigsaw pOJ = new PieceOfJigsaw(
&&&&&&&&&&&&&&&&&&&&&&&&&&& null,
&&&&&&&&&&&&&&&&&&&&&&&&&&& new Point(0, 0),
&&&&&&&&&&&&&&&&&&&&&&&&&&& new Size(1, 1),
&&&&&&&&&&&&&&&&&&&&&&&&&&& new ID(0, 0));
&&&&&&&&&&&&&&&&&&&&&&& availbleChildren.Add(pOJ);
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsRotated += new IsRotatedHandler(rotatePieceOfJigsawSet);
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsTranslated += new IsTranslatedHandler(translatePieceOfJigsawSet);
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsClicked += new IsClickedHandler(topPieceOfJigsawSet);
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& for (int i = 0; i & layout.RowC i++)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& for (int j = 0; j & layout.ColC j++)
&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&& ID id = new ID(i, j);
&&&&&&&&&&&&&&&&&&&&&&&&&&& PieceOfJigsaw pOJ = availbleChildren[i * layout.RowCount + j];
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.RowIndex =
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.ColIndex =
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Size = new Size(pOJWidth, pOJHeight);
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Image = getPOJImage(i,j);
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Margin = new Thickness(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& position.X + j * (pOJWidth),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& position.Y + i * (pOJHeight),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 0, 0);
&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&& contentGrid.Children.Add(pOJ);
&&&&&&&&&&&&&&&&&&&&&&&&&&& children.AddElemet(pOJ);
&&&&&&&&&&&&&&&&&&&&&&&&&&& pOJ.Reset();
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& Group = isG
&&&&&&&&&&& }
&&&&&&& public bool Group
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& isGroup =
&&&&&&&&&&&&&&& if (isGroup == true)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& children.Sets.Clear();
&&&&&&&&&&&&&&&&&&& children.Group(5);
&&&&&&&&&&&&&&&&&&& textBox1.Text += &集合数=&;
&&&&&&&&&&&&&&&&&&& textBox1.Text += children.Sets.C
&&&&&&&&&&&&&&&&&&& textBox1.Text += &\n&;
&&&&&&&&&&&&&&&&&&& foreach (List&PieceOfJigsaw& set in children.Sets)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& textBox1.Text += &集合:&;
&&&&&&&&&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in set)
&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&& textBox1.Text += pOJ.Id;
&&&&&&&&&&&&&&&&&&&&&&&&&&& textBox1.Text += &---&;
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&& textBox1.Text += &\n&;
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& drawLineBorder();
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& children.Sets.Clear();
&&&&&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in children.Elements)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderLeftVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderTopVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderRightVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderBottomVisible =
&&&&&&&&&&&&&&&&&&&&&&& List&PieceOfJigsaw& set = new List&PieceOfJigsaw&();
&&&&&&&&&&&&&&&&&&&&&&& set.Add(pOJ);
&&&&&&&&&&&&&&&&&&&&&&& children.Sets.Add(set);
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public void Spread()
&&&&&&&&&&& Group = isG
&&&&&&&&&&& foreach (List&PieceOfJigsaw& set in children.Sets)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& double deltaX = (double)random.Next(0, (int)(2.0 / 3 * Width - size.Width));
&&&&&&&&&&&&&&& double deltaY = (double)random.Next(0, (int)(2.0 / 3 * Height - size.Height));
&&&&&&&&&&&&&&& double an = (double)random.Next(0, 360);&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in set)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& pOJ.CenterX = set[0].Margin.Left - pOJ.Margin.L
&&&&&&&&&&&&&&&&&&& pOJ.CenterY = set[0].Margin.Top - pOJ.Margin.T
&&&&&&&&&&&&&&&&&&& pOJ.Angle =
&&&&&&&&&&&&&&&&&&& pOJ.TranslateX = deltaX;
&&&&&&&&&&&&&&&&&&& pOJ.TranslateY = deltaY;
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public void Reset()
&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in children.Elements)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& pOJ.Reset();
&&&&&&&&&&& }
&&&&&&&&&&& Group = isG
&&&&&&& private double pOJWidth
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return size.Width / layout.ColC
&&&&&&&&&&& }
&&&&&&& private double pOJHeight
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return size.Height / layout.RowC
&&&&&&&&&&& }
&&&&&&& private void rotatePieceOfJigsawSet(PieceOfJigsaw source)
&&&&&&&&&&& List&PieceOfJigsaw& currentSet = children.GetSet(source);
&&&&&&&&&&& double angle = source.A
&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in currentSet)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& pOJ.Angle =
&&&&&&&&&&& }
&&&&&&& private void translatePieceOfJigsawSet(PieceOfJigsaw pOJ)
&&&&&&&&&&& List&PieceOfJigsaw& currentSet = children.GetSet(pOJ);
&&&&&&&&&&& foreach (PieceOfJigsaw ig in currentSet)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& ig.TranslateX = pOJ.TranslateX;
&&&&&&&&&&&&&&& ig.TranslateY = pOJ.TranslateY;
&&&&&&&&&&& }
&&&&&&&&&&& union(currentSet);
&&&&&&& private void topPieceOfJigsawSet(PieceOfJigsaw source)
&&&&&&&&&&& List&PieceOfJigsaw& currentSet = children.GetSet(source);
&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in currentSet)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& contentGrid.Children.Remove(pOJ);
&&&&&&&&&&&&&&& contentGrid.Children.Add(pOJ);
&&&&&&&&&&& }
&&&&&&& private void union(List&PieceOfJigsaw& currentSet)
&&&&&&&&&&& bool found =
&&&&&&&&&&& List&PieceOfJigsaw& setB = new List&PieceOfJigsaw&();
&&&&&&&&&&& foreach (PieceOfJigsaw cig in currentSet)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& foreach (List&PieceOfJigsaw& set in children.Sets)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& if (set != currentSet)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& foreach (PieceOfJigsaw sig in set)
&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&& if (cig.IsBuddy(sig) == false)
&&&&&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&&&&&& found =
&&&&&&&&&&&&&&&&&&&&&&&&&&& setB =
&&&&&&&&&&&&&&&&&&&&&&&&&&& foreach (PieceOfJigsaw igg in set)
&&&&&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& igg.TranslateX = cig.TranslateX;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& igg.TranslateY = cig.TranslateY;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& igg.CenterX = currentSet[0].Margin.Left - igg.Margin.L
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& igg.CenterY = currentSet[0].Margin.Top - igg.Margin.T
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& igg.Angle = currentSet[0].A
&&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&&&&&& if (found == true)
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& if (found == true)
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& if (found == true)
&&&&&&&&&&& }
&&&&&&&&&&& if (found == true)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& children.Union(setB, currentSet);
&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in currentSet)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& pOJ.Animate();
&&&&&&&&&&&&&&&&&&& pOJ.BorderLeftColor = Brushes.R
&&&&&&&&&&&&&&&&&&& pOJ.BorderRightColor = Brushes.R
&&&&&&&&&&&&&&&&&&& pOJ.BorderTopColor = Brushes.R
&&&&&&&&&&&&&&&&&&& pOJ.BorderBottomColor = Brushes.R
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& drawLineBorder(currentSet);
&&&&&&&&&&& }
&&&&&&& private void drawLineBorder(List&PieceOfJigsaw& set)
&&&&&&&&&&& foreach (PieceOfJigsaw pOJ in set)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& pOJ.IsBorderBottomVisible =
&&&&&&&&&&&&&&& pOJ.IsBorderLeftVisible =
&&&&&&&&&&&&&&& pOJ.IsBorderRightVisible =
&&&&&&&&&&&&&&& pOJ.IsBorderTopVisible =
&&&&&&&&&&&&&&& foreach (PieceOfJigsaw pOJNeighbour in set)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& if (pOJ == pOJNeighbour)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& if (pOJ.Id.RowIndex == pOJNeighbour.Id.RowIndex &&
&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.ColIndex == pOJNeighbour.Id.ColIndex - 1)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderRightVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJNeighbour.IsBorderLeftVisible =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& else if (pOJ.Id.RowIndex == pOJNeighbour.Id.RowIndex &&
&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.ColIndex == pOJNeighbour.Id.ColIndex + 1)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderLeftVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJNeighbour.IsBorderRightVisible =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& else if (pOJ.Id.RowIndex == pOJNeighbour.Id.RowIndex + 1 &&
&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.ColIndex == pOJNeighbour.Id.ColIndex)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderTopVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJNeighbour.IsBorderBottomVisible =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& else if (pOJ.Id.RowIndex == pOJNeighbour.Id.RowIndex - 1 &&
&&&&&&&&&&&&&&&&&&&&&&& pOJ.Id.ColIndex == pOJNeighbour.Id.ColIndex)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pOJ.IsBorderBottomVisible =
&&&&&&&&&&&&&&&&&&&&&&& pOJNeighbour.IsBorderTopVisible =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& private void drawLineBorder()
&&&&&&&&&&& foreach (List&PieceOfJigsaw& set in children.Sets)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& drawLineBorder(set);
&&&&&&&&&&& }
&&&&&&& private bool isNeighbourhood(object pOJ11, object pOJ22)
&&&&&&&&&&& PieceOfJigsaw pOJ1 = (PieceOfJigsaw)pOJ11;
&&&&&&&&&&& PieceOfJigsaw pOJ2 = (PieceOfJigsaw)pOJ22;
&&&&&&&&&&& return pOJ1.IsNeighbourhood(pOJ2);
&&&&&&& private BitmapSource getPOJImage(int i, int j)
&&&&&&&&&&& return new CroppedBitmap(
&&&&&&&&&&&&&&& image,
&&&&&&&&&&&&&&& new Int32Rect(
&&&&&&&&&&&&&&&&&&& j * ScreenUnitConverter.InchToPixel(pOJWidth),
&&&&&&&&&&&&&&&&&&& i * ScreenUnitConverter.InchToPixel(pOJHeight),
&&&&&&&&&&&&&&&&&&& ScreenUnitConverter.InchToPixel(pOJWidth),
&&&&&&&&&&&&&&&&&&& ScreenUnitConverter.InchToPixel(pOJHeight)
&&&&&&&&&&&&&&&&&&& ));&&&&&&&&&&&&&&&&&&&&&&
PieceOfJigsaw.xaml.cs
using System.Collections.G
using System.L
using System.T
using System.W
using System.Windows.C
using System.Windows.D
using System.Windows.D
using System.Windows.I
using System.Windows.M
using System.Windows.Media.I
using System.Windows.N
using System.Windows.S
using System.Windows.Media.A
namespace JigsawGame
&&& public delegate void IsRotatedHandler(PieceOfJigsaw pOJ);
&&& public delegate void IsTranslatedHandler(PieceOfJigsaw pOJ);
&&& public delegate void IsClickedHandler(PieceOfJigsaw pOJ);
&&& public class ID
&&&&&&& public int RowI
&&&&&&& public int ColI
&&&&&&& public ID(int rowIndex, int colIndex)
&&&&&&&&&&& RowIndex = rowI
&&&&&&&&&&& ColIndex = colI
&&&&&&& public override string ToString()
&&&&&&&&&&& return &ID:& + RowIndex + &.& + ColI
&&&&&&& public string Name()
&&&&&&&&&&& return &ID_& + RowIndex + &_& + ColI
&&& /// &summary&
&&& /// PieceOfJigsaw.xaml 的交互逻辑
&&& /// &/summary&
&&& public partial class PieceOfJigsaw : UserControl
&&&&&&& public event IsRotatedHandler IsR
&&&&&&& public event IsTranslatedHandler IsT
&&&&&&& public event IsClickedHandler IsC
&&&&&&& public ID Id;
&&&&&&& private TranslateTransform Tt;
&&&&&&& private RotateTransform Rt;
&&&&&&& private Point&& offsetP
&&&&&&& private bool&&& isTranslate =
&&&&&&& private bool&&& isRotate =
&&&&&&& //边界线
&&&&&&& private Line LineL
&&&&&&& private Line LineT
&&&&&&& private Line LineR
&&&&&&& private Line LineB
&&&&&&& //坐标
&&&&&&& private Point LeftT
&&&&&&& private Point RightT
&&&&&&& private Point RightB
&&&&&&& private Point LeftB
&&&&&&& private S
&&&&&&& public PieceOfJigsaw(
&&&&&&&&&&& BitmapSource bitmapSource,
&&&&&&&&&&& Point position,
&&&&&&&&&&& Size size,
&&&&&&&&&&& ID id)
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& image.Source = bitmapS
&&&&&&&&&&& HorizontalAlignment = HorizontalAlignment.L
&&&&&&&&&&& VerticalAlignment = VerticalAlignment.T
&&&&&&&&&&& Margin = new Thickness(position.X, position.Y, 0, 0);&&&&&&&&&&&
&&&&&&&&&&& Width = size.W
&&&&&&&&&&& Height = size.H
&&&&&&&&&&& image.Width = W
&&&&&&&&&&& image.Height = H
&&&&&&&&&&& Id =&&&&&&&&&&&
&&&&&&&&&&& Rt = new RotateTransform(0);
&&&&&&&&&&& Rt.CenterX = 0;
&&&&&&&&&&& Rt.CenterY = 0;
&&&&&&&&&&& Tt = new TranslateTransform();
&&&&&&&&&&& Tt.X = 0;
&&&&&&&&&&& Tt.Y = 0;
&&&&&&&&&&& TransformGroup tg = new TransformGroup();
&&&&&&&&&&& tg.Children.Add(Rt);//顺序很重要,先旋转再平移
&&&&&&&&&&& tg.Children.Add(Tt);
&&&&&&&&&&& RenderTransform =
&&&&&&&&&&& rotateHandle.Visibility = System.Windows.Visibility.H
&&&&&&&&&&& initLineBorder();
&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& initStoryBoard();
&&&&&&& public BitmapSource Image
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& image.Source =
&&&&&&&&&&& }
&&&&&&& public Size Size
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Width = value.W;
&&&&&&&&&&&&&&& Height = value.H
&&&&&&&&&&&&&&& image.Width = W
&&&&&&&&&&&&&&& image.Height = H
&&&&&&&&&&&&&&& LineLeft.Y2 = H
&&&&&&&&&&&&&&& LineTop.X2 = W
&&&&&&&&&&&&&&& LineRight.X1 = W
&&&&&&&&&&&&&&& LineRight.X2 = W
&&&&&&&&&&&&&&& LineRight.Y2 = H
&&&&&&&&&&&&&&& LineBottom.Y1 = H
&&&&&&&&&&&&&&& LineBottom.X2 = W
&&&&&&&&&&&&&&& LineBottom.Y2 = H
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public double Angle
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return Rt.A
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Rt.Angle =
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public double CenterX
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Rt.CenterX =&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public double CenterY
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Rt.CenterY =
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public double TranslateX
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return Tt.X;
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Tt.X =
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public double TranslateY
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return Tt.Y;
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Tt.Y =
&&&&&&&&&&&&&&& calculateCoordinates();
&&&&&&&&&&& }
&&&&&&& public bool IsBorderLeftVisible
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (LineLeft.Visibility == System.Windows.Visibility.Visible)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (value == true)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineLeft.Visibility = System.Windows.Visibility.V
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineLeft.Visibility = System.Windows.Visibility.H
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public bool IsBorderRightVisible
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (LineRight.Visibility == System.Windows.Visibility.Visible)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (value == true)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineRight.Visibility = System.Windows.Visibility.V
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineRight.Visibility = System.Windows.Visibility.H
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public bool IsBorderTopVisible
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (LineTop.Visibility == System.Windows.Visibility.Visible)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (value == true)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineTop.Visibility = System.Windows.Visibility.V
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineTop.Visibility = System.Windows.Visibility.H
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public bool IsBorderBottomVisible
&&&&&&&&&&& get
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (LineBottom.Visibility == System.Windows.Visibility.Visible)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (value == true)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineBottom.Visibility = System.Windows.Visibility.V
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& LineBottom.Visibility = System.Windows.Visibility.H
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public Brush BorderLeftColor
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& LineLeft.Stroke =
&&&&&&&&&&& }
&&&&&&& public Brush BorderRightColor
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& LineRight.Stroke =
&&&&&&&&&&& }
&&&&&&& public Brush BorderTopColor
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& LineTop.Stroke =
&&&&&&&&&&& }
&&&&&&& public Brush BorderBottomColor
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& LineBottom.Stroke =
&&&&&&&&&&& }
&&&&&&& public void Animate()
&&&&&&&&&&& storyboard.Begin(this);
&&&&&&& public bool IsNeighbourhood(PieceOfJigsaw pOJ)
&&&&&&&&&&& if (Id.RowIndex == pOJ.Id.RowIndex &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex - 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&& else if (Id.RowIndex == pOJ.Id.RowIndex &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex + 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&& else if (Id.ColIndex == pOJ.Id.ColIndex &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex - 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&& else if (Id.ColIndex == pOJ.Id.ColIndex &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex + 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&&
&&&&&&& public bool IsBuddy(PieceOfJigsaw pOJ)
&&&&&&&&&&& double dis1, dis2;
&&&&&&&&&&& if (IsBorderRightVisible == true &&
&&&&&&&&&&&&&&& pOJ.IsBorderLeftVisible == true &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex - 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& dis1 = distance(RightTop, pOJ.LeftTop);
&&&&&&&&&&&&&&& dis2 = distance(RightBottom, pOJ.LeftBottom);
&&&&&&&&&&&&&&& if (dis1 & 6 && dis2 & 6)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& else if (IsBorderBottomVisible == true &&
&&&&&&&&&&&&&&& pOJ.IsBorderTopVisible == true &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex - 1 &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& dis1 = distance(LeftBottom, pOJ.LeftTop);
&&&&&&&&&&&&&&& dis2 = distance(RightBottom, pOJ.RightTop);
&&&&&&&&&&&&&&& if (dis1 & 6 && dis2 & 6)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& else if (IsBorderLeftVisible == true &&
&&&&&&&&&&&&&&& pOJ.IsBorderRightVisible == true &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex + 1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& dis1 = distance(LeftTop, pOJ.RightTop);
&&&&&&&&&&&&&&& dis2 = distance(LeftBottom, pOJ.RightBottom);
&&&&&&&&&&&&&&& if (dis1 & 6 && dis2 & 6)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& else if (IsBorderTopVisible == true &&
&&&&&&&&&&&&&&& pOJ.IsBorderBottomVisible == true &&
&&&&&&&&&&&&&&& Id.RowIndex == pOJ.Id.RowIndex + 1 &&
&&&&&&&&&&&&&&& Id.ColIndex == pOJ.Id.ColIndex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& dis1 = distance(LeftTop, pOJ.LeftBottom);
&&&&&&&&&&&&&&& dis2 = distance(RightTop, pOJ.RightBottom);
&&&&&&&&&&&&&&& if (dis1 & 6 && dis2 & 6)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&&
&&&&&&& public void Reset()
&&&&&&&&&&& Angle = 0;
&&&&&&&&&&& CenterX = 0;
&&&&&&&&&&& CenterY = 0;
&&&&&&&&&&& TranslateX = 0;
&&&&&&&&&&& TranslateY = 0;
&&&&&&&&&&& IsBorderLeftVisible =
&&&&&&&&&&& IsBorderRightVisible =
&&&&&&&&&&& IsBorderTopVisible =
&&&&&&&&&&& IsBorderBottomVisible =
&&&&&&&&&&& BorderLeftColor = Brushes.S
&&&&&&&&&&& BorderRightColor = Brushes.S
&&&&&&&&&&& BorderTopColor = Brushes.S
&&&&&&&&&&& BorderBottomColor = Brushes.S
&&&&&&& private void mouseEnter(object sender, MouseEventArgs e)
&&&&&&&&&&& rotateHandle.Visibility = System.Windows.Visibility.V
&&&&&&&&&&& rotateHandle.Margin = new Thickness(Width / 2, Height / 2, 0, 0);
&&&&&&&&&&& rotateHandle.Width = 8;
&&&&&&&&&&& rotateHandle.Height = 8;
&&&&&&& private void mouseLeave(object sender, MouseEventArgs e)
&&&&&&&&&&& isRotate =
&&&&&&&&&&& isTranslate =
&&&&&&&&&&& rotateHandle.Visibility = System.Windows.Visibility.H
&&&&&&& private void mouseLeftButtonDown(object sender, MouseButtonEventArgs e)
&&&&&&&&&&& if (e.Source is Ellipse)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& isRotate =
&&&&&&&&&&&&&&& offsetPrevious = Mouse.GetPosition(this);
&&&&&&&&&&& }
&&&&&&&&&&& else
&&&&&&&&&&& {
&&&&&&&&&&&&&&& isTranslate =
&&&&&&&&&&&&&&& offsetPrevious = Mouse.GetPosition(null);
&&&&&&&&&&& }
&&&&&&&&&&& IsClicked(this);
&&&&&&& private void mouseMove(object sender, MouseEventArgs e)
&&&&&&& {&&&&&&&&&&&
&&&&&&&&&&& if (isRotate == true)
&&&&&&&&&&& {&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& Point offset = Mouse.GetPosition(this);
&&&&&&&&&&&&&&& double alpha = Math.Atan((offset.Y - Rt.CenterY) / (offset.X - Rt.CenterX));
&&&&&&&&&&&&&&& double beta = Math.Atan((offsetPrevious.Y - Rt.CenterY) / (offsetPrevious.X - Rt.CenterX));
&&&&&&&&&&&&&&& double deltaAngle = alpha -
&&&&&&&&&&&&&&& deltaAngle *= 180 / Math.PI;
&&&&&&&&&&&&&&& deltaAngle += Rt.A
&&&&&&&&&&&&&&& deltaAngle %= 360;
&&&&&&&&&&&&&&& deltaAngle += 360;
&&&&&&&&&&&&&&& deltaAngle %= 360;
&&&&&&&&&&&&&&& if (deltaAngle & 3 || deltaAngle & 357)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& deltaAngle = 0;
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& Angle = deltaA
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& IsRotated(this);
&&&&&&&&&&& }
&&&&&&&&&&& else if (isTranslate == true)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Point offset = Mouse.GetPosition(null);
&&&&&&&&&&&&&&& double deltaX = offset.X - offsetPrevious.X;
&&&&&&&&&&&&&&& double deltaY = offset.Y - offsetPrevious.Y;
&&&&&&&&&&&&&&& TranslateX += deltaX;
&&&&&&&&&&&&&&& TranslateY += deltaY;
&&&&&&&&&&&&&&& offsetPrevious =
&&&&&&&&&&&&&&& IsTranslated(this);
&&&&&&&&&&& }
&&&&&&& private void mouseLeftButtonUp(object sender, MouseButtonEventArgs e)
&&&&&&&&&&& isRotate =
&&&&&&&&&&& isTranslate =
&&&&&&& private void initLineBorder()
&&&&&&&&&&& double borderThickness = ScreenUnitConverter.PixelToInch(1);
&&&&&&&&&&& LineLeft = new Line();
&&&&&&&&&&& LineLeft.X1 = 0;
&&&&&&&&&&& LineLeft.Y1 = 0;
&&&&&&&&&&& LineLeft.X2 = 0;
&&&&&&&&&&& LineLeft.Y2 = H
&&&&&&&&&&& LineLeft.Stroke = Brushes.S
&&&&&&&&&&& LineLeft.StrokeThickness = borderT
&&&&&&&&&&& LineLeft.Visibility = Visibility.V
&&&&&&&&&&& LineTop = new Line();
&&&&&&&&&&& LineTop.X1 = 0;
&&&&&&&&&&& LineTop.Y1 = 0;
&&&&&&&&&&& LineTop.X2 = W
&&&&&&&&&&& LineTop.Y2 = 0;
&&&&&&&&&&& LineTop.Stroke = Brushes.S
&&&&&&&&&&& LineTop.StrokeThickness = borderT
&&&&&&&&&&& LineTop.Visibility = Visibility.V
&&&&&&&&&&& LineRight = new Line();
&&&&&&&&&&& LineRight.X1 = W
&&&&&&&&&&& LineRight.Y1 = 0;
&&&&&&&&&&& LineRight.X2 = W
&&&&&&&&&&& LineRight.Y2 = H
&&&&&&&&&&& LineRight.Stroke = Brushes.S
&&&&&&&&&&& LineRight.StrokeThickness = borderT
&&&&&&&&&&& LineRight.Visibility = Visibility.V
&&&&&&&&&&& LineBottom = new Line();
&&&&&&&&&&& LineBottom.X1 = 0;
&&&&&&&&&&& LineBottom.Y1 = H
&&&&&&&&&&& LineBottom.X2 = W
&&&&&&&&&&& LineBottom.Y2 = H
&&&&&&&&&&& LineBottom.Stroke = Brushes.S
&&&&&&&&&&& LineBottom.StrokeThickness = borderT
&&&&&&&&&&& LineBottom.Visibility = Visibility.V
&&&&&&&&&&& POJGrid.Children.Add(LineLeft);
&&&&&&&&&&& POJGrid.Children.Add(LineTop);
&&&&&&&&&&& POJGrid.Children.Add(LineRight);
&&&&&&&&&&& POJGrid.Children.Add(LineBottom);
&&&&&&& private void calculateCoordinates()
&&&&&&&&&&& if (LineBottom.IsVisible == false &&
&&&&&&&&&&&&&&& LineLeft.IsVisible == false &&
&&&&&&&&&&&&&&& LineRight.IsVisible == false &&
&&&&&&&&&&&&&&& LineTop.IsVisible == false)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&& double x0 = Rt.CenterX + Margin.L
&&&&&&&&&&& double y0 = Rt.CenterY + Margin.T
&&&&&&&&&&& y0 = -y0;
&&&&&&&&&&& double x1 = Margin.L
&&&&&&&&&&& double y1 = Margin.T
&&&&&&&&&&& y1 = -y1;
&&&&&&&&&&& double gama = (360 - Rt.Angle) * Math.PI / 180;
&&&&&&&&&&& LeftTop.X = x0 + (x1 - x0) * Math.Cos(gama) - (y1 - y0) * Math.Sin(gama) + Tt.X;
&&&&&&&&&&& LeftTop.Y = -1 * (y0 + (x1 - x0) * Math.Sin(gama) + (y1 - y0) * Math.Cos(gama)) + Tt.Y;
&&&&&&&&&&& x1 = Margin.Left + W
&&&&&&&&&&& y1 = Margin.T
&&&&&&&&&&& y1 = -y1;
&&&&&&&&&&& gama = (360 - Rt.Angle) * Math.PI / 180;
&&&&&&&&&&& RightTop.X = x0 + (x1 - x0) * Math.Cos(gama) - (y1 - y0) * Math.Sin(gama) + Tt.X;
&&&&&&&&&&& RightTop.Y = -1 * (y0 + (x1 - x0) * Math.Sin(gama) + (y1 - y0) * Math.Cos(gama)) + Tt.Y;
&&&&&&&&&&& x1 = Margin.Left + W
&&&&&&&&&&& y1 = Margin.Top + H
&&&&&&&&&&& y1 = -y1;
&&&&&&&&&&& gama = (360 - Rt.Angle) * Math.PI / 180;
&&&&&&&&&&& RightBottom.X = x0 + (x1 - x0) * Math.Cos(gama) - (y1 - y0) * Math.Sin(gama) + Tt.X;
&&&&&&&&&&& RightBottom.Y = -1 * (y0 + (x1 - x0) * Math.Sin(gama) + (y1 - y0) * Math.Cos(gama)) + Tt.Y;
&&&&&&&&&&& x1 = Margin.L
&&&&&&&&&&& y1 = Margin.Top + H
&&&&&&&&&&& y1 = -y1;
&&&&&&&&&&& gama = (360 - Rt.Angle) * Math.PI / 180;
&&&&&&&&&&& LeftBottom.X = x0 + (x1 - x0) * Math.Cos(gama) - (y1 - y0) * Math.Sin(gama) + Tt.X;
&&&&&&&&&&& LeftBottom.Y = -1 * (y0 + (x1 - x0) * Math.Sin(gama) + (y1 - y0) * Math.Cos(gama)) + Tt.Y;
&&&&&&& private void initStoryBoard()
&&&&&&&&&&& Name = Id.Name();
&&&&&&&&&&& this.RegisterName(Name, this);
&&&&&&&&&&& DoubleAnimation pOJAnimation = new DoubleAnimation();
&&&&&&&&&&& pOJAnimation.From = 1.0;
&&&&&&&&&&& pOJAnimation.To = 0.0;
&&&&&&&&&&& pOJAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
&&&&&&&&&&& pOJAnimation.AutoReverse =
&&&&&&&&&&& storyboard = new Storyboard();
&&&&&&&&&&& Storyboard.SetTargetName(pOJAnimation, Name);
&&&&&&&&&&& Storyboard.SetTargetProperty(pOJAnimation, new PropertyPath(PieceOfJigsaw.OpacityProperty));
&&&&&&&&&&& storyboard.Children.Add(pOJAnimation);
&&&&&&& private double distance(Point p1, Point p2)
&&&&&&&&&&& return Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y));

参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:741次
排名:千里之外

我要回帖

更多关于 vb编写无界面窗体 的文章

 

随机推荐