I'm writing a solitaire game in vb6 and have cards in gui on the left side of the screen lined up by suits. I have blank bitmaps on the right hand side of the screen for each suit; therefore I would drop the left hand card on the location of the right hand card that matches the card number and suit; i.e. image1 image of hearts king would drop on the blank card, equalling hearts(12) array.
This is my code, but I am having so many problems with this. I cannot find a way to state that when I drag a card such as image1(12) from the left hand side, it matches the right hand side card and allows for a drop, else an error message is displayed...
Option Explicit
Public Sub Main()
Start_Game.Show
End Sub
Private Sub Exit_Click()
MsgBox ("Thank you for playing. Good Bye.")
End
End Sub
Private Sub Start_Click()
Dim arrDeck(52)
Randomize
Dim Cardcount As Integer
Dim Counter As Integer
Dim Card1 As Integer
Dim Card2 As Integer
' Fill deck with cards in order 1 to 52
Cardcount = 0
Do While Cardcount <= 51
arrDeck(Cardcount) = Cardcount
Cardcount = Cardcount + 1
Loop
' Shuffle the deck - end value (100)
Counter = 0
For Counter = 0 To 100
Card1 = Int(52 * Rnd)
Card2 = Int(52 * Rnd)
If (Card1 <> Card2) Then
Image1(0).Picture = Image1(Card1).Picture
Image1(Card1).Picture = Image1(Card2).Picture
Image1(Card2).Picture = Image1(0).Picture
End If
Next Counter
' Re-shuffle the deck
Counter = 0
For Counter = 0 To 100
Card1 = Int(52 * Rnd)
Card2 = Int(52 * Rnd)
If (Card1 <> Card2) Then
Image1(0).Picture = Image1(Card1).Picture
Image1(Card1).Picture = Image1(Card2).Picture
Image1(Card2).Picture = Image1(0).Picture
End If
Next Counter
' Now output images in order
Counter = 0
For Counter = 0 To 51
Image1(Counter).Visible = True
Next Counter
End Sub
'This is where I'm having problems...
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Dim NewIndex As Integer
Dim i As Integer
Dim j As Integer
For Index = 0 To 12
For NewIndex = 0 To 12
If TypeOf Source Is Image Then
Hearts(Index).Picture = Source.Picture
Hearts(Index).Tag = Source.Tag
Source.Picture = Image1(NewIndex).Picture
Set i = Hearts(Index).Tag
Set j = Image1(NewIndex).Tag
If i = j Then
Image1(NewIndex).Drag vbEndDrag
MsgBox ("You're right!")
Exit Sub
Else
Image1(NewIndex).Drag vbCancel
MsgBox ("This card does not belong here")
Exit Sub
End If
Next
Next
End Sub