-
well, i had loaded array of images during run-time and when the user clicks on the imagebox then the image is shown and when the user clicks on the other imagebox then the other image also shown.
well my problem is that, how can i compare the image which is first clicked with the image which is second clicked?
if both pics are of the same then both pics will remain in the imagebox (means shown), else both pics is closed (means unload picture).
Code:
Private Sub imagebox_Click(Index As Integer)
:
:
:
-
Can't you just let it remember what picture you loaded in that imagebox??? :confused:
-
Code:
Private iLastClick As Integer
Private Sub Form_Load()
iLastClick = -1
End Sub
Private Sub imagebox_Click(Index As Integer)
If iLastClick = -1 Then
' This is the first image we clicked, save the index
iLastClick = Index
' And you can Do the picture changing here, like:
' imagebox(Index).Picture = sourceimgbox.Picture
Else
' This is the second image we clicked, reset the index
iLastClick = -1
' Check If they're the same
If imagebox(Index).Picture = imagebox(iLastClick).Picture Then
' The images should stay
Else
' Make them go away
End If
End Sub
Is that what you mean?
-
Ummm... PsychoMark, you reset the index before checking it... I think he wants to make a simple concentration game. (for this you may want to have another array of stdpictures so the images are just card backs, if that's what you are making: )
Code:
Dim Pics(0 to 9, 0 to 9) as StdPicture
Dim LastClickedX as Integer
Dim LastClickedY as Integer
Dim DonePic(0 to 9, 0 to 9) as Boolean
Private Sub Picture1_Click(Index as Integer)
If DonePic(Index Mod 10, Int(Index / 10)) Then Exit Sub
If LastClickedX < 0 or LastClickedY < 0 Then
LastClickedY = Int(Index / 10)
LastClickedX = Index Mod 10
End If
If LastClickedX > -1 or LastClickedY > -1 Then
If Pics(Index Mod 10, Int(Index / 10)) = Pics(LastClickedX, LastClickedY) Then
Picture1(LastClickedY * 10 + LastClickedX).Picture = Pics(LastClickedX, LastClickedY)
Picture1(Index).Picture = Pics(LastClickedX, LastClickedY)
DonePic(Index Mod 10, Int(Index / 10)) = True
DonePic(LastClickedX, LastClickedY) = True
End If
End If
End Sub
Private Sub Form_Load()
Dim I as Integer: Dim J as Integer
LastClickedX = -1: LastClickedY = -1
For I = 0 to 9: For J = 0 to 9
Pics(J, I) = LoadPicture(App.Path & "\pic" & J & I & ".bmp"
Next I: Next J
End Sub
-
To find out if the user has "won", loop through donepic. If they are all true, then the user has won. (The above code does a 10 x 10 card game.
-
Ummm.... Sastraxi :D
I resetted the index at Form_Load, and whenever someone had selected the second image...
* looks again *
Oops, wait, my mistake, just saw what I did. You're right, the iLastIndex = -1 should be after the If imagebox.....