VB.NET et "Des chiffres et des lettres"

Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 - 8 nov. 2011 à 18:34
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 - 16 nov. 2011 à 12:53
Re bonsoir
J'enviseage de creer un petit soft base sur le jeu "des chiffres et des lettres" pour une maison de retraitecee du projet

J'ai une idée bien avancee du projet mais je butte sur un truc, le tirage aleatoire

ce que je voudrais c'est un bouton "voyelles" et un bouton "c onsonnes" et lorsque quelqu'un demende voyelle ou consonne,le logiciel m'affiche dans une textbox une voyelle ou une consonne au hasard, sachant que les doublons sont autorises"

Il y aurait bien sur autant de textbox que dans le vrai jeu pour l'affichage

Mais je n'arrive pas a affectuer un tirge aleatoire (Ramdomize ?)
J'en appelle a vos lumieres
Merci

30 réponses

Utilisateur anonyme
8 nov. 2011 à 18:57
Bonsoir,

La classe Random est là pour ça.
dim chiffre as integer = new random().next(0,7)

Dans ce cas, tu obtiendras un Integer supérieur ou égal à 0 et inférieur à 7 (non compris).
A toi d'adapter ensuite...

Bonne prog.
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
8 nov. 2011 à 19:52
merci banana32
je comprends donc que je fais pareil pour les lettres avec un
dim voyelle as string = new random().next(A,.......)

et les consonnes sur le meme modele

mais les chiffres se suivent au cas précis
un Integer supérieur ou égal à 0 et inférieur à 7


si la je peux faire
dim chiffre as integer = new random().next(0,101)
pour avoir un chiffre aléatoire entre 0 et 100,

je ne vois pas comment faire pour les lettres vu que je dois différencier les voyelles des consonnes et donc je n'ai pas de suite logique dans ces 2 tirages aléatoires
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
8 nov. 2011 à 19:52
Bonsoir

pour les chiffres .....
tu veux que l'ordi trouve la solution
ou seulement distribue les nombres
pour la solution
soi avec récursion prend beaucoup de temps
soi avec l'algorithm de recherche aléatoire

http://en.wikipedia.org/wiki/Randomized_algorithm

http://www.dcode.fr/compte-est-bon

Bonne prog
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
8 nov. 2011 à 20:15
non non je ne veux pas qu'il trouve la solution
je veux juste que quand je clique sur le bouton "chiffres" il me place 5 chiffres au hasard de 0 a 100 dans 5 textbox différentes et que dans une sixieme textbox, il me choisisse un chiffre aléatoirement entre 150 et 1000

pour les lettres idem
1er clic sur bouton consonne = une consonne dans une textbox1
2ieme sur bouton consonne = une consonne dans une textbox2
3ieme sur bouton consonne = une consonne dans une textbox3
4ieme sur bouton consonne = une consonne dans une textbox4
5ieme sur bouton consonne = une consonne dans une textbox5
6ieme sur bouton consonne = une consonne dans une textbox6

1er clic sur bouton voyelle = une voyelle dans une textbox7
2ieme sur bouton voyelle = une voyelle dans une textbox7
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
8 nov. 2011 à 21:50
je te conseille de placer tous les textbox
consonne dans un groupbox control
et les textbox voyelle dans un autre groupbox
control

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitGroupBox()
End Sub

