vendredi 4 décembre 2015

VB.NET multiple picturebox randomizer

I want to create a game in which the player will have to find the correct answer out of four... All displayed answers will be pictures... I though using ImageLists could be a good idea -I did the same using ArrayList and it worked fine- but I stuck and can't find out what changes should I do in my code now that I'm trying to use images...

     Public Sub reloadForm()

    Dim questions As New ArrayList
    questions.Add("Question1")
    questions.Add("Question2")
    questions.Add("Question3")
    questions.Add("Question4")
    questions.Add("Question5")
    questions.Add("Question6")

    Dim Randm As New Random
    Dim rnd As New Integer
    Dim temp As New ImageList
    Dim flaG As Boolean

    flaG = False

    Do
        rnd = Randm.Next(0, (questions.Count))
        If Not ListBox1.Items.Contains(rnd) Then
            question.Text = questions(rnd)
            temp.Images.Add(ImageListC(rnd).ToString)
            ListBox1.Items.Add(rnd)
            flaG = True
        End If
    Loop Until flaG = True

    Do
        rnd = Randm.Next(0, (ImageListW.Images.Count))
        If Not temp.Contains(ImageListW(rnd)) Then
'Contains and Add 
don't work for Imagelist, is there any similar attribute ?'
        temp.Add(ImageListW(rnd))
        End If
    Loop Until temp.Count = 4
    Dim quizlist As New Imagelist
        Do
            rnd = Randm.Next(0, 4)
            If Not quizlist.Contains(tempList(rnd)) Then
                quizlist.Add(tempList(rnd))
            End If
        Loop Until quizList.Count = 4

        PictureBox1.Image = quizlist(0)
        PictureBox2.Image = quizlist(1)
        PictureBox3.Image = quizlist(2)
        PictureBox4.Image = quizlist(3)
End Sub

Can you suggest a solution for this one, or a different way to do it? Thanks in advance




Aucun commentaire:

Enregistrer un commentaire