Imports System.Threading
Public Class Form1
Dim esperarJugador As Boolean
Dim INTERVALO_COLORES As Integer
Private Const INTERVALO_COLORES_DEFECTO As Integer = 750
Private Const INTERVALO_PARPADEO As Integer = 100
Dim NUMERO_ITERACIONES As Integer = 5
'Dim coloresPulsados As New ArrayList()
Dim coloresCorrectos As New ArrayList()
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim aleatorio As New Random()
Dim color As Integer
coloresCorrectos.Clear()
For i As Integer = 1 To NUMERO_ITERACIONES
color = aleatorio.Next(1, 4)
Select Case color
Case 1
lbl1.BackColor = Drawing.Color.Brown
Me.Refresh()
Thread.Sleep(INTERVALO_PARPADEO)
lbl1.BackColor = Drawing.Color.Red
coloresCorrectos.Add(1)
Case 2
lbl2.BackColor = Drawing.Color.Peru
Me.Refresh()
Thread.Sleep(INTERVALO_PARPADEO)
lbl2.BackColor = Drawing.Color.Orange
coloresCorrectos.Add(2)
Case 3
lbl3.BackColor = Drawing.Color.YellowGreen
Me.Refresh()
Thread.Sleep(INTERVALO_PARPADEO)
lbl3.BackColor = Drawing.Color.Olive
coloresCorrectos.Add(3)
Case 4
lbl4.BackColor = Drawing.Color.Aqua
Me.Refresh()
Thread.Sleep(INTERVALO_PARPADEO)
lbl4.BackColor = Drawing.Color.CadetBlue
coloresCorrectos.Add(4)
Case Else
End Select
Me.Refresh()
Thread.Sleep(INTERVALO_COLORES)
Next
'Hay que detectar los colores pulsados por el usuario a partir de este momento, y en cuanto no coincida
'con las mostradas anteriormente se indica el error.
esperarJugador = True
End Sub
'Inicializamos las variables necesarias
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
esperarJugador = False
End Sub
Private Sub lbl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click
'Es el turno del jugador
CType(sender, Label).BackColor = Color.Brown
Me.Refresh()
Thread.Sleep(50)
CType(sender, Label).BackColor = Color.Red
Me.Refresh()
If esperarJugador = True Then
If CType(coloresCorrectos(0), Integer) = 1 Then
coloresCorrectos.RemoveAt(0)
If coloresCorrectos.Count = 0 Then
esperarJugador = False
MessageBox.Show("CONGRATULATIONS!")
nudNivel.Value += 1
End If
Else
esperarJugador = False
MessageBox.Show("GAME OVER!")
End If
End If
End Sub
Private Sub lbl2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl2.Click
'Es el turno del jugador
CType(sender, Label).BackColor = Color.Peru
Me.Refresh()
Thread.Sleep(50)
CType(sender, Label).BackColor = Color.Orange
Me.Refresh()
If esperarJugador = True Then
If CType(coloresCorrectos(0), Integer) = 2 Then
coloresCorrectos.RemoveAt(0)
If coloresCorrectos.Count = 0 Then
esperarJugador = False
MessageBox.Show("CONGRATULATIONS!")
nudNivel.Value += 1
End If
Else
esperarJugador = False
MessageBox.Show("GAME OVER!")
End If
End If
End Sub
Private Sub lbl3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl3.Click
'Es el turno del jugador
CType(sender, Label).BackColor = Color.YellowGreen
Me.Refresh()
Thread.Sleep(50)
CType(sender, Label).BackColor = Color.Olive
Me.Refresh()
If esperarJugador = True Then
If CType(coloresCorrectos(0), Integer) = 3 Then
coloresCorrectos.RemoveAt(0)
If coloresCorrectos.Count = 0 Then
esperarJugador = False
MessageBox.Show("CONGRATULATIONS!")
nudNivel.Value += 1
End If
Else
esperarJugador = False
MessageBox.Show("GAME OVER!")
End If
End If
End Sub
Private Sub lbl4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl4.Click
'Es el turno del jugador
CType(sender, Label).BackColor = Color.Aqua
Me.Refresh()
Thread.Sleep(50)
CType(sender, Label).BackColor = Color.CadetBlue
Me.Refresh()
If esperarJugador = True Then
If CType(coloresCorrectos(0), Integer) = 4 Then
coloresCorrectos.RemoveAt(0)
If coloresCorrectos.Count = 0 Then
esperarJugador = False
MessageBox.Show("CONGRATULATIONS!")
nudNivel.Value += 1
End If
Else
esperarJugador = False
MessageBox.Show("GAME OVER!")
End If
End If
End Sub
Private Sub nudNivel_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudNivel.ValueChanged
If esperarJugador = False Then
NUMERO_ITERACIONES = CInt(nudNivel.Value)
INTERVALO_COLORES = INTERVALO_COLORES_DEFECTO - NUMERO_ITERACIONES * 50
End If
End Sub
End Class
Trabajaste con AppInventor? Es para desarrolar este juego como una aplicacion Android. cualquier ayuda se agradece! Sludos
ResponderEliminar