Vous êtes sur la page 1sur 7

PARA FUTUROS PROGRAMAS:

En cuanto al cdigo, lo ideal es que separaras tu interfaz grfica, de las reglas de


negocio(Subrutinas de cdigo).
Cmo hacerlo?.
1) Crea un modulo llamado modAcciones
2) Dentro de este Declara todas tus variables y crea los procedimientos
necesarios,ejemplo.
Public sub limpiar()
'Aqui va el codigo que restablece todos los controles
End sub
Public sub elegir()
'Aqui va el codigo principal
End sub
3)En el evento Open del formulario, deberas llamar al procedimiento principal.
Public sub Form_Open()
modAcciones.elegir()
End sub
4) En el boton nuevo juego, en su evento click, debes agregar el siguiente
codigo.
Public sub nuevojuego_click()
modAcciones.limpiar()
End sub
Esto es solo un bosquejo, para que tu codigo quede mejor estructurado.
Saludos

Public Class Form1


'tiempo almacena la contabilidad del timer general
Dim tiempo As Integer
Dim tiemporespuesta As Integer
Dim intervalomuestra As Integer
Dim intervalorespuesta As Integer
'almacenan el resultado (correcto-incorrecto) de cada bloque.
Dim bloque1 As Integer 'si la suma da 2, es correcto
Dim bloque2 As Integer 'si la suma da 3, es correcto
Dim bloque3 As Integer 'si la suma da 4, es correcto
Dim bloque4 As Integer 'si la suma da 5, es correcto

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Timer1.Enabled = False
timerrespuesta.Enabled = False
Label1.Text = ""
Labeltiemporesp.Text = ""
NumericUpDownMuestra.Value = 1
NumericUpDownRespuesta.Value = 5
End Sub
Private Sub BotonDelante_Click(sender As Object, e As EventArgs) Handles
BotonDelante.Click
'define intervalos por defecto de los timer
Timer1.Interval = NumericUpDownMuestra.Value * 1000
timerrespuesta.Interval = NumericUpDownRespuesta.Value * 1000
tiempo = 0
tiemporespuesta = 0
'inicia el timer
Timer1.Enabled = True
'pone las variables de bloque (buffer) en cero
bloque1 = 0
bloque2 = 0
bloque3 = 0
bloque4 = 0
'se asegura de que los botones estn visibles al iniciar la prueba
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
'Borra los label de resultados por si ya se ejecut antes la prueba
LabelBloque1.Text = "-"
LabelBloque2.Text = "-"
LabelBloque3.Text = "-"
LabelBloque4.Text = "-"

End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'la variable tiempo aumenta y se muestra en label1. Si picturebox1 est visible, lo
invisibiliza y viceversa
'PictureBox1.Visible = Not PictureBox1.Visible
tiempo = tiempo + 1
Label1.Text = tiempo.ToString
'oculta el boton empezar
BotonDelante.Enabled = False
'secuencia 1 (1-2)
If tiempo = 1 Then
Button1.Visible =
End If
If tiempo = 2 Then
Button1.Visible =
End If
If tiempo = 3 Then
Button2.Visible =
End If
If tiempo = 4 Then
Button2.Visible =

False
True
False
True

End If
'fin secuencia 1 (mostrar todos para que el usuario clickee)
If tiempo = 4 Then
Timer1.Enabled = False
timerrespuesta.Enabled = True
End If
'secuencia 2 (2-4-3)
If tiemporespuesta = 1 Then
timerrespuesta.Enabled = False
Labeltiemporesp.Text = "Pausa"
End If
If tiempo = 5 Then
Button2.Visible = False
End If
If tiempo = 6 Then
Button2.Visible = True
End If
If tiempo = 7 Then
Button4.Visible = False
End If
If tiempo = 8 Then
Button4.Visible = True
End If
If tiempo = 9 Then
Button3.Visible = False
End If
If tiempo = 10 Then
Button3.Visible = True
End If
'fin secuencia 2 (mostrar todos para que el usuario clickee)
If tiempo = 10 Then
Timer1.Enabled = False
timerrespuesta.Enabled = True
End If
'secuencia 3 (3-4-2-1)
If tiemporespuesta = 2 Then
timerrespuesta.Enabled = False
Labeltiemporesp.Text = "Pausa"
End If
If tiempo = 11 Then
Button3.Visible = False
End If
If tiempo = 12 Then
Button3.Visible = True
End If
If tiempo = 13 Then
Button4.Visible = False
End If
If tiempo = 14 Then
Button4.Visible = True
End If
If tiempo = 15 Then
Button2.Visible = False
End If
If tiempo = 16 Then
Button2.Visible = True

End If
If tiempo = 17 Then
Button1.Visible = False
End If
If tiempo = 18 Then
Button1.Visible = True
End If
'fin secuencia 3 (mostrar todos para que el usuario clickee)
If tiempo = 18 Then
Timer1.Enabled = False
timerrespuesta.Enabled = True
End If
'secuencia 4 (1-4-2-3-4)
If tiemporespuesta = 3 Then
timerrespuesta.Enabled = False
Labeltiemporesp.Text = "Pausa"
End If
If tiempo = 19 Then
Button1.Visible = False
End If
If tiempo = 20 Then
Button1.Visible = True
End If
If tiempo = 21 Then
Button4.Visible = False
End If
If tiempo = 22 Then
Button4.Visible = True
End If
If tiempo = 23 Then
Button2.Visible = False
End If
If tiempo = 24 Then
Button2.Visible = True
End If
If tiempo = 25 Then
Button3.Visible = False
End If
If tiempo = 26 Then
Button3.Visible = True
End If
If tiempo = 27 Then
Button4.Visible = False
End If
If tiempo = 28 Then
Button4.Visible = True
End If
'fin secuencia 4 (mostrar todos para que el usuario clickee)
If tiempo = 28 Then
Timer1.Enabled = False
timerrespuesta.Enabled = True
End If
End Sub
'Controla el timer del tiempo de respuesta y las variables asociadas