Private Sub InitGroupBox()
        For Each ctrl As Control In GroupBoxConsonne.Controls
            If TypeOf ctrl Is TextBox Then
                DirectCast(ctrl, TextBox).Text = String.Empty
            End If
        Next
        For Each ctrl As Control In GroupBoxVoyelle.Controls
            If TypeOf ctrl Is TextBox Then
                DirectCast(ctrl, TextBox).Text = String.Empty
            End If
        Next
    End Sub

    Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick
        Dim randomlettre As New Random
        Dim consonne As String = "bcdfghjklmnpqrstvwxz"
        Dim lettre As Char
        Dim x As Integer
        x = randomlettre.Next(0, consonne.Length)
        lettre = CChar(consonne.Substring(x, 1))
        For Each ctrl As Control In GroupBoxConsonne.Controls
            If TypeOf ctrl Is TextBox Then
                If DirectCast(ctrl, TextBox).Text = String.Empty Then
                    DirectCast(ctrl, TextBox).Text = lettre
                    Exit For
                End If
            End If
        Next

    End Sub

    Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick
        Dim randomlettre As New Random

        Dim voyelle As String = "aeiouy"
        Dim lettre As Char
        Dim x As Integer
        x = randomlettre.Next(0, voyelle.Length)
        lettre = CChar(voyelle.Substring(x, 1))
        For Each ctrl As Control In GroupBoxVoyelle.Controls
            If TypeOf ctrl Is TextBox Then
                If DirectCast(ctrl, TextBox).Text = String.Empty Then
                    DirectCast(ctrl, TextBox).Text = lettre
                    Exit For
                End If
            End If
        Next
    End Sub

Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick
        InitGroupBox()
    End Sub
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
9 nov. 2011 à 09:55
Merci ShayW

Je dois toutefois avoir un petit souci car a chaque GroupBoxVoyelle.Controlls et GroupBoxconsonnes.Controlls, j'ai un message d'erreur me disant
controls n'est pas un membre de system.array
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
9 nov. 2011 à 10:40
Salut
Bizarre
envoie ton bout de code
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
9 nov. 2011 à 11:56
j'espère que deux l n'ont pas été mis, comme montré ici :

Je dois toutefois avoir un petit souci car a chaque GroupBoxVoyelle.Controlls et GroupBoxconsonnes.Controlls, j'ai un message d'erreur me disant


____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
9 nov. 2011 à 11:56
Arf c'est moi qui avait merd..... j'avais mal orthographie le nom des groupbox
Par contre maintenant j'ai mis 8 textbox textbox1, 2, ....,7 et

- au premier clic
si je clique sur "consonne", il doit me mettre une consonne aleatoirement tiree
dans le textbox1
si je clique sur "voyelle", il doit me mettre une voyelle aleatoirement tiree
dans le textbox1

Une fois que la textbox1 est remplie je clique de nouveau
si je clique sur "consonne", il doit me mettre une consonne aleatoirement tiree
dans le textbox2
si je clique sur "voyelle", il doit me mettre une voyelle aleatoirement tiree
dans le textbox2

ainsi de suite jusqu'a remplir les 8 textbox.

Apres, il faut faire une temporisation pendant 6 secondes et lancer un decompte avec une barre de chargement visible qui durera 1 minute 30s, puis apres les 1 minutes 30 , un message apparait disant " Solution ?"

voili voila
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
9 nov. 2011 à 12:51
Bon Plan A ne convient pas donc PlanB

Private listconsonne As New List(Of TextBox)
 Private listvoyelle As New List(Of TextBox)
 Private Sub InitList()
    listconsonne.Add(TextBox1)
    listconsonne.Add(TextBox2)
    listconsonne.Add(TextBox3)
    listconsonne.Add(TextBox4)
    listconsonne.Add(TextBox5)
    listconsonne.Add(TextBox6)
    listvoyelle.Add(TextBox7)
    listvoyelle.Add(TextBox8)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitList()
        InitGroupBox()
End Sub
        Private Sub InitGroupBox()
    For Each ctrl As Control In GroupBoxConsonne.Controls
       If TypeOf ctrl Is TextBox Then
           DirectCast(ctrl, TextBox).Text = String.Empty
       End If
    Next
   For Each ctrl As Control In GroupBoxVoyelle.Controls
       If TypeOf ctrl Is TextBox Then
            DirectCast(ctrl, TextBox).Text = String.Empty
       End If
    Next
 End Sub

rivate Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick
        Dim randomlettre As New Random
        Dim consonne As String = "bcdfghjklmnpqrstvwxz"
        Dim lettre As Char
        Dim x As Integer
        x = randomlettre.Next(0, consonne.Length)
        lettre = CChar(consonne.Substring(x, 1))
        For Each element In listconsonne
            If element.Text = String.Empty Then
                element.Text = lettre
                Exit For
            End If
            
        Next

    End Sub

    Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick
        Dim randomlettre As New Random

        Dim voyelle As String = "aeiouy"
        Dim lettre As Char
        Dim x As Integer
        x = randomlettre.Next(0, voyelle.Length)
        lettre = CChar(voyelle.Substring(x, 1))
        For Each element In listvoyelle
            If element.Text = String.Empty Then
                element.Text = lettre
                Exit For
            End If

        Next
    End Sub

    Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick
        InitGroupBox()
    End Sub
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
9 nov. 2011 à 13:14
on y est presque j'y crois pas
Y'a un petit truc qui cloche dans la repartition des voyelles ou consonnes

En fait on n'a pas 6 textbox pour les consonnes et 2 Textbox pour les voyelles

On a en tout 8 Textbox pour les voyelles et les consonnes

On clique sur consonne ou voyelle => le textbox1 affiche une consonne ou une voyelle selon le bouton clique
On clique sur consonne ==>le textbox2 affiche une consonne ou une voyelle selon le bouton clique ... etc ... jusqu'au textbox8

Ah oui j'oubliais, je dois tout mettre en majuscules
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
9 nov. 2011 à 13:33
Il faut savoir dans tes messages précédent
pour les lettres idem
1er clic sur bouton consonne = une consonne dans une textbox1
2ieme sur bouton consonne = une consonne dans une textbox2
3ieme sur bouton consonne = une consonne dans une textbox3
4ieme sur bouton consonne = une consonne dans une textbox4
5ieme sur bouton consonne = une consonne dans une textbox5
6ieme sur bouton consonne = une consonne dans une textbox6

1er clic sur bouton voyelle = une voyelle dans une textbox7
2ieme sur bouton voyelle = une voyelle dans une textbox7


tu dis

On clique sur consonne ou voyelle => le textbox1 affiche une consonne ou une voyelle selon le bouton clique
On clique sur consonne ==>le textbox2 affiche une consonne ou une voyelle selon le bouton clique ... etc ... jusqu'au textbox8


et si tu obtiens que des consonnes ou que des
voyelle
donc je te conseille de réflechir
le problème ce n'est pas le code mais
1 savoir ce que tu veux faire d'abord
le code traduire en language informatique 1
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
9 nov. 2011 à 13:36
Ah non j'ai compris
Sorry je t'envoie prochainement autre chose
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
9 nov. 2011 à 13:45
c'est une erreur syntaxique de ma part et je m'en excuse

la règle est bien
On clique sur consonne ou voyelle => le textbox1 affiche une consonne ou une voyelle selon le bouton clique
On clique sur consonne ==>le textbox2 affiche une consonne ou une voyelle selon le bouton clique ... etc ... jusqu'au textbox8


Mais sur un tirage complet, donc 8 clics, on doit obligatoirement cliquer 6 fois sur consonne et 2 fois sur voyelle.
On peut faire : C,V,V,C,C,C,C,C ou C,V,C,C,V,C,C,C ou V,C,C,C,C,C,V,C par exemple, peu importe l'ordre du choix

encore desole pour la bourde syntaxique
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
10 nov. 2011 à 05:00
Salut

1 sur ta form tu places
un control panel que tu nommes PanelJeu
1 buttons nommé Buttonconsonne
1 buttons nommé Buttonvoyelle
1 buttons nommé ButtonEffacer
1 picturebox nommé progresbar
1 timer

