SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
http://www.youtube.com/watch?v=755QvP2Rtuw&feature=related
El juego del ahorcado
Crear un nuevo proyecto, agregar form2 y form3.
Form1 base del juego
Agregar un fondo en la propiedad picture= archivo.jpg
Agregar commad para ayuda (llamar al form2), con la instrucción:

Form2.Show

Agregar un frame con 2 OptionButton para 1 y 2 jugadores
Agregar 2 command deben estar invisibles al arrancar el juego y se activan con cada opción.
1.- iniciar el juego
2.- escribir palabra
Form2 Ayuda
Agregar datos con herramientas LABEL, agregar el botón ACEPTAR para salir de la ayuda programar la instrucción en el botón
aceptar: Unload Me
Form3 escribir palabra
Para todos los form la propiedad Borderstyle=5 sizable toolwindow
Para cambiar el color de los botones modificar las propiedades:
Style = 1-Graphical
BackColor = elegir el color deseado

Para cambiar a mayúsculas lo que escriban codificar en lo siguiente
Private Sub L1_Change()
L1.Text = UCase(L1.Text)
End Sub
Para que el cursor pase sólo a la siguiente casilla una vez que el usuario a puesto una letra codifica:
Private Sub L1_KeyPress(KeyAscii As Integer)
L2.SetFocus
End Sub
Cuando llega a la ultima castilla debe pasar al boton
Private Sub L10_KeyPress(KeyAscii As Integer)
Command1.SetFocus End Sub
Cuando se da click al boton de listo:
Private Sub Command1_Click()
If L1 = "" Then
MsgBox "Escriba la palabra, desde la primera casilla"
Else
Form1.L1.Caption = L1.Text
Form1.L2.Caption = L2.Text
<< y así con todas las letras >>
Form1.L10.Caption = L10.Text
If Form1.L1.Caption <> "" Then Form1.R1.Caption = "_": Form1.R1.Visible = True
<< y así con todas las letras del Form1>>
If Form1.L10.Caption <> "" Then
Form1.R10.Caption = "_": Form1.R10.Visible = True
Else
Form1.R10.Caption = ""
End if
Form1.Label1.Visible = True
Form1.Label2.Visible = True
Form1.Label2.Caption = 0
Form1.Text1.Visible = True
Form1.Text1.Text = ""
Form1.Text1.SetFocus
Form1.errores = 0
Unload Me
End If
End Sub
CODIGO DE FORM 1
Public errores As Integer
PARA LIMPIAR LAS CASILLAS
Private Sub limpiar()
Label2.Caption = 0: Label2.Visible = False
Label1.Visible = False: Text1.Visible = False
L1.Caption = "*": R1.Caption = "": x1.Caption = ""
L2.Caption = "": R2.Caption = "": x2.Caption = ""
L3.Caption = "": R3.Caption = "": x3.Caption = ""
L4.Caption = "": R4.Caption = "": x4.Caption = ""
L5.Caption = "": R5.Caption = "": x5.Caption = ""
L6.Caption = "": R6.Caption = "": x6.Caption = ""
L7.Caption = "": R7.Caption = ""
L8.Caption = "": R8.Caption = ""
L9.Caption = "": R9.Caption = ""
L10.Caption = "": R10.Caption = ""
L1.Visible = False: R1.Visible = False: x1.Visible = False
L2.Visible = False: R2.Visible = False: x2.Visible = False
L3.Visible = False: R3.Visible = False: x3.Visible = False
L4.Visible = False: R4.Visible = False: x4.Visible = False
L5.Visible = False: R5.Visible = False: x5.Visible = False
L6.Visible = False: R6.Visible = False: x6.Visible = False
L7.Visible = False: R7.Visible = False
L8.Visible = False: R8.Visible = False
L9.Visible = False: R9.Visible = False
L10.Visible = False: R10.Visible = False
Image1.Visible = False: Image2.Visible = False: Image3.Visible = False: Image4.Visible = False: Image5.Visible = False:
Image6.Visible = False
End Sub
CUANDO EL JUGADOR PIERDE
Private Sub perdiste()
MsgBox "perdiste"
limpiar
End Sub
VERIFICAR SI YA GANO
Private Sub verifica()
If L1 = R1 And L2 = R2 And L3 = R3 And L4 = R4 And L5 = R5 And L6 = R6 And L7 = R7 And L8 = R8 And L9 = R9 And L10 =
R10 Then
MsgBox "Ganaste, felicidades"
limpiar
End If
End Sub
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Command2_Click()
limpiar
Text1.Visible = True
If Label3.Caption = 1 Then L1.Caption = "H": L2.Caption = "O": L3.Caption = "L": L4.Caption = "A": L5.Caption = "":
L6.Caption = "": L7.Caption = "": L8.Caption = "": L9.Caption = "": L10.Caption = ""
If Label3.Caption = 2 Then L1.Caption = "A": L2.Caption = "L": L3.Caption = "E": L4.Caption = "J": L5.Caption = "A":
L6.Caption = "N": L7.Caption = "D": L8.Caption = "R": L9.Caption = "O": L10.Caption = ""
If Label3.Caption = 3 Then L1.Caption = "A": L2.Caption = "R": L3.Caption = "A": L4.Caption = "C": L5.Caption = "E":
L6.Caption = "L": L7.Caption = "I": L8.Caption = "": L9.Caption = "": L10.Caption = ""
If Label3.Caption = 4 Then L1.Caption = "M": L2.Caption = "A": L3.Caption = "R": L4.Caption = "I": L5.Caption = "S":
L6.Caption = "A": L7.Caption = "": L8.Caption = "": L9.Caption = "": L10.Caption = ""
If L1.Caption <> "" Then R1.Caption = "_": R1.Visible = True
If L2.Caption <> "" Then R2.Caption = "_": R2.Visible = True Else R2.Caption = ""
If L3.Caption <> "" Then R3.Caption = "_": R3.Visible = True Else R3.Caption = ""
If L4.Caption <> "" Then R4.Caption = "_": R4.Visible = True Else R4.Caption = ""
If L5.Caption <> "" Then R5.Caption = "_": R5.Visible = True Else R5.Caption = ""
If L6.Caption <> "" Then R6.Caption = "_": R6.Visible = True Else R6.Caption = ""
If L7.Caption <> "" Then R7.Caption = "_": R7.Visible = True Else R7.Caption = ""
If L8.Caption <> "" Then R8.Caption = "_": R8.Visible = True Else R8.Caption = ""
If L9.Caption <> "" Then R9.Caption = "_": R9.Visible = True Else R9.Caption = ""
If L10.Caption <> "" Then R10.Caption = "_": R10.Visible = True Else R10.Caption = ""
Label1.Visible = True
Label2.Visible = True
Text1.Visible = True
Text1.SetFocus
errores = 0
Label3.Caption = Label3.Caption + 1
If Label3.Caption = 5 Then Label3.Caption = 1
End Sub
Private Sub Command3_Click()
errores = 0
Form3.Show
End Sub
Private Sub Option1_Click()
Command2.Visible = True
Command2.Enabled = True
Command3.Visible = False
Command3.Enabled = False
End Sub
Private Sub Option2_Click()
Command2.Visible = False
Command2.Enabled = False
Command3.Visible = True
Command3.Enabled = True
End Sub
Private Sub Option3_Click()
End
End Sub
Private Sub Text1_Change()
Dim band As Boolean
Dim letra As Variant
If Text1.Text <> "" Then
letra = UCase(Text1.Text)
band = False
If letra = L1.Caption Then R1.Caption = letra: band = True
If letra = L2.Caption Then R2.Caption = letra: band = True
If letra = L3.Caption Then R3.Caption = letra: band = True
If letra = L4.Caption Then R4.Caption = letra: band = True
If letra = L5.Caption Then R5.Caption = letra: band = True
If letra = L6.Caption Then R6.Caption = letra: band = True
If letra = L7.Caption Then R7.Caption = letra: band = True
If letra = L8.Caption Then R8.Caption = letra: band = True
If letra = L9.Caption Then R9.Caption = letra: band = True
If letra = L10.Caption Then R10.Caption = letra: band = True
If band = False Then
errores = errores + 1
Label2.Caption = errores
If errores = 1 Then x1.Caption = letra: x1.Visible = True: Image1.Visible = True
If errores = 2 Then x2.Caption = letra: x2.Visible = True: Image2.Visible = True
If errores = 3 Then x3.Caption = letra: x3.Visible = True: Image3.Visible = True
If errores = 4 Then x4.Caption = letra: x4.Visible = True: Image4.Visible = True
If errores = 5 Then x5.Caption = letra: x5.Visible = True: Image5.Visible = True
If errores = 6 Then x6.Caption = letra: x6.Visible = True: Image6.Visible = True: perdiste
Else
verifica
End If
Text1.Text = ""
Text1.Refresh
End If
End Sub
El form1, debe tener los siguientes objetos:
Un label por cada
letra, que adivinará
Labels para
errores

