Je suis en train de créer un jeu de cartes où des images sont chargées à partir d'une liste d'images et affichées pendant un court laps de temps, puis "cachées" - l'image de la carte change. J'ai besoin d'aide lorsque je clique sur l'une de ces images pour qu'elle me dise quel est l'index de la carte et que je puisse changer l'image de cette carte. Ceci sera utilisé par le dernier sous dans le code posté ci-dessous ; "CARD THE USER CLICKED".
Public Class Form1
Private Cards As New List(Of PictureBox)
Private randomnumber As Integer
Private UserChoice As Integer
Private Timer As Integer
Private Sub SetupCards(numberofcards As Integer)
ClearGame()
For i As Integer = 0 To numberofcards
Dim PicCard As PictureBox = New PictureBox()
RandomCard()
PicCard.Width = 100
PicCard.Height = 200
PicCard.Top = 50
PicCard.Left = 50 + PicCard.Width * i
Me.Controls.Add(PicCard)
PicCard.Image = imglist1.Images(randomnumber)
PicCard.Tag = randomnumber
AddHandler PicCard.Click, AddressOf Me.cardflip_click
Cards.Add(PicCard)
Next i
End Sub
Private Sub ClearGame()
If Cards.Count > 0 Then
For i As Integer = 0 To Cards.Count - 1
Me.Controls.Remove(Cards(i))
Next
End If
' Clear the cards if they were already setup from a previous game.
Cards.Clear()
End Sub
Private Sub EndRound()
'set all the images to back of card
If Cards.Count > 0 Then
For i As Integer = 0 To Cards.Count - 1
Cards(i).Image = imglistBackOfCard.Images(2)
Next
End If
End Sub
Private Sub cardflip_click(sender As Object, e As EventArgs)
Dim picture As PictureBox = CType(sender, PictureBox)
Dim idTag As Integer = CType(picture.Tag, Integer)
'MsgBox(idTag)
UserChoice = idTag
End Sub
Private Sub btnstartGame_Click(sender As Object, e As EventArgs) Handles btnStartGame.Click
Dim howmanycards As String
howmanycards = InputBox("How Many Cards?", "Please Enter")
SetupCards(Int(howmanycards - 1))
ListBox1.Enabled = True
ListBox1.Visible = True
For Each imagesNames As String In imglist1.Images.Keys
ListBox1.Items.Add(imagesNames)
Next
Timer1.Start()
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If UserChoice = ListBox1.SelectedIndex Then
MsgBox("correct")
Cards(CARDTHEUSERCLICKED).Image = imglist1.Images(UserChoice)
' Cards(idTag).Image =
Else
MsgBox("WRONG :(")
Cards(CARDTHEUSERCLICKED).Image = imglist1.Images(UserChoice)
End If
End Sub
End Class