c'est tout
Imports System.Drawing.Drawing2D
Public Class Form1
   
    Private flagstart As Boolean
    Dim lettre As String
    Dim counter As Integer
    Dim flagresult As Boolean
    Dim thetimespan As New TimeSpan
    Private lastmouselocation As New Point
    Dim starttime As New DateTime


    Private listlettre As New List(Of PictureBox)
    Private Sub InitPanelJeu()
        For iter = 0 To 7
            Dim thepic As New PictureBox
            thepic.Tag = String.Empty
            thepic.BackColor = Color.White
            thepic.Width = 80
            thepic.Height = 100
            thepic.BorderStyle = BorderStyle.Fixed3D
            PanelJeu.Controls.Add(thepic)
            listlettre.Add(thepic)
            AddHandler listlettre(iter).MouseDown, AddressOf thepicMouseDown
            AddHandler listlettre(iter).MouseMove, AddressOf thepicMouseMove
            AddHandler listlettre(iter).Paint, AddressOf thepicPaint
        Next
        ButtonEffacer.Enabled = False
        counter = 0
        
        Timer1.Interval = 6000
        Timer1.Stop()
        flagstart = False
        progresbar.Width = 0
        progresbar.Height = 12

    End Sub

    
    Private Sub DisposeLettre()
        Dim left As Integer
        left = 6
        For Each item In listlettre
            item.Location = New Point(left, 6)
            left += item.Width + 3
        Next
        PanelJeu.Height = 3 * listlettre(0).Height + 20
        PanelJeu.Width = listlettre(0).Width * 8 + 12 + 7 * 3
        PanelJeu.Left = Me.Width \ 2 - PanelJeu.Width \ 2
        PanelJeu.Top = Me.Height \ 2 - PanelJeu.Height \ 2
        Buttonconsonne.Location = New Point(PanelJeu.Right + 2, PanelJeu.Top)
        Buttonvoyelle.Location = New Point(PanelJeu.Right + 2, Buttonconsonne.Bottom + 2)
        ButtonEffacer.Location = New Point(PanelJeu.Right + 2, Buttonvoyelle.Bottom + 2)
        flagresult = False
