PWM63
Messages postés127Date d'inscriptionlundi 11 octobre 2004StatutMembreDernière intervention18 mai 2016 13 juil. 2007 à 11:05
Désolé pour le double post (on ne peut pas éditer ses propres posts ?).
Private Sub ma_picturebox_click(mon_tir as double, ma_PictureBox as PictureBox, mon_Timer as Timer)
mon_tir = mon_tir + 1
If mon_tir > 2 Then
ma_PictureBox.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
mon_Timer.Stop()
End If
Call touché()
End Sub
PWM63
Messages postés127Date d'inscriptionlundi 11 octobre 2004StatutMembreDernière intervention18 mai 2016 13 juil. 2007 à 10:59
Tu peux optimiser le code en utilisant des procédures avec passage de paramètres si besoin afin de traiter tout ce qui est répétitif, car si tu dois corriger 1 ligne, ca te permet de ne corriger qu'une seule fois au lieu de x fois.
Par exemple, tu peux obtenir ceci :
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
Call ma_picturebox_click(tir, PictureBox4, Timer2)
End Sub
Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
Call ma_picturebox_click(tir2, PictureBox6, Timer3)
End Sub
Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
Call ma_picturebox_click(tir4, PictureBox7, Timer4)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call touché()
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
Call touché()
Else
MsgBox("vous avez raté la cible", MsgBoxStyle.Information, "TIR")
End If
End Sub
Private Sub ma_picturebox_click(mon_tir as double, ma_PictureBox as PictureBox, mon_Timer as Timer)
mon_tir = mon_tir + 1
If mon_tir < 3 Then
Call touché()
Else
ma_PictureBox.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
mon_Timer.Stop()
MsgBox("vous avez explosé le navire de police", MsgBoxStyle.Information, "EXPLOSION")
ma_PictureBox.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 touché()
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 Sub
Tu peux également mettre la plupart de tes variables (voire toutes) en Byte plutôt que Double afin d'économiser quelques octets de mémoire.
En grattant, on peut encore optimiser.
Stéphane.
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 19:38
ah d'accord! :)
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 12 juil. 2007 à 18:25
Sharkiller
Messages postés71Date d'inscriptiondimanche 12 octobre 2003StatutMembreDernière intervention 9 janvier 2009 12 juil. 2007 à 18:21
Ta source est .NET et tu ne l'avais pas indiqué. Apparemment PCPT s'en est chargé :).
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 18:14
Mais au fait, quest - ce que veut dire "flag "dotnet" manquant, modifié " ?
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 18:06
Merci. (a PCPT)
OK (a ghuysmans99)
ghuysmans99
Messages postés2496Date d'inscriptionjeudi 14 juillet 2005StatutContributeurDernière intervention 5 juin 20161 12 juil. 2007 à 18:00
c'est pas programmateurs c'est programmeurs
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 12 juil. 2007 à 17:56
tu t'es foulé pour l'interface....
flag "dotnet" manquant, modifié
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 17:07
C'est fait.
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 17:03
d'accord, je vais le mettre.
Sharkiller
Messages postés71Date d'inscriptiondimanche 12 octobre 2003StatutMembreDernière intervention 9 janvier 2009 12 juil. 2007 à 17:00
Ah par contre.. Je pensais que c'était mon navigateur qui déconnait, mais cette fois ce n'est pas ça^^. Ca serait mieux que tu mettes le zip avec la source, ne serait-ce que pour les images!
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 16:59
Merci. je vais essayer.
Sharkiller
Messages postés71Date d'inscriptiondimanche 12 octobre 2003StatutMembreDernière intervention 9 janvier 2009 12 juil. 2007 à 16:52
Si la form a le focus, il te faut utiliser KeyPress/KeyUp/KeyDown (évènement de form) et trier la touche enfoncée en fonction de celles que tu veux utiliser pour déplacer l'image.
Un truc dans le genre:
Sub [Form]_KeyUp(KeyAscii as Long,Shift as Integer)
If KeyAscii=vbKeyUp then [Picture].Top=[Picture].Top+10 'la PictureBox montera de 10 unités si on appuie sur la touche Haut (flèche)
End Sub
Il faut que la form ait le focus, là ce n'est pas le cas à cause des boutons... Alors soit tu les enlèves, soit tu testes avec [Form].SetFocus.
levg
Messages postés59Date d'inscriptionvendredi 19 janvier 2007StatutMembreDernière intervention27 juin 2008 12 juil. 2007 à 15:57
Bonjour. voici mon pemier jeu. je pose une question aux programmateurs chevronés : comment déplace t on une PictureBox avec le clavier ?
13 juil. 2007 à 11:05
Private Sub ma_picturebox_click(mon_tir as double, ma_PictureBox as PictureBox, mon_Timer as Timer)
mon_tir = mon_tir + 1
If mon_tir > 2 Then
ma_PictureBox.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
mon_Timer.Stop()
End If
Call touché()
End Sub
13 juil. 2007 à 10:59
Par exemple, tu peux obtenir ceci :
Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
Call ma_picturebox_click(tir, PictureBox4, Timer2)
End Sub
Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
Call ma_picturebox_click(tir2, PictureBox6, Timer3)
End Sub
Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
Call ma_picturebox_click(tir4, PictureBox7, Timer4)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call touché()
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
Call touché()
Else
MsgBox("vous avez raté la cible", MsgBoxStyle.Information, "TIR")
End If
End Sub
Private Sub ma_picturebox_click(mon_tir as double, ma_PictureBox as PictureBox, mon_Timer as Timer)
mon_tir = mon_tir + 1
If mon_tir < 3 Then
Call touché()
Else
ma_PictureBox.Image = System.Drawing.Bitmap.FromFile("boum.bmp")
mon_Timer.Stop()
MsgBox("vous avez explosé le navire de police", MsgBoxStyle.Information, "EXPLOSION")
ma_PictureBox.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 touché()
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 Sub
Tu peux également mettre la plupart de tes variables (voire toutes) en Byte plutôt que Double afin d'économiser quelques octets de mémoire.
En grattant, on peut encore optimiser.
Stéphane.
12 juil. 2007 à 19:38
12 juil. 2007 à 18:25
12 juil. 2007 à 18:21
12 juil. 2007 à 18:14
12 juil. 2007 à 18:06
OK (a ghuysmans99)
12 juil. 2007 à 18:00
12 juil. 2007 à 17:56
flag "dotnet" manquant, modifié
12 juil. 2007 à 17:07
12 juil. 2007 à 17:03
12 juil. 2007 à 17:00
12 juil. 2007 à 16:59
12 juil. 2007 à 16:52
Un truc dans le genre:
Sub [Form]_KeyUp(KeyAscii as Long,Shift as Integer)
If KeyAscii=vbKeyUp then [Picture].Top=[Picture].Top+10 'la PictureBox montera de 10 unités si on appuie sur la touche Haut (flèche)
End Sub
Il faut que la form ait le focus, là ce n'est pas le cas à cause des boutons... Alors soit tu les enlèves, soit tu testes avec [Form].SetFocus.
12 juil. 2007 à 15:57