Vous êtes sur la page 1sur 2

Public Class FrmCarros

Private valor As Byte = 0 'variable para posiconar los pbCarros


Private ctrl As Control = Nothing 'variable para almacenar los pictureBox
Private puntos As Integer = 0 'Almacena los puntos
Private Nivel As Byte = 1 'El nivel
Private Sub UbicarCarro1(ByVal x As Byte)
Select Case x
Case 0 : pbCarro1.Location = New Point(40, -86)
Case 1 : pbCarro1.Location = New Point(173, -86)
End Select
End Sub
Private Sub UbicarCarro2(ByVal x As Byte)
Select Case x
Case 0 : pbCarro2.Location = New Point(173, -270)
Case 1 : pbCarro2.Location = New Point(40, -270)
End Select
End Sub
Private Sub UbicarCarro3(ByVal x As Byte)
Select Case x
Case 0 : pbCarro3.Location = New Point(40, -470)
Case 1 : pbCarro3.Location = New Point(173, -470)
End Select
End Sub
Private Sub DetectarColision()
'
'Creo una lista con los carros en mivimiento(son 3)
'
Dim carros As New List(Of PictureBox)
carros.Add(pbCarro1)
carros.Add(pbCarro2)
carros.Add(pbCarro3)
'
'Recorro la lista y detecto colison con Bounds.IntersectcWith
'(Esta Función me determina si hay intersección con un rectangulo(en este
caso un pictureBox)
' si la hay ocupa el espacio de esta y por lo tanto hay colisión)
'
For Each ctrl In carros
If pbCarro.Bounds.IntersectsWith(ctrl.Bounds) Then
tmMoverCarros.Stop()
MessageBox.Show("Perdiste." & Chr(13) & "Vuelve a interntarlo",
"Información", MessageBoxButtons.OK, MessageBoxIcon.Information)
Reiniciar()
End If
Next
End Sub
Private Sub Reiniciar()
'Inicializo los valores de los textbox
txtNivel.Text = 1
puntos = 0
txtPuntos.Text = puntos
'Posiciono los carros en su posición de origen
UbicarCarro1(0)
UbicarCarro2(0)
UbicarCarro3(0)

'Asigno a 1000 milSeg el tmNivel para volver a empezar


tmNivel.Interval = 1000
End Sub

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


tmMoverCarros.Tick
If pbCarro1.Top >= Me.Height Then
valor = Rnd() * 1
UbicarCarro1(valor)
pbCarro1.Top = -pbCarro1.Height * 2
puntos += 1
txtPuntos.Text = puntos
Else
pbCarro1.Top += 5

End If
'
If pbCarro2.Top >= Me.Height Then
valor = Rnd() * 1
UbicarCarro2(valor)
pbCarro2.Top = -pbCarro2.Height * 2
puntos += 1
txtPuntos.Text = puntos
Else
pbCarro2.Top += 5
End If
'
If pbCarro3.Top >= Me.Height Then
valor = Rnd() * 1
UbicarCarro3(valor)
pbCarro3.Top = -pbCarro3.Height * 2
puntos += 1
txtPuntos.Text = puntos
Else
pbCarro3.Top += 5
End If
DetectarColision()

End Sub

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles


MyBase.KeyDown

Select Case e.KeyCode


Case Keys.Left : pbCarro.Left -= 130
Case Keys.Right : pbCarro.Left += 130
End Select

End Sub

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


btnEmpezar.Click
tmMoverCarros.Start()
pbCarro.Focus()
End Sub

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


tmNivel.Tick
tmNivel.Interval += 1000
If tmNivel.Interval = 10000 Then
txtNivel.Text += Nivel
tmMoverCarros.Interval = 30
ElseIf tmNivel.Interval = 13000 Then
txtNivel.Text += Nivel
tmMoverCarros.Interval = 20
ElseIf tmNivel.Interval = 15000 Then
txtNivel.Text += Nivel
tmMoverCarros.Interval = 10
End If
End Sub
End Class

Vous aimerez peut-être aussi