Esempio n. 1
0
 /// <summary>
 /// Refresca el dibujo del laberinto para que no se pierda
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_Paint(object sender, PaintEventArgs e)
 {
     try
     {
         if (Laberinto.Dibujado)
         {
             Laberinto.Dibujar(this.CreateGraphics());
         }
     }
     catch (Exception) { }
 }
Esempio n. 2
0
        private void btnGenerar_Click_1(object sender, EventArgs e)
        {
            #region Validaciones

            errorProvider1.Clear();

            //Valida campos vacios
            if (cbxAncho.Text.Trim().Length == 0)
            {
                errorProvider1.SetError(cbxAncho, "Debe escribir el ancho del laberinto"); return;
            }
            if (cbxAlto.Text.Trim().Length == 0)
            {
                errorProvider1.SetError(cbxAlto, "Debe escribir el alto del laberinto"); return;
            }

            //Valida los tipos y rangos
            try
            {
                int iAncho = Convert.ToInt32(cbxAncho.Text);
                int iAlto  = Convert.ToInt32(cbxAlto.Text);
                if (iAncho < 4)
                {
                    errorProvider1.SetError(cbxAncho, "El ancho debe ser un número mayor o igual a 4"); return;
                }
                if (iAlto < 4)
                {
                    errorProvider1.SetError(cbxAlto, "El alto debe ser un número mayor o igual a 4"); return;
                }
            }
            catch (Exception)
            {
                errorProvider1.SetError(cbxAncho, "Revise los valores");
                errorProvider1.SetError(cbxAlto, "Revise los valores");
                return;
            }

            pnlControles.Visible = false;
            btnVolver.Visible    = true;
            btnVRML.Visible      = true;
            btnResolver.Visible  = true;
            picLogo.Visible      = false;

            #endregion Validaciones

            //Asigna parámetros
            if (cbxRecorrer.SelectedIndex == 0)
            {
                Laberinto.Recorrido = Direccion.ArribaAbajo;
            }
            if (cbxRecorrer.SelectedIndex == 1)
            {
                Laberinto.Recorrido = Direccion.IzquierdaDerecha;
            }
            Laberinto.Ancho         = Convert.ToInt32(cbxAncho.Text);
            Laberinto.Alto          = Convert.ToInt32(cbxAlto.Text);
            Laberinto.TamanoCasilla = Convert.ToInt32(cbxTamanoCasilla.Text);
            Laberinto.Objetivos     = Convert.ToInt32(cbxObjetivos.Text);
            Laberinto.Retardo_ms    = Convert.ToInt32(cbxRetardo.Text);

            //Autoconstruye un laberinto
            Laberinto.Generar();
            //Lo dibuja en pantalla
            Laberinto.Dibujar(this.CreateGraphics());
        }