Private Sub timerrespuesta_Tick(sender As Object, e As EventArgs) Handles


timerrespuesta.Tick
tiemporespuesta = tiemporespuesta + 1
Labeltiemporesp.Text = tiemporespuesta.ToString
'activa el timer tras cada bloque
If tiemporespuesta = 1 Then
Timer1.Enabled = True
timerrespuesta.Enabled = False
End If
If tiemporespuesta = 2 Then
Timer1.Enabled = True
timerrespuesta.Enabled = False
End If
If tiemporespuesta = 3 Then
Timer1.Enabled = True
timerrespuesta.Enabled = False
End If
'final de prueba
If tiemporespuesta = 4 Then
Timer1.Enabled = False
timerrespuesta.Enabled = False
MessageBox.Show("Prueba finalizada")
BotonDelante.Enabled = True
'muestra si fue correcto cada bloque en los label de correcto/incorrecto
If bloque1 = 2 Then
LabelBloque1Correcto.Text = "OK"
LabelBloque1Correcto.BackColor = Color.Green
Else
LabelBloque1Correcto.Text = "X"
LabelBloque1Correcto.BackColor = Color.Red
End If
If bloque2 = 3 Then
LabelBloque2Correcto.Text = "OK"
LabelBloque2Correcto.BackColor = Color.Green
Else
LabelBloque2Correcto.Text = "X"
LabelBloque2Correcto.BackColor = Color.Red
End If
If bloque3 = 4 Then
LabelBloque3Correcto.Text = "OK"
LabelBloque3Correcto.BackColor = Color.Green
Else
LabelBloque3Correcto.Text = "X"
LabelBloque3Correcto.BackColor = Color.Red
End If
If bloque4 = 5 Then
LabelBloque4Correcto.Text = "OK"
LabelBloque4Correcto.BackColor = Color.Green
Else
LabelBloque4Correcto.Text = "X"
LabelBloque4Correcto.BackColor = Color.Red
End If
End If
End Sub
Private Sub BotonColor_Click(sender As Object, e As EventArgs) Handles BotonColor.Click
If ColorDialog1.ShowDialog() = DialogResult.OK Then

Button1.BackColor
Button2.BackColor
Button3.BackColor
Button4.BackColor
End If

=
=
=
=

ColorDialog1.Color
ColorDialog1.Color
ColorDialog1.Color
ColorDialog1.Color

End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'suma1 a cada variable de bloque si el botn1 es parte de la respuesta
If tiemporespuesta >= 0 And tiemporespuesta <= 1 And bloque1 = 0 Then
bloque1 = bloque1 + 1
End If
If tiemporespuesta >= 2 And tiemporespuesta <= 3 And bloque3 = 3 Then
bloque3 = bloque3 + 1
End If
If tiemporespuesta >= 3 And tiemporespuesta <= 4 Then
bloque4 = bloque4 + 1
End If
'Muestra el buffer en los label de resultados
LabelBloque1.Text = bloque1.ToString
LabelBloque2.Text = bloque2.ToString
LabelBloque3.Text = bloque3.ToString
LabelBloque4.Text = bloque4.ToString
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If tiemporespuesta >= 0 And tiemporespuesta <= 1 And bloque1 = 1 Then
bloque1 = bloque1 + 1
End If
If tiemporespuesta >= 1 And tiemporespuesta <= 2 And bloque2 = 0 Then
bloque2 = bloque2 + 1
End If
If tiemporespuesta >= 2 And tiemporespuesta <= 3 And bloque3 = 2 Then
bloque3 = bloque3 + 1
End If
If tiemporespuesta >= 3 And tiemporespuesta <= 4 And bloque4 = 2 Then
bloque4 = bloque4 + 1
End If
'Muestra el buffer en los label de resultados
LabelBloque1.Text = bloque1.ToString
LabelBloque2.Text = bloque2.ToString
LabelBloque3.Text = bloque3.ToString
LabelBloque4.Text = bloque4.ToString
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If tiemporespuesta >= 1 And tiemporespuesta <= 2 And bloque2 = 2 Then
bloque2 = bloque2 + 1
End If
If tiemporespuesta >= 2 And tiemporespuesta <= 3 And bloque3 = 0 Then
bloque3 = bloque3 + 1
End If
If tiemporespuesta >= 3 And tiemporespuesta <= 4 And bloque4 = 3 Then
bloque4 = bloque4 + 1
End If
'Muestra el buffer en los label de resultados
LabelBloque1.Text = bloque1.ToString
LabelBloque2.Text = bloque2.ToString
LabelBloque3.Text = bloque3.ToString
LabelBloque4.Text = bloque4.ToString
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


If tiemporespuesta >= 1 And tiemporespuesta <= 2 And bloque2 = 1 Then
bloque2 = bloque2 + 1
End If
If tiemporespuesta >= 2 And tiemporespuesta <= 3 And bloque3 = 1 Then
bloque3 = bloque3 + 1
End If
If tiemporespuesta >= 3 And tiemporespuesta <= 4 And bloque4 = 1 Or bloque4 = 4
Then
bloque4 = bloque4 + 1
End If
'Muestra el buffer en los label de resultados
LabelBloque1.Text = bloque1.ToString
LabelBloque2.Text = bloque2.ToString
LabelBloque3.Text = bloque3.ToString
LabelBloque4.Text = bloque4.ToString
End Sub
End Class

Vous aimerez peut-être aussi