Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Dim palabra1(6), palabra2(6), palabra3(6), palabra4(6), palabra5(6), palabra6(6), palabra7(6), palabra8(6), palabra9(6), palabra10(6), palabraActual(6) As Char
- Dim intentos, numeroPalabra As Integer
- Dim ganar, iniciar As Boolean
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTrampa.Click
- If lblTrampa.Visible = True Then
- lblTrampa.Visible = False
- ElseIf lblTrampa.Visible = False Then
- lblTrampa.Visible = True
- End If
- End Sub
- Private Sub btnReiniciar_Click(sender As Object, e As EventArgs) Handles btnReiniciar.Click
- 'Este evento click las 10 palabras, genera un numero al azar que es el numero de la palaba
- 'y le asigna la palabra presente a una variable que se llama "palabraActual"
- 'ademas de eso, hace que la picture box sea visible, y que el textbox este disponible
- btnReiniciar.Text = "Reiniciar"
- 'tbxVerificar.ReadOnly = False
- tbxVerificar.Enabled = True
- PictureBox1.Visible = True
- ganar = False
- iniciar = True
- intentos = 7
- palabra1 = "a" & "b" & "c" & "d" & "e" & "f"
- palabra2 = "g" & "h" & "i" & "j" & "k" & "l"
- palabra3 = "m" & "n" & "o" & "p" & "q" & "r"
- palabra4 = "s" & "t" & "u" & "v" & "x" & "y"
- palabra5 = "z" & "a" & "b" & "c" & "d" & "e"
- palabra6 = "f" & "g" & "h" & "i" & "j" & "k"
- palabra7 = "l" & "m" & "n" & "o" & "p" & "q"
- palabra8 = "a" & "a" & "b" & "a" & "a" & "a"
- palabra9 = "a" & "a" & "b" & "a" & "a" & "a"
- palabra10 = "a" & "a" & "b" & "a" & "a" & "a"
- lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
- lbl1.Text = "_"
- lbl2.Text = "_"
- lbl3.Text = "_"
- lbl4.Text = "_"
- lbl5.Text = "_"
- lbl6.Text = "_"
- Randomize()
- numeroPalabra = (9 * Rnd() + 1)
- If numeroPalabra = 1 Then
- palabraActual = palabra1
- End If
- If numeroPalabra = 2 Then
- palabraActual = palabra2
- End If
- If numeroPalabra = 3 Then
- palabraActual = palabra3
- End If
- If numeroPalabra = 4 Then
- palabraActual = palabra4
- End If
- If numeroPalabra = 5 Then
- palabraActual = palabra5
- End If
- If numeroPalabra = 6 Then
- palabraActual = palabra6
- End If
- If numeroPalabra = 7 Then
- palabraActual = palabra7
- End If
- If numeroPalabra = 8 Then
- palabraActual = palabra8
- End If
- If numeroPalabra = 9 Then
- palabraActual = palabra9
- End If
- If numeroPalabra = 10 Then
- palabraActual = palabra10
- End If
- lblTrampa.Text = palabraActual
- End Sub
- Private Sub btnVerificar_Click(sender As Object, e As EventArgs) Handles btnVerificar.Click
- Dim i As Integer
- 'se declara el contador y se actualiza el label con el numero de intentos
- lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
- 'evaluacion letra por letra del textbox con la palabra actual
- 'si una de las letras de la palabra actual coincide con la del textbox
- 'el o los labels de la letra correspondiente se "revelan" por asi decirlo
- 'en realidad el texto del label toma el valor de la letra en el textbox
- For i = 0 To 5
- If tbxVerificar.Text = palabraActual(i) Then
- If i = 0 Then
- lbl1.Text = tbxVerificar.Text
- End If
- If i = 1 Then
- lbl2.Text = tbxVerificar.Text
- End If
- If i = 2 Then
- lbl3.Text = tbxVerificar.Text
- End If
- If i = 3 Then
- lbl4.Text = tbxVerificar.Text
- End If
- If i = 4 Then
- lbl5.Text = tbxVerificar.Text
- End If
- If i = 5 Then
- lbl6.Text = tbxVerificar.Text
- End If
- End If
- Next
- 'se resta un intento
- If iniciar = True Then
- intentos -= 1
- 'se actualizan visualmente los intentos restantes
- lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
- Else
- intentos = 7
- End If
- If intentos >= 0 Then
- 'se verifica si ya se han descubierto todas las letras de la palabra y se desactiva el texbox si asi sucede
- If (lbl1.Text = palabraActual(0)) And (lbl2.Text = palabraActual(1)) And (lbl3.Text = palabraActual(2)) And (lbl4.Text = palabraActual(3)) And (lbl5.Text = palabraActual(4)) And (lbl6.Text = palabraActual(5)) Then
- lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
- 'tbxVerificar.ReadOnly = True
- tbxVerificar.Enabled = False
- MsgBox("Ganaste")
- ganar = True
- End If
- End If
- If ganar = False Then
- PictureBox1.Image = System.Drawing.Bitmap.FromFile(My.Application.Info.DirectoryPath & "C:\0d4.png")
- End If
- 'si los intentos son 0 y aun no se han descubierto todas las letras (vease variable ganar) se notifica la derrota y se revelan las letras de todas formas
- If intentos = 0 And ganar = False Then
- MsgBox("Perdiste")
- tbxVerificar.Enabled = False
- For i = 0 To 5
- If i = 0 Then
- lbl1.Text = palabraActual(i)
- End If
- If i = 1 Then
- lbl2.Text = palabraActual(i)
- End If
- If i = 2 Then
- lbl3.Text = palabraActual(i)
- End If
- If i = 3 Then
- lbl4.Text = palabraActual(i)
- End If
- If i = 4 Then
- lbl5.Text = palabraActual(i)
- End If
- If i = 5 Then
- lbl6.Text = palabraActual(i)
- End If
- Next
- End If
- 'se limpia el texbox cada vez que se verifica una letra
- tbxVerificar.Clear()
- If iniciar = False Then
- lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: "
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement