Ejemplo n.º 1
0
        private void SolveButton_Click(object sender, EventArgs e)
        {
            int[,] input = new int[9, 9];

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    string key = string.Format("TB{0}{1}", row, col);
                    if (Controls.IndexOfKey(key) < 0)
                        continue;

                    TextBox tb = Controls[key] as TextBox;
                    if (tb != null)
                    {
                        if (!string.IsNullOrEmpty(tb.Text))
                        {
                            input[row, col] = int.Parse(tb.Text);
                        }
                        else
                        {
                            input[row, col] = 0;
                        }
                    }
                }
            }

            _puzzle = new Puzzle(input);

            ThreadStart start = new ThreadStart(SolvePuzzle);
            Thread t = new Thread(start);
            t.Start();

            SolveButton.Text = "";
            SolveButton.Enabled = false;
        }
Ejemplo n.º 2
0
        private void LoadSamplePuzzle(string filename)
        {
            // "Temporary" code to load a default puzzle.
            _puzzle = new Puzzle(filename);
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    if (!_puzzle.Rows[row].Tiles[col].Given)
                        continue;

                    string key = string.Format("TB{0}{1}", row, col);
                    if (Controls.IndexOfKey(key) < 0)
                        continue;

                    TextBox tb = Controls[key] as TextBox;
                    if (tb != null)
                    {
                        tb.Text = _puzzle.Rows[row].Tiles[col].Value.ToString();
                    }
                }
            }
        }