使用 .tag 匹配卡片
Matching cards by using .tag
在我创建的这个游戏中,我有一组 "cards" 作为图片框,这些图片框设置为随机的大量图像。游戏开始时,图片框中的图像被隐藏,用户必须猜测每张卡片中的图像。我无法确定用户的猜测是否与实际卡片中的内容相符。
在下面的代码中,我使用列表框对用户可以从中猜测的图像名称进行评分。
https://imgur.com/a/xCg8X
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ClickedCard Is Nothing Then 'Make sure that a card has been clicked, otherwise the below code will fail.
MsgBox("You must select a card.")
Return 'Do not continue execution of this code.
End If
btnSubmit.Visible = True
ClickedCard.Image = imglist1.Images(ListBox1.SelectedIndex)
If ClickedCard.Tag = ListBox1.SelectedIndex Then
roundscore += 1
If roundscore = Cards.Count Then
MsgBox("All right")
End If
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Static AlreadySelected As New List(Of Integer)
If AlreadySelected.Contains(ListBox1.SelectedIndex) Then
MessageBox.Show("Already select once")
Exit Sub
End If
AlreadySelected.Add(ListBox1.SelectedIndex)
'Your other code here
End Sub
静态列表将在对此子程序的调用之间保持不变。进入新一轮时,您必须清除此列表。我希望这有助于解决您在评论中提到的问题。 :-)
在我创建的这个游戏中,我有一组 "cards" 作为图片框,这些图片框设置为随机的大量图像。游戏开始时,图片框中的图像被隐藏,用户必须猜测每张卡片中的图像。我无法确定用户的猜测是否与实际卡片中的内容相符。 在下面的代码中,我使用列表框对用户可以从中猜测的图像名称进行评分。 https://imgur.com/a/xCg8X
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ClickedCard Is Nothing Then 'Make sure that a card has been clicked, otherwise the below code will fail.
MsgBox("You must select a card.")
Return 'Do not continue execution of this code.
End If
btnSubmit.Visible = True
ClickedCard.Image = imglist1.Images(ListBox1.SelectedIndex)
If ClickedCard.Tag = ListBox1.SelectedIndex Then
roundscore += 1
If roundscore = Cards.Count Then
MsgBox("All right")
End If
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Static AlreadySelected As New List(Of Integer)
If AlreadySelected.Contains(ListBox1.SelectedIndex) Then
MessageBox.Show("Already select once")
Exit Sub
End If
AlreadySelected.Add(ListBox1.SelectedIndex)
'Your other code here
End Sub
静态列表将在对此子程序的调用之间保持不变。进入新一轮时,您必须清除此列表。我希望这有助于解决您在评论中提到的问题。 :-)