0

I am writing a very basic memory match card game, and am trying to get the program to flip over the selected cards, wait 2 seconds so the user can see the values, then flip back over. The code I have to do this is:

Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click, Label2.Click, Label3.Click, Label4.Click, Label5.Click, Label6.Click, Label7.Click, Label8.Click, Label9.Click, Label10.Click, Label11.Click, Label12.Click, Label13.Click, Label14.Click, Label15.Click, Label16.Click
        Dim message As String = "Label Clicked was Index" + sender.TabIndex.ToString
        MessageBox.Show(message)
        list(sender.TabIndex).BackColor = Color.White
        If secondFlip Then
            moves += 1
            If list(sender.tabIndex).Text = firstFlip.ToString Then
                matches += 1
                list(sender.tabIndex).Tag = "Match"
                pickOne.Tag = "Match"
            Else
                resetLastTwo(sender.tabIndex)
            End If
            secondFlip = False
        Else
            firstFlip = list(sender.tabIndex).Text
            pickOne = list(sender.tabIndex)
            secondFlip = True
        End If
    End Sub

    Private Sub resetLastTwo(ByVal n)
        Dim sw = New Stopwatch()
        sw.Start()
        While sw.ElapsedMilliseconds < 2000
 
        End While
        pickOne.BackColor = Color.Black
        list(n).BackColor = Color.Black
    End Sub

The first label that is clicked is flipped successfully, but the second one stays black, then 2 seconds later the first one returns to black. The only thing I can think of is that in the first if statement, the program loads the resetLastTwo function and keeps the second card black for some reason. If the cards match, ie the resetLastTwo is never called, the second card is flipped over without any problem.
If I move the MessageBox to after the BackColor = Color.White, it works, but my goal is to get rid of that messagebox completely for the final version. What am I missing here?

Anthony

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by awestove
0

after some creative commenting, I realize that the form is just not repainting or something. If I comment out the list(n).backcolor = color.black, it gets repainted with a white bg at the same time that the first click gets repainted with the black bg. Anyway to force the repaint before reaching the end?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.