Exemplo n.º 1
0
        public SudokuCell(UIElementCollection panel, int bsize, SudokuBoard sb)
        {
            this.sb = sb;
            this.bsize = bsize;
            this.children = new List<SudokuCell>();
            this.panel = panel;
            isLeaf = false;
            int size = bsize * bsize;
            int bss = size * size;
            int[] data = new int[bss];
            for (var i = 0; i < bss; i++) data[i] = i;

            for (var i = 0; i < bsize; i++)
            {
                for (var j = 0; j < bsize; j++)
                {
                    var t = new List<int>();
                    for (var k = i * bsize; k < (i + 1) * bsize; k++)
                    {
                        for (var l = j * bsize; l < (j + 1) * bsize; l++)
                        {
                            t.Add(data[k * size + l]);
                        }
                    }
                    var sc = new SudokuCell(this.panel, t.ToArray(), j, i, bsize, sb);
                    children.Add(sc);
                }
            }
        }
Exemplo n.º 2
0
 private SudokuCell(UIElementCollection panel, int[] data, int x, int y, int bsize, SudokuBoard sb)
 {
     this.sb = sb;
     this.bsize = bsize;
     this.panel = panel;
     this.x = x;
     this.y = y;
     if (data.Length > 1)
     {
         isLeaf = false;
         this.children = new List<SudokuCell>();
         for (var i = 0; i < bsize; i++)
             for (var j = 0; j < bsize; j++)
             {
                 var sc = new SudokuCell(panel, new int[] { data[i * bsize + j] }, j, i, bsize, sb);
                 children.Add(sc);
             }
     }
     else
     {
         isLeaf = true;
         this.index = data[0];
     }
 }
Exemplo n.º 3
0
        public void Load(int[] data)
        {
            if (isLeaf)
            {
                int d = data[index];
                if (d > 0)
                {

                    if (children != null)
                    {
                        foreach (var item in children)
                        {
                            panel.Remove(item.ui);
                            panel.Remove(item.border);
                        }
                        children.Clear();
                        children = null;
                    }
                    if (ui == null)
                    {
                        AddUI();
                        updateUI();

                        //DoubleAnimation oLabelAngleAnimation = new DoubleAnimation();
                        //oLabelAngleAnimation.From = 0;
                        //oLabelAngleAnimation.To = 360;
                        //oLabelAngleAnimation.Duration
                        //  = new Duration(new TimeSpan(0, 0, 0, 0, 500));
                        //oLabelAngleAnimation.RepeatBehavior = new RepeatBehavior(4);
                        //ui.LayoutTransform=new System.Windows.Media.ScaleTransform(40 * 1, 1);
                        //ScaleTransform oTransform = ui.LayoutTransform   as ScaleTransform;
                        //oTransform.BeginAnimation(RotateTransform.AngleProperty, oLabelAngleAnimation);

                    }
                    this.Content = d;
                }
                else
                {
                    if (ui != null)
                        panel.Remove(ui);
                    if (children == null)
                    {
                        children = new List<SudokuCell>();
                        var al = sb.Allow(index);
                        for (var i = 0; i < bsize; i++)
                        {
                            for (var j = 0; j < bsize; j++)
                            {
                                var dig = i * bsize + j + 1;
                                var sc = new SudokuCell(panel, new int[] { index }, j, i, bsize, sb);
                                sc.AddUI();
                                sc.Content = al.Contains(dig) ? dig : 0;
                                if (sc.Content > 0) sc.AddMouse();
                                children.Add(sc);

                            }
                        }
                    }
                    else
                    {
                        var al = sb.Allow(index);
                        foreach (var item in children)
                        {
                            var dig = item.y * bsize + item.x + 1;
                            item.Content = al.Contains(dig) ? dig : 0;
                            if (item.Content == 0) item.DelMouse();
                        }
                    }
                }
            }
            else
                foreach (var item in children)
                    item.Load(data);
        }