Esempio n. 1
0
 private void ClearResult()
 {
     for (int i = 0; i < CA_Main.Children.Count; i++)
     {
         Button b = CA_Main.Children[i] as Button;
         if (b != null)
         {
             ButtonProperty bp = b.Tag as ButtonProperty;
             if (bp.Type == 4 || bp.Type == 5)
             {
                 bp.Type        = 0;
                 bp.Distance    = -1;
                 bp.EvaDistance = -1;
                 bp.Parent      = -1;
                 b.Style        = this.FindResource("CommonButtonStyle") as Style;
             }
             if (b.Content != null)
             {
                 ArrowControl ar = b.Content as ArrowControl;
                 ar.SetDistance(0);
                 ar.SetEvaDistance(0);
                 ar.SetSumDistance(0);
                 if (ar != null)
                 {
                     ar.Visibility = Visibility.Hidden;
                 }
             }
         }
     }
 }
Esempio n. 2
0
 private void ShowResult(ResultCollection ret)
 {
     if (ret.parentMap != null)
     {
         for (int i = 0; i < size; i++)
         {
             for (int j = 0; j < size; j++)
             {
                 Button         b     = buttonMap[i, j];
                 ArrowControl   arrow = b.Content as ArrowControl;
                 ButtonProperty bp    = buttonMap[i, j].Tag as ButtonProperty;
                 if (ret.parentMap[i, j] != -1)
                 {
                     arrow.Visibility = Visibility.Visible;
                     bp.Parent        = ret.parentMap[i, j];
                     arrow.SetDirection(ret.parentMap[i, j]);
                 }
             }
         }
     }
     if (ret.resultMap != null)
     {
         for (int i = 0; i < size; i++)
         {
             for (int j = 0; j < size; j++)
             {
                 Button         b    = buttonMap[i, j];
                 ButtonProperty bp   = buttonMap[i, j].Tag as ButtonProperty;
                 int            type = ret.resultMap[i, j];
                 if (type == 4)
                 {
                     b.Style = FindResource("PathButtonStyle") as Style;
                     bp.Type = type;
                     b.Tag   = bp;
                 }
                 if (type == 5)
                 {
                     b.Style = FindResource("TraveledButtonStyle") as Style;
                     bp.Type = type;
                     b.Tag   = bp;
                 }
             }
         }
     }
     if (ret.distanceMap != null)
     {
         for (int i = 0; i < size; i++)
         {
             for (int j = 0; j < size; j++)
             {
                 Button         b     = buttonMap[i, j];
                 ArrowControl   arrow = b.Content as ArrowControl;
                 ButtonProperty bp    = buttonMap[i, j].Tag as ButtonProperty;
                 if (ret.distanceMap[i, j] != int.MaxValue)
                 {
                     arrow.Visibility = Visibility.Visible;
                     bp.Parent        = ret.parentMap[i, j];
                     bp.Distance      = ret.distanceMap[i, j];
                     if (ret.evaDistanceMap != null)
                     {
                         bp.EvaDistance = ret.evaDistanceMap[i, j];
                     }
                     arrow.SetDistance(ret.distanceMap[i, j]);
                     if (ret.evaDistanceMap != null)
                     {
                         arrow.SetEvaDistance(ret.evaDistanceMap[i, j]);
                     }
                     else
                     {
                         arrow.SetEvaDistance(0);
                     }
                     if (ret.evaDistanceMap != null)
                     {
                         arrow.SetSumDistance(ret.distanceMap[i, j] + ret.evaDistanceMap[i, j]);
                     }
                     else
                     {
                         arrow.SetEvaDistance(0);
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
        private void InitMap(int size)
        {
            this.st        = null;
            this.ed        = null;
            this.size      = size;
            this.map       = new int[size, size];
            this.buttonMap = new Button[size, size];
            int count = 0;

            for (int i = 0; i < CA_Main.Children.Count; i++)
            {
                Button b = CA_Main.Children[i] as Button;
                if (b != null)
                {
                    count++;
                    b.Style      = this.FindResource("CommonButtonStyle") as Style;
                    b.Visibility = Visibility.Collapsed;
                    if (b.Content != null)
                    {
                        ArrowControl ar = b.Content as ArrowControl;
                        if (ar != null)
                        {
                            ar.Visibility = Visibility.Hidden;
                        }
                    }
                }
            }
            if (count < size * size)
            {
                for (int i = 0; i < size * size - count; i++)
                {
                    Button b = new Button();
                    b.Style = this.FindResource("CommonButtonStyle") as Style;
                    b.PreviewMouseLeftButtonDown  += new MouseButtonEventHandler(b_PreviewMouseLeftButtonDown);
                    b.PreviewMouseRightButtonDown += new MouseButtonEventHandler(b_PreviewMouseRightButtonDown);
                    b.PreviewMouseMove            += new MouseEventHandler(b_PreviewMouseMove);
                    CA_Main.Children.Add(b);
                    ArrowControl arrow = new ArrowControl();
                    arrow.Width  = blockWidth - 1;
                    arrow.Height = blockWidth - 1;
                    arrow.HorizontalAlignment = HorizontalAlignment.Center;
                    arrow.VerticalAlignment   = VerticalAlignment.Center;
                    b.Content        = arrow;
                    arrow.Visibility = Visibility.Hidden;
                }
            }
            int index = 0;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    ButtonProperty bp = new ButtonProperty(i, j, 0);
                    Button         b  = (CA_Main.Children[index] as Button);
                    buttonMap[i, j] = b;
                    b.Tag           = bp;
                    index++;
                    Canvas.SetLeft(b, bp.X * blockWidth);
                    Canvas.SetTop(b, bp.Y * blockWidth);
                    b.Visibility = Visibility.Visible;
                }
            }
        }