martes, 2 de julio de 2013

PROYECTOS


EJERCICIOS DEL CUARTO CICLO DE INFORMATICA
PROYECTOS

FMAIN


EJECUTABLE



' Gambas class file

PRIVATE NunCanton AS Integer
PRIVATE NunCanton1 AS Integer
PRIVATE NunCanton2 AS Integer
PRIVATE NunCanton3 AS Integer
PRIVATE NunCanton4 AS Integer
PRIVATE NunCanton5 AS Integer
PRIVATE NunCanton6 AS Integer
PRIVATE NunCanton7 AS Integer
PRIVATE opcionseleccionada AS Integer
PRIVATE imagen1 AS Picture
PRIVATE imagen2 AS Picture
PUBLIC SUB _new()
END

PUBLIC SUB Form_Open()
ME.Title = "EJEMPLO CON TREEVIEW"
ME.Center
Arbol.Add("ProvinciaBolivar", "ProvinciaBolivar") 'Nodo Raiz
Arbol.Add("Guaranda", "Guaranda",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("Chimbo", "Chimbo",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("San Miguel", "San Miguel",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("Chillanes", "Chillanes",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("Caluma", "Caluma",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("Echandia", "Echandia",, "ProvinciaBolivar") 'Nodo Padre
Arbol.Add("Las Naves", "Las Naves",, "ProvinciaBolivar") 'Nodo Padre

Arbol["ProvinciaBolivar"].Expanded = TRUE ' Permite ver en nodo raiz extendido

NunCanton = 1 'Inicializa el contador de personas
NunCanton1 = 1
NunCanton2 = 1
NunCanton3 = 1
NunCanton4 = 1
NunCanton5 = 1
NunCanton6 = 1
END



PUBLIC SUB Adicionar_Click()
IF RadioButton1.Value = TRUE
opcionseleccionada = 0
ENDIF
IF RadioButton2.Value = TRUE
opcionseleccionada = 1
ENDIF
IF RadioButton3.Value = TRUE
opcionseleccionada = 2
ENDIF
IF RadioButton4.Value = TRUE
opcionseleccionada = 3
ENDIF
IF RadioButton5.Value = TRUE
opcionseleccionada = 4
ENDIF
IF RadioButton6.Value = TRUE
opcionseleccionada = 5
ENDIF
IF RadioButton7.Value = TRUE
opcionseleccionada = 6
ENDIF

SELECT CASE opcionseleccionada

CASE 0
Arbol.Add("Guaranda-" & NunCanton, "Guaranda-" & NunCanton, imagen1, "Guaranda")
NunCanton += 1

CASE 1
Arbol.Add("Chimbo-" & NunCanton1, "Chimbo-" & NunCanton1, imagen1, "Chimbo")
NunCanton1 += 1

CASE 2
Arbol.Add("San Miguel-" & NunCanton2, "San Miguel-" & NunCanton2, imagen1, "San Miguel")
NunCanton2 += 1

CASE 3
Arbol.Add("Chillanes-" & NunCanton3, "Chillanes-" & NunCanton3, imagen1, "Chillanes")
NunCanton3 += 1
CASE 4
Arbol.Add("Caluma-" & NunCanton4, "Caluma-" & NunCanton4, imagen1, "Caluma")
NunCanton4 += 1
CASE 5
Arbol.Add("Echandia-" & NunCanton5, "Echandia-" & NunCanton5, imagen1, "Echandia")
NunCanton5 += 1
CASE 6
Arbol.Add("Las Naves-" & NunCanton6, "Las Naves-" & NunCanton6, imagen1, "Las Naves")
NunCanton6 += 1

END SELECT
END


PUBLIC SUB Button3_Click()

QUIT

END


PUBLIC SUB Borrarelem_Click()
IF Arbol.Key <> "ProvinciaBolivar" AND Arbol.Key <> "Guaranda" AND Arbol.Key <> "Chimbo" AND Arbol.Key <> "San Miguel" AND Arbol.Key <> "Chillanes" AND Arbol.Key <> "Caluma" AND Arbol.Key <> "Echandia" AND Arbol.Key <> "Las Naves" THEN
Arbol.Remove(Arbol.Key)
ELSE
Message.Info("No se puede eliminar el nodo raiz o padre")
ENDIF
END





FMAIN







PUBLIC SUB reiniciar()
CONTRAPC.Close
CONTRAPC.show
END
PUBLIC SUB reinicio()
COMPETENCIA.Close
COMPETENCIA.show
END
' Gambas class file


PRIVATE MatrizObjetos AS Object[]
PRIVATE Inicializado AS Boolean
PRIVATE LargoCadena AS Integer
PRIVATE Fallos AS Integer
PRIVATE Letras AS Integer
PRIVATE aciertos AS Integer
PRIVATE blancos AS Integer

PUBLIC SUB Form_Open()


TextBox1.SetFocus
TextErrores.Text = "6"
Elegir
TextTiempo.Text = 120
aciertos = 0
END
PUBLIC SUB Elegir()
DIM PartesCadena AS String
DIM TextBox AS TextBox
DIM Caracter AS String
DIM X, y AS Integer
DIM NombreLibro AS String
DIM Libro AS String[]
DIM CadenaCompleta AS String
DIM Label AS Label
DIM Lugar AS Integer
'Elegir aleatoriamente un libro de la lista y copiarla e
PictureBox1.Picture = picture["descarga.jpg"]
'Asignar el nombre al libro
NombreLibro = TextBox1.Text
'Pasar a minuscula
NombreLibro = LCase(NombreLibro)
'Dividir caracteres
Libro = Split(NombreLibro)
'Juntar nombre del libro
FOR EACH PartesCadena IN Libro
CadenaCompleta = CadenaCompleta & PartesCadena
NEXT
'Tomar largo del libro
LargoCadena = Len((CadenaCompleta))
'Inicializar variable letras (cantidad a aceptar)
Letras = LargoCadena
IF NOT Inicializado THEN
'Creacion de la matriz de textbox
MatrizObjetos = NEW Object[]
'Numero de textbox
FOR X = 1 TO LargoCadena
'Creacion de los textbox
TextBox = NEW TextBox(ME)
Label = NEW Label(ME)
TextBox.X = (X * 6 + X) * 3 + 2
TextBox.Y = 180
TextBox.Width = 18
TextBox.Height = 40
TextBox.Visible = TRUE
Label.X = (X * 6 + X) * 3 + 2
Label.Y = 230
Label.Width = 18
Label.Height = 5
Label.Background = Color.Black
'Lectura de los caracteres de la cadena y colocacion en los textbox
Caracter = Mid(CadenaCompleta, X, 1)
TextBox.Text = Caracter
MatrizObjetos.Add(TextBox, x)
'Bloquearlos textbox para que el usuario no pueda escribir en ellos
'Comprovar si es espacio vacio y cambiar color de fondo en caso contrario hacer textbox invisible
IF TextBox.Text = " " THEN
TextBox.Background = Color.Blue
'Restapetar espacios vacios a variable letra
Letras = Letras - 1
ELSE
TextBox.Visible = FALSE
ENDIF
NEXT
ENDIF
TextTirarLetra.SetFocus
TextAcertar.Text = Letras
blancos = 0
FOR Y = 0 TO LargoCadena - 1
IF MatrizObjetos[Y].Text = " " THEN
blancos = blancos + 1
END IF
NEXT
END
PUBLIC SUB BntTirarLetra_Click()
DIM Y AS Integer
DIM Buena AS Boolean
DIM Falta AS Integer
Falta = Letras
Timer1.Enabled = TRUE
'Inicializar variable buena (acierto) como falsa
Buena = FALSE
IF TextTirarLetra.Text = "" OR InStr((TextUsadas.Text), (TextTirarLetra.text)) > 0 THEN
Message.Info("Debe escribir otra letra Aceptar")
TextTirarLetra.Clear
TextTirarLetra.Setfocus
ELSE
FOR Y = 0 TO LargoCadena - 1
IF MatrizObjetos[Y].Text = TextTirarLetra.Text THEN
MatrizObjetos[y].visible = TRUE
Falta = Falta - 1
aciertos = aciertos + 1
TextAcertar.Text = aciertos
Letras = Falta
Buena = TRUE
END IF
NEXT
TextUsadas.Text = TextUsadas.Text & TextTirarLetra.Text
TextTirarLetra.Clear
TextTirarLetra.SetFocus
IF Buena = FALSE THEN
TextErrores.Text = TextErrores.Text - 1
cargar_imagenes
END IF
ENDIF
'Si acertaron todas las letras finalizar juego
IF Falta = "0"
TextTirarLetra.Enabled = FALSE
PictureBox1.Picture = Picture["images.jpg"]
Label7.Visible = TRUE
Timer1.enabled = FALSE
ENDIF
END

PUBLIC SUB BntNuevo_Click()
Label7.Visible = FALSE
REINICIO.reinicio

END

PUBLIC SUB BntSalir_Click()

ME.Close

END

PUBLIC SUB Timer1_Timer()
DIM y AS Integer
'—————controlar que el timer no este en 0,si es asì bloquear botones y mostrar solucion
IF TextTiempo.text = "0" THEN
Timer1.enabled = FALSE
BntTirarLetra.enabled = FALSE
PictureBox1.Picture = picture["perdiste.jpg"]
TextTirarLetra.Enabled = FALSE
FOR y = 0 TO LargoCadena - 1
MatrizObjetos[y].visible = TRUE
NEXT
ELSE
'————————————–ir restando el tiempo y mostrarlo en el textbox
TextTiempo.text = TextTiempo.text - 1
ENDIF
END


PUBLIC SUB BntParar_Click()

Timer1.enabled = FALSE
TextTirarLetra.SetFocus
BntParar.enabled = FALSE

END

PUBLIC SUB cargar_imagenes()
DIM y AS Integer
'———————————cargar imagen según errores restantes, cuando no queden m às
'———————————- bloquear botones y mostrar solucion
IF TextErrores.Text = "0" THEN
PictureBox1.Picture = picture["perdiste.jpg"]
TextTirarLetra.Enabled = FALSE
Timer1.Enabled = FALSE
END IF
IF TextErrores.Text = "1" THEN PictureBox1.picture = picture["1.jpg"]
IF TextErrores.Text = "2" THEN PictureBox1.Picture = picture["2.jpg"]
IF TextErrores.Text = "3" THEN PictureBox1.Picture = picture["3.jpg"]
IF TextErrores.Text = "4" THEN PictureBox1.Picture = picture["4.jpg"]
IF TextErrores.Text = "5" THEN PictureBox1.Picture = Picture["5.jpg"]
END





PUBLIC SUB btncargar_Click()

IF TextBox1.text = "" THEN
Message.Info("debe escribir algo con que jugar")
TextBox1.setfocus

ELSE
elegir
END IF

END





Gambas class file

PRIVATE MatrizObjetos AS Object[]
PRIVATE Inicializado AS Boolean
PRIVATE LargoCadena AS Integer
PRIVATE Fallos AS Integer
PRIVATE Letras AS Integer
PRIVATE aciertos AS Integer
PRIVATE blancos AS Integer

PUBLIC SUB Form_Open()

ListBox1.Add("La Iliada")
ListBox1.Add("La Odisea")
ListBox1.Add("Cien años de Soledad")
ListBox1.Add("Kramer versus Kramer")
ListBox1.Add("La balada de pistolero")
TextErrores.Text = "6"
Elegir
TextBox1.Visible = FALSE
TextTiempo.Text = 120
aciertos = 0
END
PUBLIC SUB Elegir()
DIM PartesCadena AS String
DIM TextBox AS TextBox
DIM Caracter AS String
DIM X, y AS Integer
DIM NombreLibro AS String
DIM Libro AS String[]
DIM CadenaCompleta AS String
DIM Label AS Label
DIM Lugar AS Integer
'Elegir aleatoriamente un libro de la lista y copiarla e
PictureBox1.Picture = picture["descarga.jpg"]
Lugar = Int(Rnd() * (ListBox1.Count))
TextBox1.Text = ListBox1.List[Lugar]
'Asignar el nombre al libro
NombreLibro = TextBox1.Text
'Pasar a minuscula
NombreLibro = LCase(NombreLibro)
'Dividir caracteres
Libro = Split(NombreLibro)
'Juntar nombre del libro
FOR EACH PartesCadena IN Libro
CadenaCompleta = CadenaCompleta & PartesCadena
NEXT
'Tomar largo del libro
LargoCadena = Len((CadenaCompleta))
'Inicializar variable letras (cantidad a aceptar)
Letras = LargoCadena
IF NOT Inicializado THEN
'Creacion de la matriz de textbox
MatrizObjetos = NEW Object[]
'Numero de textbox
FOR X = 1 TO LargoCadena
'Creacion de los textbox
TextBox = NEW TextBox(ME)
Label = NEW Label(ME)
TextBox.X = (X * 6 + X) * 3 + 2
TextBox.Y = 180
TextBox.Width = 18
TextBox.Height = 40
TextBox.Visible = TRUE
Label.X = (X * 6 + X) * 3 + 2
Label.Y = 230
Label.Width = 18
Label.Height = 5
Label.Background = Color.Black
'Lectura de los caracteres de la cadena y colocacion en los textbox
Caracter = Mid(CadenaCompleta, X, 1)
TextBox.Text = Caracter
MatrizObjetos.Add(TextBox, x)
'Bloquearlos textbox para que el usuario no pueda escribir en ellos
'Comprovar si es espacio vacio y cambiar color de fondo en caso contrario hacer textbox invisible
IF TextBox.Text = " " THEN
TextBox.Background = Color.Blue
'Restapetar espacios vacios a variable letra
Letras = Letras - 1
ELSE
TextBox.Visible = FALSE
ENDIF
NEXT
ENDIF
TextTirarLetra.SetFocus
TextAcertar.Text = Letras
blancos = 0
FOR Y = 0 TO LargoCadena - 1
IF MatrizObjetos[Y].Text = " " THEN
blancos = blancos + 1
END IF
NEXT
END
PUBLIC SUB BntTirarLetra_Click()
DIM Y AS Integer
DIM Buena AS Boolean
DIM Falta AS Integer
Falta = Letras
Timer1.Enabled = TRUE
'Inicializar variable buena (acierto) como falsa
Buena = FALSE
IF TextTirarLetra.Text = "" OR InStr((TextUsadas.Text), (TextTirarLetra.text)) > 0 THEN
Message.Info("Debe escribir otra letra Aceptar")
TextTirarLetra.Clear
TextTirarLetra.Setfocus
ELSE
FOR Y = 0 TO LargoCadena - 1
IF MatrizObjetos[Y].Text = TextTirarLetra.Text THEN
MatrizObjetos[y].visible = TRUE
Falta = Falta - 1
aciertos = aciertos + 1
TextAcertar.Text = aciertos
Letras = Falta
Buena = TRUE
END IF
NEXT
TextUsadas.Text = TextUsadas.Text & TextTirarLetra.Text
TextTirarLetra.Clear
TextTirarLetra.SetFocus
IF Buena = FALSE THEN
TextErrores.Text = TextErrores.Text - 1
cargar_imagenes
END IF
ENDIF
'Si acertaron todas las letras finalizar juego
IF Falta = "0"
TextTirarLetra.Enabled = FALSE
PictureBox1.Picture = Picture["images.jpg"]
Label7.Visible = TRUE
Timer1.enabled = FALSE
ENDIF
END

PUBLIC SUB BntNuevo_Click()
Label7.Visible = FALSE
REINICIO.reiniciar

END

PUBLIC SUB BntSalir_Click()

ME.Close

END

PUBLIC SUB Timer1_Timer()
DIM y AS Integer
'—————controlar que el timer no este en 0,si es asì bloquear botones y mostrar solucion
IF TextTiempo.text = "0" THEN
Timer1.enabled = FALSE
BntTirarLetra.enabled = FALSE
PictureBox1.Picture = picture["perdiste.jpg"]
TextTirarLetra.Enabled = FALSE
FOR y = 0 TO LargoCadena - 1
MatrizObjetos[y].visible = TRUE
NEXT
ELSE
'————————————–ir restando el tiempo y mostrarlo en el textbox
TextTiempo.text = TextTiempo.text - 1
ENDIF
END


PUBLIC SUB BntParar_Click()

Timer1.enabled = FALSE
TextTirarLetra.SetFocus
BntParar.enabled = FALSE

END

PUBLIC SUB cargar_imagenes()
DIM y AS Integer
'———————————cargar imagen según errores restantes, cuando no queden m às
'———————————- bloquear botones y mostrar solucion
IF TextErrores.Text = "0" THEN
PictureBox1.Picture = picture["perdiste.jpg"]
TextTirarLetra.Enabled = FALSE
Timer1.Enabled = FALSE
END IF
IF TextErrores.Text = "1" THEN PictureBox1.picture = picture["1.jpg"]
IF TextErrores.Text = "2" THEN PictureBox1.Picture = picture["2.jpg"]
IF TextErrores.Text = "3" THEN PictureBox1.Picture = picture["3.jpg"]
IF TextErrores.Text = "4" THEN PictureBox1.Picture = picture["4.jpg"]
IF TextErrores.Text = "5" THEN PictureBox1.Picture = Picture["5.jpg"]
END

PUBLIC SUB Button3_Click()

ME.Close

END

PUBLIC SUB Button1_Click()

CONTRAPC.Show
FMain.Hide

END

PUBLIC SUB Button2_Click()

COMPETENCIA.Show
FMain.Hide

END