PanelJeu.BackColor = Color.Linen
    End Sub

    
    Private Sub AfficheTouteLesLettres(ByVal gr As System.Drawing.Graphics, ByVal thepic As PictureBox)
        Dim myfont As New Font("arial", 34, FontStyle.Bold, GraphicsUnit.Pixel)
        Dim mesure As New SizeF
        mesure = gr.MeasureString(thepic.Tag.ToString, myfont)
        gr.DrawString(thepic.Tag, myfont, Brushes.Black, (thepic.Width - mesure.Width) \ 2, (thepic.Height - mesure.Height) \ 2)


    End Sub
    Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick
        Dim randomlettre As New Random
        Dim consonne As String = "bcdfghjklmnpqrstvwxz"


        Dim x As Integer

        flagstart = True
        x = randomlettre.Next(0, consonne.Length)
        lettre = consonne.Substring(x, 1)
        lettre = lettre.ToUpper
        listlettre(counter).Tag = lettre
        counter += 1
        If counter = 8 Then
            Buttonconsonne.Enabled = False
            Buttonvoyelle.Enabled = False
            Timer1.Start()
            starttime = Now
        End If
        listlettre(counter - 1).Invalidate()
    End Sub

    Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick
        Dim randomlettre As New Random

        Dim voyelle As String = "aeiouy"
        Dim x As Integer

        flagstart = True
        x = randomlettre.Next(0, voyelle.Length)
        lettre = voyelle.Substring(x, 1)
        lettre = lettre.ToUpper
        listlettre(counter).Tag = lettre
        counter += 1
        If counter = 8 Then
            Buttonvoyelle.Enabled = False
            Buttonconsonne.Enabled = False
            starttime = Now
            Timer1.Start()
        End If
        listlettre(counter - 1).Invalidate()

    End Sub
    Private Sub Drawprogresbar(ByRef gr As System.Drawing.Graphics)
        'Dessine le progresbar
        Dim face(3) As Point
        Dim margin As Integer
        Dim space As Integer
        Dim sizelength As Integer
        Dim sizeheight As Integer
        Dim edge_colors(3) As Color

        margin = 2
        space = 2
        sizelength = progresbar.Width + 2 * space
        sizeheight = progresbar.Height + 2 * space
        face(0).X = margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + margin
        face(1).Y = face(0).Y - margin
        face(2).X = face(1).X + sizelength
        face(2).Y = face(1).Y
        face(3).X = face(0).X + sizelength
        face(3).Y = face(0).Y

        Dim path_brush As New PathGradientBrush(face)
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        face(0).X = margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + sizelength
        face(1).Y = face(0).Y
        face(2).X = face(1).X
        face(2).Y = face(1).Y + sizeheight
        face(3).X = face(0).X
        face(3).Y = face(2).Y
        path_brush.Dispose()
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        face(0).X = sizelength + margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + margin
        face(1).Y = face(0).Y - margin
        face(2).X = face(1).X
        face(2).Y = face(1).Y + sizeheight
        face(3).X = face(0).X
        face(3).Y = face(2).Y + margin
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        gr.DrawLine(Pens.Black, face(1).X, face(1).Y, face(2).X, face(2).Y)
        ' progresbar.Width = sizelength * 1
        ' progresbar.Height = sizeheight
        progresbar.Left = PanelJeu.Left
        progresbar.Top = PanelJeu.Bottom + 3
        progresbar.BringToFront()
        progresbar.Visible = True

    End Sub
    Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick
        Dim picturelettre As New PictureBox
        lettre = String.Empty
        For Each picturelettre In listlettre
            picturelettre.Tag = String.Empty
            picturelettre.Invalidate()
        Next
        counter = 0
        progresbar.Width = 0
        DisposeLettre()
        Buttonvoyelle.Enabled = True
        Buttonconsonne.Enabled = True
        ButtonEffacer.Enabled = False
    End Sub

    

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        InitPanelJeu()
        DisposeLettre()


    End Sub

    Private Sub thepicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        lastmouselocation = e.Location
    End Sub

    Private Sub thepicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim pt As New Point
        If Not flagresult Then
            Exit Sub
        End If
        pt = e.Location
        If e.Button = Windows.Forms.MouseButtons.Left Then
            pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X
            pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y

            DirectCast(sender, PictureBox).Location = pt
            PanelJeu.Invalidate()
        End If
    End Sub
    
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        thetimespan = Now - starttime
        If thetimespan.TotalSeconds >= 96 Then
            Timer1.Stop()

            MessageBox.Show("VOS RESULTAT", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ButtonEffacer.Enabled = True
            flagresult = True
            Exit Sub
        End If

        progresbar.Width += 1
        Timer1.Interval = 100
    End Sub

    
    Private Sub thepicPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
        
        If DirectCast(sender, PictureBox).Tag <> String.Empty Then
            AfficheTouteLesLettres(e.Graphics, DirectCast(sender, PictureBox))
        End If
        
    End Sub

    Private Sub progresbar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles progresbar.Paint
        Drawprogresbar(e.Graphics)
    End Sub
End Class


pour former des mots tu peux glisser les lettres avec la souris dans le tableau de jeu
il manque le générique
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
10 nov. 2011 à 10:34
arf c'est tout bonnement magique
tu es fort, tellement fort que j'ai pas tout compris ..... control panel ? ca existe encore dans visual studio ?????
Je ne le trouve pas
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
10 nov. 2011 à 10:38
Si tu parles d'un Panel, alors la je ne peux pas le nommer PanelJeu

L'identificateur 'PanelJeu ' n'est pas valide.
d'après Visual Studio
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
10 nov. 2011 à 11:08
autant pour moi, j'avais fait une boulette .....

par contre, vu que j'ai l'option explicit sur on, il me dit

Erreur 1 Option Strict On interdit les conversions implicites de 'Single' en 'Long'.
pour la ligne suivante :

gr.DrawString(thepic.Tag, myfont, Brushes.Black, (thepic.Width - mesure.Width) \ 2, (thepic.Height - mesure.Height) \ 2) 

Je passe explicit sur off ou je corrige le bug ???????
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
10 nov. 2011 à 15:16
Salut
remets à explicit on toujours
le control panel se trouve dans le tool box
panel
nommes le paneljeu
et le reste
1 buttons nommé Buttonconsonne
1 buttons nommé Buttonvoyelle
1 buttons nommé ButtonEffacer
1 picturebox nommé progresbar
1 timer

voila le code corrigé
Imports System.Drawing.Drawing2D
Public Class Form1

    Private flagstart As Boolean
    Dim lettre As String
    Dim counter As Integer
    Dim flagresult As Boolean
    Dim thetimespan As New TimeSpan
    Private lastmouselocation As New Point
    Dim starttime As New DateTime


    Private listlettre As New List(Of PictureBox)
    Private Sub InitPanelJeu()
        For iter = 0 To 7
            Dim thepic As New PictureBox
            thepic.Tag = String.Empty
            thepic.BackColor = Color.White
            thepic.Width = 80
            thepic.Height = 100
            thepic.BorderStyle = BorderStyle.Fixed3D
            PanelJeu.Controls.Add(thepic)
            listlettre.Add(thepic)
            AddHandler listlettre(iter).MouseDown, AddressOf thepicMouseDown
            AddHandler listlettre(iter).MouseMove, AddressOf thepicMouseMove
            AddHandler listlettre(iter).Paint, AddressOf thepicPaint
        Next
        ButtonEffacer.Enabled = False
        counter = 0

        Timer1.Interval = 6000
        Timer1.Stop()
        flagstart = False
        progresbar.Width = 0
        progresbar.Height = 30

    End Sub


    Private Sub DisposeLettre()
        Dim left As Integer
        left = 6
        For Each item In listlettre
            item.Location = New Point(left, 6)
            left += item.Width + 3
        Next
        PanelJeu.Height = 3 * listlettre(0).Height + 20
        PanelJeu.Width = listlettre(0).Width * 8 + 12 + 7 * 3
        PanelJeu.Left = Me.Width \ 2 - PanelJeu.Width \ 2
        PanelJeu.Top = Me.Height \ 2 - PanelJeu.Height \ 2
        PanelJeu.BackColor = Color.Linen
        Buttonconsonne.Location = New Point(PanelJeu.Right + 2, PanelJeu.Top)
        Buttonvoyelle.Location = New Point(PanelJeu.Right + 2, Buttonconsonne.Bottom + 2)
        ButtonEffacer.Location = New Point(PanelJeu.Right + 2, Buttonvoyelle.Bottom + 2)
        flagresult = False
    End Sub


    Private Sub AfficheTouteLesLettres(ByVal gr As System.Drawing.Graphics, ByVal thepic As PictureBox)
        Dim myfont As New Font("arial", 34, FontStyle.Bold, GraphicsUnit.Pixel)
        Dim mesure As New SizeF
        Dim x ,y As Single 
        mesure = gr.MeasureString(thepic.Tag.ToString, myfont)
        gr.DrawString(thepic.Tag.ToString, myfont, Brushes.Black, (thepic.Width - mesure.Width) / 2, (thepic.Height - mesure.Height) / 2)


    End Sub
    Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick
        Dim randomlettre As New Random
        Dim consonne As String = "bcdfghjklmnpqrstvwxz"


        Dim x As Integer

        flagstart = True
        x = randomlettre.Next(0, consonne.Length)
        lettre = consonne.Substring(x, 1)
        lettre = lettre.ToUpper
        listlettre(counter).Tag = lettre
        counter += 1
        If counter = 8 Then
            Buttonconsonne.Enabled = False
            Buttonvoyelle.Enabled = False
            Timer1.Start()
            starttime = Now
        End If
        listlettre(counter - 1).Invalidate()
    End Sub

    Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick
        Dim randomlettre As New Random

        Dim voyelle As String = "aeiouy"
        Dim x As Integer

        flagstart = True
        x = randomlettre.Next(0, voyelle.Length)
        lettre = voyelle.Substring(x, 1)
        lettre = lettre.ToUpper
        listlettre(counter).Tag = lettre
        counter += 1
        If counter = 8 Then
            Buttonvoyelle.Enabled = False
            Buttonconsonne.Enabled = False
            starttime = Now
            Timer1.Start()
        End If
        listlettre(counter - 1).Invalidate()

    End Sub

    Private Sub Drawprogresbar(ByRef gr As System.Drawing.Graphics)
        'Dessine le progresbar
        Dim face(3) As Point
        Dim margin As Integer
        Dim space As Integer
        Dim sizelength As Integer
        Dim sizeheight As Integer
        Dim edge_colors(3) As Color

        margin = 2
        space = 2
        sizelength = progresbar.Width + 2 * space
        sizeheight = progresbar.Height + 2 * space
        face(0).X = margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + margin
        face(1).Y = face(0).Y - margin
        face(2).X = face(1).X + sizelength
        face(2).Y = face(1).Y
        face(3).X = face(0).X + sizelength
        face(3).Y = face(0).Y

        Dim path_brush As New PathGradientBrush(face)
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        face(0).X = margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + sizelength
        face(1).Y = face(0).Y
        face(2).X = face(1).X
        face(2).Y = face(1).Y + sizeheight
        face(3).X = face(0).X
        face(3).Y = face(2).Y
        path_brush.Dispose()
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        face(0).X = sizelength + margin
        face(0).Y = 2 * margin
        face(1).X = face(0).X + margin
        face(1).Y = face(0).Y - margin
        face(2).X = face(1).X
        face(2).Y = face(1).Y + sizeheight
        face(3).X = face(0).X
        face(3).Y = face(2).Y + margin
        path_brush = New PathGradientBrush(face)
        path_brush.CenterColor = Color.CornflowerBlue
        edge_colors(0) = Color.CornflowerBlue
        edge_colors(1) = Color.Black
        edge_colors(2) = Color.CornflowerBlue
        edge_colors(3) = Color.Black
        path_brush.SurroundColors = edge_colors
        gr.FillPolygon(path_brush, face)
        gr.DrawLine(Pens.Black, face(1).X, face(1).Y, face(2).X, face(2).Y)
        ' progresbar.Width = sizelength * 1
        ' progresbar.Height = sizeheight
        progresbar.Left = PanelJeu.Left
        progresbar.Top = PanelJeu.Bottom + 3
        progresbar.BringToFront()
        progresbar.Visible = True

    End Sub


    Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick
        Dim picturelettre As New PictureBox
        lettre = String.Empty
        For Each picturelettre In listlettre
            picturelettre.Tag = String.Empty
            picturelettre.Invalidate()
        Next
        counter = 0
        Timer1.Interval = 6000
        progresbar.Width = 0
        DisposeLettre()
        Buttonvoyelle.Enabled = True
        Buttonconsonne.Enabled = True
        ButtonEffacer.Enabled = False
    End Sub



    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        InitPanelJeu()
        DisposeLettre()


    End Sub

    Private Sub thepicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        lastmouselocation = e.Location
    End Sub

    Private Sub thepicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim pt As New Point
        If Not flagresult Then
            Exit Sub
        End If
        pt = e.Location
        If e.Button = Windows.Forms.MouseButtons.Left Then
            pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X
            pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y

            DirectCast(sender, PictureBox).Location = pt
            PanelJeu.Invalidate()
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        thetimespan = Now - starttime
        If thetimespan.TotalSeconds >= 96 Then
            Timer1.Stop()

            MessageBox.Show("VOS RESULTAT", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ButtonEffacer.Enabled = True
            flagresult = True
            Exit Sub
        End If

        progresbar.Width += 1
        Timer1.Interval = 100
    End Sub


    Private Sub thepicPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

        If DirectCast(sender, PictureBox).Tag.ToString <> String.Empty Then
            AfficheTouteLesLettres(e.Graphics, DirectCast(sender, PictureBox))
        End If

    End Sub

    Private Sub progresbar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles progresbar.Paint
        Drawprogresbar(e.Graphics)
    End Sub
End Class



si tout marche bien après la distribution
des lettres après 6 secondes un indicateur
visuel se met en marche

on verra le reste plus tard
0
Attila54 Messages postés 409 Date d'inscription jeudi 30 juin 2005 Statut Membre Dernière intervention 21 novembre 2013 1
10 nov. 2011 à 15:56
Hello

Bon ben ca fonctionne correctement jusqu'a ou tu as dit, apres le temps ecoule, j'ai un textbox me demandant "vos resultats"

je n'arrive juste pas a modifier la taille de la progresbar ainsi que sa position dans le form

@ bientôt et encore merci
0
Rejoignez-nous