Example #1
0
        public void InitGrid(int Dim, bool NewSudokuSolverService = true)
        {
            if (GlobalVar.Stato == AppStatus.Starting || GlobalVar.Stato == AppStatus.Waiting)
            {
                AppStatus old = GlobalVar.Stato;
                GlobalVar.Stato = AppStatus.ModifyingGrid;
                if (NewSudokuSolverService)
                {
                    sss = new SudokuSolverService(Dim);
                    sss.FinishSudoku             += Sss_FinishSudoku;
                    sss.NeedTextBoxMatriceResize += Sss_NeedTextBoxMatriceResize;
                }

                try
                {
                    SudokuSolverTextBoxManager tm = sudokuPanel1.Genera(Dim);
                    ResizeForm();

                    tm.SetAllCellAs(NumberType.InsertByUser);
                    int i = tm.SetTextBoxIndexs();

                    sss.TextBoxManager = tm;
                    i++;
                    button1.TabIndex = i;
                    i++;
                    comboBox1.TabIndex = i;
                    comboBox1.Items.Clear();
                    comboBox1.SelectedIndex = comboBox1.Items.Add(new ObjTypeRisolutore(() => { sss.RisolviNormaleAsync(); }, "Normale"));
                    comboBox1.Items.Add(new ObjTypeRisolutore(() => { sss.RisolviRicorsioneAsync(); }, "Ricorsione"));
                    comboBox1.Items.Add(new ObjTypeRisolutore(() => { sss.RisolviRicorsioneAsync(false); }, "Ricorsione no step"));
                    comboBox1.Items.Add(new ObjTypeRisolutore(() => { sss.RisolviCombinatoAsync(); }, "Combinato"));
                    comboBox1.Items.Add(new ObjTypeRisolutore(() => { sss.RisolviCombinatoAsync(false); }, "Combinato no step"));
                    i++;
                    button2.TabIndex = i;
                    i++;
                    button3.TabIndex = i;
                    i++;
                    button4.TabIndex = i;

                    timer1.Interval = 1000;
                    Tempo           = new TimeSpanPlus();
                }
                catch (SudokuSolverException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (SudokuPanelException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                GlobalVar.Stato = old;
            }
        }
Example #2
0
        public SudokuSolverTextBoxManager Genera(int Dimensione)
        {
            SudokuSolverTextBoxManager sss = new SudokuSolverTextBoxManager();

            TextBoxPlus[] ArrTemp  = new TextBoxPlus[Dimensione * Dimensione];
            int           ArrTempI = 0;

            double ris = ((double)Dimensione).Sqrt();

            if (!ris.IsInteger())
            {
                throw new SudokuPanelException("Valore non accettato per la generazione dello schema");
            }

            Controls.Clear();
            NumRow = (int)ris;
            TextBoxPlus preV = null;
            TextBoxPlus preO = null;

            for (int i = 0; i < Dimensione; i++)
            {
                TextBoxPlus t = (TextBoxPlus) new TextBoxPlus().SetSize(_CellWidth, _CellHeight);
                if (preV == null)
                {
                    AddVerticalControl(t, null, 0, 0);
                }
                else
                {
                    AddVerticalControl(t, preV, 0, i % NumRow == 0 ? _PlusSpace : _NormalSpace);
                }

                preO = t;
                preV = t;
                ArrTemp[ArrTempI++] = t;

                for (int j = 1; j < Dimensione; j++)
                {
                    TextBoxPlus tt = (TextBoxPlus) new TextBoxPlus().SetSize(_CellWidth, _CellHeight);
                    AddOrizzontalControl(tt, preO, j % NumRow == 0 ? _PlusSpace : _NormalSpace, 0);
                    preO = tt;
                    ArrTemp[ArrTempI++] = tt;
                }
            }


            sss.SetArrayTextBox(ArrTemp);
            return(sss);
        }
Example #3
0
        public SudokuSolverTextBoxManager Genera(int Dimensione)
        {
            SudokuSolverTextBoxManager sss = new SudokuSolverTextBoxManager();
            TextBoxPlus[] ArrTemp = new TextBoxPlus[Dimensione * Dimensione];
            int ArrTempI = 0;

            double ris = ((double)Dimensione).Sqrt();
            if(!ris.IsInteger())
                throw new SudokuPanelException("Valore non accettato per la generazione dello schema");

            Controls.Clear();
            NumRow = (int)ris;
            TextBoxPlus preV = null;
            TextBoxPlus preO = null;
            for (int i = 0; i < Dimensione; i++)
            {
                TextBoxPlus t = (TextBoxPlus)new TextBoxPlus().SetSize(_CellWidth, _CellHeight);
                if (preV == null)
                    AddVerticalControl(t, null, 0, 0);
                else
                    AddVerticalControl(t, preV, 0, i % NumRow == 0 ? _PlusSpace : _NormalSpace);

                preO = t;
                preV = t;
                ArrTemp[ArrTempI++] = t;

                for (int j = 1; j < Dimensione; j++)
                {
                    TextBoxPlus tt = (TextBoxPlus)new TextBoxPlus().SetSize(_CellWidth, _CellHeight);
                    AddOrizzontalControl(tt, preO, j % NumRow == 0 ? _PlusSpace : _NormalSpace, 0);
                    preO = tt;
                    ArrTemp[ArrTempI++] = tt;
                }
            }

            sss.SetArrayTextBox(ArrTemp);
            return sss;
        }
 public SudokuSolverService(SudokuSolverService sss)
 {
     mngMat = sss.mngMat.Clone();
     mngTxb = sss.mngTxb;
 }