Una X para
cada error

Aquí se guarda la palabra oculta,
estas Label siempre estarán ocultas.

Textbox para
el usuario
La pantalla del form1, finalmente queda de la siguiente forma, y todos los objetos tienen la propiedad VISIBLE=FALSE,
con excepción del botón de ayuda y el frame de Opciones.
Revisen el código que anteriormente les envíe y deduzcan el nombre de las variables.

Label invisible para controlar el núm de
palabra a visualizar cuando es un jugador.

Más contenido relacionado

Más de Ma Isabel Arriaga (20)

Mate1y2 udeei 2do mom
Mate1y2 udeei 2do momMate1y2 udeei 2do mom
Mate1y2 udeei 2do mom
 
Mate1 2do-mom
Mate1 2do-momMate1 2do-mom
Mate1 2do-mom
 
Mate 3 d 2do-mom
Mate 3 d 2do-momMate 3 d 2do-mom
Mate 3 d 2do-mom
 
Mate 3 d 1er mom
Mate 3 d 1er momMate 3 d 1er mom
Mate 3 d 1er mom
 
Mate 1 1er mom
Mate 1 1er momMate 1 1er mom
Mate 1 1er mom
 
Mate1y3 udeei 1er. mom
Mate1y3 udeei 1er. momMate1y3 udeei 1er. mom
Mate1y3 udeei 1er. mom
 
