Пример #1
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     if (solving)
     {
         solving = false;
         stopThreads();
     }
     generated = false;
     minutes   = 0;
     seconds   = 0;
     CleanPanel_1();
     CleanPanel_2();
     resetArray();
     graphics2.FillRectangle(new SolidBrush(Color.Black), new Rectangle(1205, 220, 150, 120));
     if (comboBox1.SelectedIndex > -1)
     {
         order   = Int32.Parse(comboBox1.SelectedItem.ToString());
         sudoku  = new Sudoku(this, order);
         sudoku2 = new EmptySudoku(this, order, sudoku.GetMatrix(), sudoku.getFiguresList(), sudoku);
         drawSquareLines(x1, y1);
         drawSquareLines(x2, y2);
         drawColorBoxes();
         drawFiguresEdges(0, 0);
         drawFiguresEdges(600, 0);
         drawMatrixNumbers();
         drawOperations(Color.Black);
         drawResultInitialNumbers(Color.Blue);
         generated = true;
     }
     else
     {
         generated = false;
         MessageBox.Show("You must select a size", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     }
 }
Пример #2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Txt Files(.txt)|*.txt";
            openFileDialog1.Title  = "Load Sudoku";
            //First we have to be sure the user select the button save in the saveDialog
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {   //then check if the name the user enters is not empty
                string fileName = openFileDialog1.FileName;
                if (fileName != "")
                {
                    generated = false;
                    bool existingFile = System.IO.File.Exists(fileName);
                    if (existingFile == false)
                    {
                        MessageBox.Show("FileName not found", "FileName Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        openFileDialog1.Dispose();
                    }
                    CleanPanel_1();
                    CleanPanel_2();
                    resetArray();
                    graphics2.FillRectangle(new SolidBrush(Color.Black), new Rectangle(1205, 220, 150, 120));
                    fileSize(fileName);
                    sudoku = new Sudoku(this, order, true);
                    sudoku.LoadSudoku(fileName);
                    sudoku.LoadFigurates(fileName.Insert(fileName.IndexOf('.'), "_Figurates"));
                    sudoku.LoadPartial(fileName.Insert(fileName.IndexOf('.'), "_PartialMatrix"));
                    sudoku2 = new EmptySudoku(this, order, sudoku.GetMatrix(), sudoku.getFiguresList(), sudoku, true);
                    sudoku2.setPartialMatrix(sudoku.getPartialMatrix());
                    drawSquareLines(x1, y1);
                    drawSquareLines(x2, y2);
                    drawColorBoxes();
                    drawFiguresEdges(0, 0);
                    drawFiguresEdges(600, 0);
                    drawMatrixNumbers();
                    drawOperations(Color.Black);
                    drawResultInitialNumbers(Color.Blue);
                    generated = true;
                }
            }
            else
            {
                MessageBox.Show("Unable File name", "FileName Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                openFileDialog1.Dispose();
            }
        }