/// <summary> /// Permite exportar el código VRML /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnVRML_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "Save file as..."; dialog.Filter = "Simulación 3D (*.wrl)|"; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { Laberinto.CrearBackup(); if (Laberinto3D.Camino == null) { Laberinto.Resolver(this.CreateGraphics()); } String sCodigo = VRML.Crear(Laberinto.Matriz); Laberinto.RestaurarBackup(); //Escribe el archivo en disco using (StreamWriter outfile = new StreamWriter(dialog.FileName.Replace(".wrl", String.Empty) + ".wrl")) { outfile.Write(sCodigo); } } }
/// <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) { } }
/// <summary> /// Genera el código VRML para el laberinto autoconstruido /// </summary> /// <param name="iMatriz"></param> /// <returns></returns> public static String Crear(List <Fila> iMatriz) { //Construye las habitaciones Laberinto.QuitarParedesRedunantes(); sbHabitaciones.Clear(); for (int i = 0; i < iMatriz.Count; i++) { for (int j = 0; j < iMatriz[0].Habitaciones.Count; j++) { sbHabitaciones.Append(new Habitacion3D().ToVRML(iMatriz[i].Habitaciones[j])); } } //Construye el recorrido con la solución sbRecorrido.Clear(); sbRecorrido.Append(new Laberinto3D().TransformText()); //Construye el Avatar sbAvatar.Clear(); sbAvatar.Append(new Avatar3D().TransformText()); return(new VRML().TransformText()); }
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()); }
private void btnResolver_Click(object sender, EventArgs e) { //Resuelve el laberinto Laberinto.Resolver(this.CreateGraphics()); }