Ce code est un jeu de voitures utilisant les boucles for, next et le contrôle timer
Source / Exemple :
Public Class Form1
Dim z As Byte
Dim x As Byte
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
z = z + 1
If z = 1 Then
PictureBox1.Image = System.Drawing.Bitmap.FromFile(z & ".bmp")
ElseIf z = 2 Then
PictureBox1.Image = System.Drawing.Bitmap.FromFile(z & ".bmp")
ElseIf z = 3 Then
PictureBox1.Image = System.Drawing.Bitmap.FromFile(z & ".bmp")
ElseIf z = 4 Then
PictureBox1.Image = System.Drawing.Bitmap.FromFile(z & ".bmp")
ElseIf z = 5 Then
PictureBox1.Image = System.Drawing.Bitmap.FromFile(z & ".bmp")
z = 0
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Timer1.Interval > 200 And Timer1.Interval < 3000 Then
Timer1.Interval = Timer1.Interval - 100
ElseIf Timer1.Interval < 300 And Timer1.Interval > 200 Then
MsgBox("vous avez été pris au radar", MsgBoxStyle.Information, "RADAR")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Timer1.Interval > 200 And Timer1.Interval < 3000 Then
Timer1.Interval = Timer1.Interval + 100
ElseIf Timer1.Interval > 2500 And Timer1.Interval < 3000 Then
MsgBox("vous roulez beaucoup trop doucement", MsgBoxStyle.Information, "VITESSE")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If PictureBox2.Top < 300 Then
PictureBox2.Top = PictureBox2.Top + 10
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If PictureBox2.Top > 122 Then
PictureBox2.Top = PictureBox2.Top - 10
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
x = x + 1
PictureBox3.Visible = True
Timer3.Enabled = True
PictureBox4.Visible = True
If x = 3 Then
Timer4.Enabled = True
ElseIf x = 8 Then
Timer5.Enabled = True
PictureBox5.Visible = True
ElseIf x = 12 Then
x = 0
PictureBox4.Left = -54
PictureBox5.Left = 665
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Timer3.Interval = Timer1.Interval / 5
PictureBox3.Left = PictureBox3.Left - 10
If PictureBox3.Left < -54 Then
PictureBox3.Left = 665
Timer3.Enabled = False
PictureBox3.Visible = False
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
PictureBox4.Left = PictureBox4.Left + 10
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
PictureBox5.Left = PictureBox5.Left - 10
End Sub
End Class
Conclusion :
pas de bug connus
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.