Tradiciones guille 1_abc_18_29_mayo
Tradiciones guille 1_abc_18_29_mayoTradiciones guille 1_abc_18_29_mayo
Tradiciones guille 1_abc_18_29_mayo
 
2 ingles udeei edith
2 ingles udeei edith2 ingles udeei edith
2 ingles udeei edith
 
1 ingles udeei edith
1 ingles udeei edith1 ingles udeei edith
1 ingles udeei edith
 
1 a f cye gabriela
1 a f cye gabriela1 a f cye gabriela
1 a f cye gabriela
 
Int emocional 3ros
Int emocional 3rosInt emocional 3ros
Int emocional 3ros
 
2 d fisica udeei adrianasarabia
2 d fisica udeei adrianasarabia2 d fisica udeei adrianasarabia
2 d fisica udeei adrianasarabia
 
Diseno arquitectonico mayo2
Diseno arquitectonico mayo2Diseno arquitectonico mayo2
Diseno arquitectonico mayo2
 
1ros artes plasticas
1ros artes plasticas1ros artes plasticas
1ros artes plasticas
 
3ros artes plasticas
3ros artes plasticas3ros artes plasticas
3ros artes plasticas
 
2dos artes plasticas
2dos artes plasticas2dos artes plasticas
2dos artes plasticas
 
2dos udeei artes plasticas
2dos udeei artes plasticas2dos udeei artes plasticas
2dos udeei artes plasticas
 
Inteligencia emocional 2os
Inteligencia emocional 2osInteligencia emocional 2os
Inteligencia emocional 2os
 
Espa2 d
Espa2 dEspa2 d
Espa2 d
 
Espa2 d jonathan humberto
Espa2 d jonathan humbertoEspa2 d jonathan humberto
Espa2 d jonathan humberto
 

