Advertisement
Guest User

Programa EL HAORCAOH

a guest
Mar 25th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.47 KB | None | 0 0
  1. Public Class Form1
  2.     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
  3.     Dim intentos, numeroPalabra As Integer
  4.     Dim ganar, iniciar As Boolean
  5.  
  6.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTrampa.Click
  7.         If lblTrampa.Visible = True Then
  8.             lblTrampa.Visible = False
  9.         ElseIf lblTrampa.Visible = False Then
  10.             lblTrampa.Visible = True
  11.         End If
  12.     End Sub
  13.  
  14.     Private Sub btnReiniciar_Click(sender As Object, e As EventArgs) Handles btnReiniciar.Click
  15.         'Este evento click las 10 palabras, genera un numero al azar que es el numero de la palaba
  16.         'y le asigna la palabra presente a una variable que se llama "palabraActual"
  17.         'ademas de eso, hace que la picture box sea visible, y que el textbox este disponible
  18.         btnReiniciar.Text = "Reiniciar"
  19.         'tbxVerificar.ReadOnly = False
  20.         tbxVerificar.Enabled = True
  21.         PictureBox1.Visible = True
  22.         ganar = False
  23.         iniciar = True
  24.         intentos = 7
  25.         palabra1 = "a" & "b" & "c" & "d" & "e" & "f"
  26.         palabra2 = "g" & "h" & "i" & "j" & "k" & "l"
  27.         palabra3 = "m" & "n" & "o" & "p" & "q" & "r"
  28.         palabra4 = "s" & "t" & "u" & "v" & "x" & "y"
  29.         palabra5 = "z" & "a" & "b" & "c" & "d" & "e"
  30.         palabra6 = "f" & "g" & "h" & "i" & "j" & "k"
  31.         palabra7 = "l" & "m" & "n" & "o" & "p" & "q"
  32.         palabra8 = "a" & "a" & "b" & "a" & "a" & "a"
  33.         palabra9 = "a" & "a" & "b" & "a" & "a" & "a"
  34.         palabra10 = "a" & "a" & "b" & "a" & "a" & "a"
  35.         lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
  36.         lbl1.Text = "_"
  37.         lbl2.Text = "_"
  38.         lbl3.Text = "_"
  39.         lbl4.Text = "_"
  40.         lbl5.Text = "_"
  41.         lbl6.Text = "_"
  42.         Randomize()
  43.         numeroPalabra = (9 * Rnd() + 1)
  44.  
  45.         If numeroPalabra = 1 Then
  46.             palabraActual = palabra1
  47.         End If
  48.         If numeroPalabra = 2 Then
  49.             palabraActual = palabra2
  50.         End If
  51.         If numeroPalabra = 3 Then
  52.             palabraActual = palabra3
  53.         End If
  54.         If numeroPalabra = 4 Then
  55.             palabraActual = palabra4
  56.         End If
  57.         If numeroPalabra = 5 Then
  58.             palabraActual = palabra5
  59.         End If
  60.         If numeroPalabra = 6 Then
  61.             palabraActual = palabra6
  62.         End If
  63.         If numeroPalabra = 7 Then
  64.             palabraActual = palabra7
  65.         End If
  66.         If numeroPalabra = 8 Then
  67.             palabraActual = palabra8
  68.         End If
  69.         If numeroPalabra = 9 Then
  70.             palabraActual = palabra9
  71.         End If
  72.         If numeroPalabra = 10 Then
  73.             palabraActual = palabra10
  74.         End If
  75.         lblTrampa.Text = palabraActual
  76.  
  77.     End Sub
  78.  
  79.     Private Sub btnVerificar_Click(sender As Object, e As EventArgs) Handles btnVerificar.Click
  80.         Dim i As Integer
  81.         'se declara el contador y se actualiza el label con el numero de intentos
  82.         lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
  83.         'evaluacion letra por letra del textbox con la palabra actual
  84.         'si una de las letras de la palabra actual coincide con la del textbox
  85.         'el o los labels de la letra correspondiente se "revelan" por asi decirlo
  86.         'en realidad el texto del label toma el valor de la letra en el textbox
  87.         For i = 0 To 5
  88.  
  89.             If tbxVerificar.Text = palabraActual(i) Then
  90.                 If i = 0 Then
  91.                     lbl1.Text = tbxVerificar.Text
  92.                 End If
  93.                 If i = 1 Then
  94.                     lbl2.Text = tbxVerificar.Text
  95.                 End If
  96.                 If i = 2 Then
  97.                     lbl3.Text = tbxVerificar.Text
  98.                 End If
  99.                 If i = 3 Then
  100.                     lbl4.Text = tbxVerificar.Text
  101.                 End If
  102.                 If i = 4 Then
  103.                     lbl5.Text = tbxVerificar.Text
  104.                 End If
  105.                 If i = 5 Then
  106.                     lbl6.Text = tbxVerificar.Text
  107.                 End If
  108.             End If
  109.         Next
  110.         'se resta un intento
  111.         If iniciar = True Then
  112.             intentos -= 1
  113.             'se actualizan visualmente los intentos restantes
  114.             lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
  115.         Else
  116.             intentos = 7
  117.         End If
  118.  
  119.         If intentos >= 0 Then
  120.             'se verifica si ya se han descubierto todas las letras de la palabra y se desactiva el texbox si asi sucede
  121.             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
  122.                 lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: " & intentos
  123.                 'tbxVerificar.ReadOnly = True
  124.                 tbxVerificar.Enabled = False
  125.                 MsgBox("Ganaste")
  126.                 ganar = True
  127.             End If
  128.         End If
  129.  
  130.         If ganar = False Then
  131.             PictureBox1.Image = System.Drawing.Bitmap.FromFile(My.Application.Info.DirectoryPath & "C:\0d4.png")
  132.         End If
  133.         '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
  134.         If intentos = 0 And ganar = False Then
  135.             MsgBox("Perdiste")
  136.             tbxVerificar.Enabled = False
  137.             For i = 0 To 5
  138.  
  139.                 If i = 0 Then
  140.                     lbl1.Text = palabraActual(i)
  141.                 End If
  142.                 If i = 1 Then
  143.                     lbl2.Text = palabraActual(i)
  144.                 End If
  145.                 If i = 2 Then
  146.                     lbl3.Text = palabraActual(i)
  147.                 End If
  148.                 If i = 3 Then
  149.                     lbl4.Text = palabraActual(i)
  150.                 End If
  151.                 If i = 4 Then
  152.                     lbl5.Text = palabraActual(i)
  153.                 End If
  154.                 If i = 5 Then
  155.                     lbl6.Text = palabraActual(i)
  156.                 End If
  157.  
  158.             Next
  159.  
  160.         End If
  161.         'se limpia el texbox cada vez que se verifica una letra
  162.         tbxVerificar.Clear()
  163.         If iniciar = False Then
  164.             lblIntentos.Text = "Intentos" & vbNewLine & "Restantes: "
  165.         End If
  166.     End Sub
  167. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement