ce jeu de bateaux est concu avec une musique de fond. il faut cliquer sur les autres bateaux pour leur tirer dessus, mais la police réplique. on a 5 chances.
Source / Exemple :
Public Class Form1
Dim x As Double
Dim a As Double
Dim y As Double
Dim police As Double
Dim tir As Double
Dim rist As Double
Dim tir2 As Double
Dim tir3 As Double
Dim tir4 As Double
Dim police2 As Double
Dim p As Double
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
PictureBox2.Left = PictureBox2.Left + 20
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau gauche.bmp")
PictureBox2.Left = PictureBox2.Left - 20
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau haut.bmp")
PictureBox2.Top = PictureBox2.Top - 20
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau bas.bmp")
PictureBox2.Top = PictureBox2.Top + 20
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = 5
a = 0
y = 0
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
rist = CStr(Int(Rnd() * 10))
If rist < 5 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
Timer1.Stop()
MsgBox("vous avez explosé un navire", MsgBoxStyle.Information, "EXPLOSION")
PictureBox3.Visible = False
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car un bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
Else
MsgBox("vous avez raté la cible", MsgBoxStyle.Information, "TIR")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
a = a + 1
If a < 10 Then
PictureBox3.Top = PictureBox3.Top + 20
ElseIf a < 21 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic.bmp")
PictureBox3.Left = PictureBox3.Left - 20
ElseIf a < 25 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic hb.bmp")
PictureBox3.Top = PictureBox3.Top - 20
ElseIf a < 50 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic.bmp")
PictureBox3.Left = PictureBox3.Left + 20
ElseIf a < 75 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic hb.bmp")
PictureBox3.Top = PictureBox3.Top + 20
ElseIf a < 100 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic.bmp")
PictureBox3.Left = PictureBox3.Left - 20
ElseIf a < 130 Then
PictureBox3.Image = System.Drawing.Bitmap.FromFile("bateautrafic hb.bmp")
PictureBox3.Top = PictureBox3.Top - 20
Else
a = 0
End If
End Sub
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
tir = tir + 1
If tir < 3 Then
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car le bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
Else
PictureBox4.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
Timer2.Stop()
MsgBox("vous avez explosé le navire de police", MsgBoxStyle.Information, "EXPLOSION")
PictureBox4.Visible = False
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car un autre bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
police = police + 1
If police < 50 Then
PictureBox4.Left = PictureBox4.Left + 20
Else
PictureBox4.Left = PictureBox4.Left - 20
If police = 100 Then
police = 0
End If
End If
End Sub
Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
tir4 = tir4 + 1
If tir4 < 5 Then
MsgBox("vous avez touché le navire mais il n'est pas encore coulé", MsgBoxStyle.Information, "TIR")
Else
PictureBox5.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé un navire", MsgBoxStyle.Information, "EXPLOSION")
PictureBox5.Visible = False
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car le bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
End If
End Sub
Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
tir2 = tir2 + 1
If tir2 < 3 Then
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car le bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
Else
PictureBox6.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
Timer3.Stop()
MsgBox("vous avez explosé le navire de police", MsgBoxStyle.Information, "EXPLOSION")
PictureBox6.Visible = False
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car un autre bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
End If
End Sub
Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
tir4 = tir4 + 1
If tir4 < 3 Then
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car le bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
Else
PictureBox7.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
Timer4.Stop()
MsgBox("vous avez explosé le navire de police", MsgBoxStyle.Information, "EXPLOSION")
PictureBox7.Visible = False
PictureBox2.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
MsgBox("vous avez explosé car un autre bateau de police a repondu a vos tirs et vous a coulé", MsgBoxStyle.Critical, "EXPLOSION")
x = x - 1
If x > 0 Then
MsgBox("Mais vous avez " & x & " autre chance", MsgBoxStyle.Information, "REPARATION")
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
Else
MsgBox("vous etes mort", MsgBoxStyle.Critical, "FIN")
End
End If
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
police2 = police2 + 1
If police2 < 20 Then
PictureBox6.Left = PictureBox6.Left + 20
Else
PictureBox6.Left = PictureBox6.Left - 20
If police2 = 40 Then
police2 = 0
End If
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
p = p + 1
If p < 10 Then
PictureBox7.Left = PictureBox7.Left - 20
Else
PictureBox7.Left = PictureBox7.Left + 20
If p = 20 Then
p = 0
End If
End If
End Sub
Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
MsgBox("vous ne pouvez pas atteindre les avions !!!", MsgBoxStyle.Exclamation, "OH !")
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
PictureBox8.Left = PictureBox8.Left + 20
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
Timer6.Enabled = True
End Sub
Private Sub ReglesDuJeuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReglesDuJeuToolStripMenuItem.Click
MsgBox("Déplacez vous avec les boutons. Pour exploser, le bouton 'explosion'. Pour tirer sur un navire, cliquez dessus. Vous avez 5 chances. Attention a la police!", MsgBoxStyle.ApplicationModal, "regles du jeu")
End Sub
Private Sub OuiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuiToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
My.Computer.Audio.Play(OpenFileDialog1.FileName, AudioPlayMode.BackgroundLoop)
End Sub
Private Sub NonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NonToolStripMenuItem.Click
My.Computer.Audio.Stop()
End Sub
Private Sub AProposDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AProposDeToolStripMenuItem.Click
AboutBox1.ShowDialog()
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim top As Integer = PictureBox2.Top
Dim left As Integer = PictureBox2.Left
If e.KeyCode = Keys.Down Then
top += 20
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau bas.bmp")
End If
If e.KeyCode = Keys.Up Then
top -= 20
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau haut.bmp")
End If
If e.KeyCode = Keys.Right Then
left += 20
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau.bmp")
End If
If e.KeyCode = Keys.Left Then
left -= 20
PictureBox2.Image = System.Drawing.Bitmap.FromFile("bateau gauche.bmp")
End If
PictureBox2.Location = New System.Drawing.Point(left, top)
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
MsgBox("ceci est votre bateau", MsgBoxStyle.Information, "INFO")
End Sub
End Class
Conclusion :
Quand on veut changer de repertoire avec OpenFileDialog1, le programme ne retrouve plus les images.
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.