Click to See Complete Forum and Search --> : Card games
Andrew Empson
Aug 13th, 2000, 11:12 PM
Hi
Just for fun, I've written a sample program which includes functions in a module for drawing any card back or front, shuffling, dragging and dropping and basically anything else I thought people might need to make a card game. I've heard Cards32.dll can draw the cards, but all the other bits you might need you have to do yourself. This should make it simpler.
If anybody wants the sample, send me an email, and I'll send it back to them
Andrew Empson
Aug 16th, 2000, 04:52 PM
If anyone else is interested, please let me know.
RCharlton
Aug 20th, 2000, 02:25 AM
but I have tried to make the card drag along with the mouse by
Public tempX As Single
Public tempY As Single
Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Source.Move X - tempX, Y - tempY
End Sub
Private Sub Card_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lRetVal As Long
lRetVal = ShowCursor(False)
tempX = X
tempY = Y
End Sub
Private Sub Card_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Source.Left = Source.Left + X - tempX
Source.Top = Source.Top + Y - tempY
End Sub
and
Card.DragIcon = imglist.Listimages(4).ExtractIcon
The first works very slowly, but the drag icon is whatever a standard icon size is.
Could you please help.
Richard CHarlton
Andrew Empson
Aug 20th, 2000, 08:00 PM
Are you using my sample?
Here is how I drag cards using my module:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'Prepare for Dragging
If Button = 1 Then
Oldx = x
Oldy = y
toDrag = GetCard(x, y)
Dragged = False
BeginDrag Me, toDrag
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'Drag in progress
Dim xx As Single
Dim yy As Single
If Button = 1 Then
If toDrag > -1 Then
xx = Pack(toDrag).xPos
yy = Pack(toDrag).yPos
xx = xx + (x - Oldx)
yy = yy + (y - Oldy)
Drag Me, xx, yy
Dragged = True
Oldx = x
Oldy = y
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
'Flip the clicked card, or Drag complete
If Dragged = True Then
ToTop toDrag
ReleaseDrag
Me.Cls
DrawPack Me
Else
Card = GetCard(x, y)
If Card > -1 Then
Pack(Card).Face = Not Pack(Card).Face
DrawPack Me
End If
End If
toDrag = -1
Dragged = False
End Sub
There are some form-level variables I haven't mentioned in this scrap. Try painting the cards directly onto the form or a picture box and using MouseMove events on the object rather than drag methods to move the cards.
RCharlton
Aug 21st, 2000, 02:24 AM
With your code, how can you tell when the card being dragged is over another card? Also could you please send me the modules which you have referred to.
Thank you very very much
Richard Charlton
Andrew Empson
Aug 21st, 2000, 03:54 PM
Hi Richard.
My routine includes a GetCard function, which you supply the X and Y positions, and it returns the card at that position. Send me your email address, and I'll forward it to you.
andrewe@tbd.co.nz
RCharlton
Aug 21st, 2000, 04:07 PM
In my first reply on this post, I said that my original code worked but was very slow. Perhaps this could be to do with my using a picture box - maybe an image would refresh faster.
Anyone like to (dis)agree with me? (please)
Thank you
Richard Charlton
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.