Ahorcado

  • 1. http://www.youtube.com/watch?v=755QvP2Rtuw&feature=related El juego del ahorcado Crear un nuevo proyecto, agregar form2 y form3. Form1 base del juego Agregar un fondo en la propiedad picture= archivo.jpg Agregar commad para ayuda (llamar al form2), con la instrucción: Form2.Show Agregar un frame con 2 OptionButton para 1 y 2 jugadores Agregar 2 command deben estar invisibles al arrancar el juego y se activan con cada opción. 1.- iniciar el juego 2.- escribir palabra Form2 Ayuda Agregar datos con herramientas LABEL, agregar el botón ACEPTAR para salir de la ayuda programar la instrucción en el botón aceptar: Unload Me
  • 2. Form3 escribir palabra Para todos los form la propiedad Borderstyle=5 sizable toolwindow Para cambiar el color de los botones modificar las propiedades: Style = 1-Graphical BackColor = elegir el color deseado Para cambiar a mayúsculas lo que escriban codificar en lo siguiente Private Sub L1_Change() L1.Text = UCase(L1.Text) End Sub Para que el cursor pase sólo a la siguiente casilla una vez que el usuario a puesto una letra codifica: Private Sub L1_KeyPress(KeyAscii As Integer) L2.SetFocus End Sub Cuando llega a la ultima castilla debe pasar al boton Private Sub L10_KeyPress(KeyAscii As Integer) Command1.SetFocus End Sub
  • 3. Cuando se da click al boton de listo: Private Sub Command1_Click() If L1 = "" Then MsgBox "Escriba la palabra, desde la primera casilla" Else Form1.L1.Caption = L1.Text Form1.L2.Caption = L2.Text << y así con todas las letras >> Form1.L10.Caption = L10.Text If Form1.L1.Caption <> "" Then Form1.R1.Caption = "_": Form1.R1.Visible = True << y así con todas las letras del Form1>> If Form1.L10.Caption <> "" Then Form1.R10.Caption = "_": Form1.R10.Visible = True Else Form1.R10.Caption = "" End if Form1.Label1.Visible = True Form1.Label2.Visible = True Form1.Label2.Caption = 0 Form1.Text1.Visible = True Form1.Text1.Text = "" Form1.Text1.SetFocus Form1.errores = 0 Unload Me End If End Sub CODIGO DE FORM 1 Public errores As Integer PARA LIMPIAR LAS CASILLAS Private Sub limpiar() Label2.Caption = 0: Label2.Visible = False Label1.Visible = False: Text1.Visible = False L1.Caption = "*": R1.Caption = "": x1.Caption = "" L2.Caption = "": R2.Caption = "": x2.Caption = "" L3.Caption = "": R3.Caption = "": x3.Caption = "" L4.Caption = "": R4.Caption = "": x4.Caption = "" L5.Caption = "": R5.Caption = "": x5.Caption = "" L6.Caption = "": R6.Caption = "": x6.Caption = "" L7.Caption = "": R7.Caption = "" L8.Caption = "": R8.Caption = "" L9.Caption = "": R9.Caption = "" L10.Caption = "": R10.Caption = "" L1.Visible = False: R1.Visible = False: x1.Visible = False L2.Visible = False: R2.Visible = False: x2.Visible = False L3.Visible = False: R3.Visible = False: x3.Visible = False L4.Visible = False: R4.Visible = False: x4.Visible = False L5.Visible = False: R5.Visible = False: x5.Visible = False L6.Visible = False: R6.Visible = False: x6.Visible = False L7.Visible = False: R7.Visible = False L8.Visible = False: R8.Visible = False L9.Visible = False: R9.Visible = False
  • 4. L10.Visible = False: R10.Visible = False Image1.Visible = False: Image2.Visible = False: Image3.Visible = False: Image4.Visible = False: Image5.Visible = False: Image6.Visible = False End Sub CUANDO EL JUGADOR PIERDE Private Sub perdiste() MsgBox "perdiste" limpiar End Sub VERIFICAR SI YA GANO Private Sub verifica() If L1 = R1 And L2 = R2 And L3 = R3 And L4 = R4 And L5 = R5 And L6 = R6 And L7 = R7 And L8 = R8 And L9 = R9 And L10 = R10 Then MsgBox "Ganaste, felicidades" limpiar End If End Sub Private Sub Command1_Click() Form2.Show End Sub Private Sub Command2_Click() limpiar Text1.Visible = True If Label3.Caption = 1 Then L1.Caption = "H": L2.Caption = "O": L3.Caption = "L": L4.Caption = "A": L5.Caption = "": L6.Caption = "": L7.Caption = "": L8.Caption = "": L9.Caption = "": L10.Caption = "" If Label3.Caption = 2 Then L1.Caption = "A": L2.Caption = "L": L3.Caption = "E": L4.Caption = "J": L5.Caption = "A": L6.Caption = "N": L7.Caption = "D": L8.Caption = "R": L9.Caption = "O": L10.Caption = "" If Label3.Caption = 3 Then L1.Caption = "A": L2.Caption = "R": L3.Caption = "A": L4.Caption = "C": L5.Caption = "E": L6.Caption = "L": L7.Caption = "I": L8.Caption = "": L9.Caption = "": L10.Caption = "" If Label3.Caption = 4 Then L1.Caption = "M": L2.Caption = "A": L3.Caption = "R": L4.Caption = "I": L5.Caption = "S": L6.Caption = "A": L7.Caption = "": L8.Caption = "": L9.Caption = "": L10.Caption = "" If L1.Caption <> "" Then R1.Caption = "_": R1.Visible = True If L2.Caption <> "" Then R2.Caption = "_": R2.Visible = True Else R2.Caption = "" If L3.Caption <> "" Then R3.Caption = "_": R3.Visible = True Else R3.Caption = "" If L4.Caption <> "" Then R4.Caption = "_": R4.Visible = True Else R4.Caption = "" If L5.Caption <> "" Then R5.Caption = "_": R5.Visible = True Else R5.Caption = "" If L6.Caption <> "" Then R6.Caption = "_": R6.Visible = True Else R6.Caption = "" If L7.Caption <> "" Then R7.Caption = "_": R7.Visible = True Else R7.Caption = "" If L8.Caption <> "" Then R8.Caption = "_": R8.Visible = True Else R8.Caption = "" If L9.Caption <> "" Then R9.Caption = "_": R9.Visible = True Else R9.Caption = "" If L10.Caption <> "" Then R10.Caption = "_": R10.Visible = True Else R10.Caption = "" Label1.Visible = True Label2.Visible = True Text1.Visible = True Text1.SetFocus errores = 0 Label3.Caption = Label3.Caption + 1 If Label3.Caption = 5 Then Label3.Caption = 1 End Sub Private Sub Command3_Click() errores = 0
  • 5. Form3.Show End Sub Private Sub Option1_Click() Command2.Visible = True Command2.Enabled = True Command3.Visible = False Command3.Enabled = False End Sub Private Sub Option2_Click() Command2.Visible = False Command2.Enabled = False Command3.Visible = True Command3.Enabled = True End Sub Private Sub Option3_Click() End End Sub Private Sub Text1_Change() Dim band As Boolean Dim letra As Variant If Text1.Text <> "" Then letra = UCase(Text1.Text) band = False If letra = L1.Caption Then R1.Caption = letra: band = True If letra = L2.Caption Then R2.Caption = letra: band = True If letra = L3.Caption Then R3.Caption = letra: band = True If letra = L4.Caption Then R4.Caption = letra: band = True If letra = L5.Caption Then R5.Caption = letra: band = True If letra = L6.Caption Then R6.Caption = letra: band = True If letra = L7.Caption Then R7.Caption = letra: band = True If letra = L8.Caption Then R8.Caption = letra: band = True If letra = L9.Caption Then R9.Caption = letra: band = True If letra = L10.Caption Then R10.Caption = letra: band = True If band = False Then errores = errores + 1 Label2.Caption = errores If errores = 1 Then x1.Caption = letra: x1.Visible = True: Image1.Visible = True If errores = 2 Then x2.Caption = letra: x2.Visible = True: Image2.Visible = True If errores = 3 Then x3.Caption = letra: x3.Visible = True: Image3.Visible = True If errores = 4 Then x4.Caption = letra: x4.Visible = True: Image4.Visible = True If errores = 5 Then x5.Caption = letra: x5.Visible = True: Image5.Visible = True If errores = 6 Then x6.Caption = letra: x6.Visible = True: Image6.Visible = True: perdiste Else verifica End If Text1.Text = "" Text1.Refresh End If End Sub
  • 6. El form1, debe tener los siguientes objetos: Un label por cada letra, que adivinará Labels para errores Una X para cada error Aquí se guarda la palabra oculta, estas Label siempre estarán ocultas. Textbox para el usuario
  • 7. La pantalla del form1, finalmente queda de la siguiente forma, y todos los objetos tienen la propiedad VISIBLE=FALSE, con excepción del botón de ayuda y el frame de Opciones. Revisen el código que anteriormente les envíe y deduzcan el nombre de las variables. Label invisible para controlar el núm de palabra a visualizar cuando es un jugador.