Example #1
0
        private void ResolverButton_MouseUp(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.AppStarting;
            InfoLabel.ResetText();
            InfoLabel.Text = "Resolviendo...";


            WaitSeconds(0.2);
            CambiarFondoBoton(sender, e);
            if (tablero.ComprobarTablero() == false)
            {
                InfoLabel.Text = "No hay solucion.";
                MostrarCasillas();
                MostrarFondos();
                return;
            }
            else
            {
                // tablero.LimpiarErrores();
                tablero.ResolverTablero();
            }
            MostrarCasillas();
            MostrarFondos();
            this.Cursor = Cursors.Default;

            if (tablero.TableroLleno() == true && tablero.ComprobarTablero() == true)
            {
                InfoLabel.Text = "Tablero resuelto.";
            }
            else
            {
                InfoLabel.Text = "No hay solucion.";
            }


            return;
        }
Example #2
0
        private void Cargarbutton_MouseUp(object sender, MouseEventArgs e)
        {
            InfoLabel.ResetText();


            this.Cursor = Cursors.AppStarting;
            CambiarFondoBoton(sender, e);
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @Directory.GetCurrentDirectory().ToString() + "\\Tableros";
            openFileDialog1.Filter           = "All files (*.*)|*.*|xml (*.xml)|*.xml";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            TextBox auxb;

            Elementos.TableroSudoku tableroAux = tablero;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            InfoLabel.Text = "Cargando tablero.";
                            tablero        = new Elementos.TableroSudoku();
                            tablero.CargarTablero(myStream);
                            myStream.Close();
                            InfoLabel.Text = "Comprobando...";
                            WaitSeconds(0.2);
                            tablero.ResolverTablero();
                            if (tablero.TableroLleno() != true && tablero.ComprobarTablero() != true)
                            {
                                MessageBox.Show("El tablero cargado no se pudo resolver. Seleccione otro tablero.");
                            }
                            else
                            {
                                InfoLabel.Text = "Tablero cargado.";
                            }


                            tablero.LimpiarTablero();
                            LimpiarTablero();
                            for (int i = 0; i < 9; i++)
                            {
                                for (int j = 0; j < 9; j++)
                                {
                                    auxb = (TextBox)tableroSudoku.GetControlFromPosition(j, i);
                                    if (tablero.BuscarCasilla(i, j).Estatico == true)
                                    {
                                        auxb.ReadOnly = true;
                                    }
                                }
                            }
                            MostrarCasillas();
                            MostrarFondos();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

            this.Cursor = Cursors.Default;
        }