VB6 card game question
-
Firstly, I don't think you should be messing with OLEDrag* at all, so would set OLEDragMode property to 0. OLE drag features are for dragging and dropping data rather than images. E.g. drag data between DataGrid controls. Secondly, I don't think you should have loops in the Hearts_DragOver or Hearts_DragDrop events. You probably should not be changing the value of Index (as the loops are doing) and I doubt that you should be changing the Source.Picture. Imagine the following. There is a form with two control arrays called theShapes and theBoxes. Both have say 5 items (so indexes go from 0 to 4) with theShapes on left of form; theBoxes on right. The user clicks and drags e.g. theShapes(3) image over to the right. Suppose it is dragged over theBoxes(1) image. Then the theBoxes_DragOver event is triggered with Index = 1 and State = 0. So in the code the only image that should change color is theBoxes(1). All the other theBoxes() images should remain as they were. So no loop required. Also, the Source is theShapes(3) and presumably you don't want its picture to change. So you never want to be doing something like
Source.Picture = SomeOtherControl.Picture
. Suppose that the object is to place the correct shapes in the correct boxes. So at the start theBoxes() all have some blank image; theShapes() all have some appropriate image. E.g. theShapes(3) could be a triangle, theShapes(4) could be a circle, etc. If the user drags a shape and drops it into a box, the box should only accept it if it is the correct shape. So e.g. if theShape(3) (i.e. a triangle) is dragged and dropped into theBoxes(1), the drop should only succeed if theBoxes(1) accepts triangles. So how do we tell if this is the case? We cannot compare pictures because theBoxes() are all a blank image so will never be the same as a shape image. One way of doing this is to set the Tag property for each of the controls and compare the Tags before allowing the drop to succeed or fail. E.g. when setting up the control arrays you would have something liketheShapes(3).Tag = "Triangle"
theBoxes(0).Tag = "Square"
theBoxes(1).Tag = "Triangle"
theBoxes(2).Tag = "Circle"In the theBoxes_DragDrop event you would then have something like
If theBoxes(Index).Tag = Source.Tag Then
'Allow the drop
Else
'Cancel the drop
End IfI think this is how to do it. But to do so requires that the DragMode for theShapes() to be set to 0 (i.e. vbManual) and that the Drag method is implemented. I might b
Wow! Thanks for the expert explanation. Does this mean I would put: Image1(0).Tag = Hearts(0).Tag Somewhere in the first part of the code? Where so? This is all my code so far; problem is which ever card is in the first slot (as in Image1(0)), but can be any card, when dropped over Hearts(0), it says, you're right and allows drop. If the real Image1(0).Picture, King Hearts is dropped over Hearts(0), it says you're wrong. I changed all my settings in design mode to put images on the left as Automatic and none for both OLE modes. I set images on the right to be Manual for drag and none for both Ole modes. Any problems on this? Here is all of my code so far: I appeciate your help.... 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) Dim Cardcount As Integer Dim Counter As Integer Do While Cardcount <= 51 arrDeck(Cardcount) = Cardcount Cardcount = Cardcount + 1 Loop Dim swap As Integer Dim posn1 As Integer Dim posn2 As Integer Randomize For swap = 0 To 100 posn1 = Int(52 * Rnd) posn2 = Int(52 * Rnd) If (posn1 <> posn2) Then KingH(0).Picture = Image1(posn1).Picture Image1(posn1).Picture = Image1(posn2).Picture Image1(posn2).Picture = KingH(0).Picture End If Next swap Counter = 0 For Counter = 0 To 51 Image1(Counter).Visible = True Next Counter End Sub Private Sub Hearts_DragOver(Index As Integer, Source As Control, _ X As Single, Y As Single, State As Integer) If Index <= 12 Then If State = 0 Then &n
-
Wow! Thanks for the expert explanation. Does this mean I would put: Image1(0).Tag = Hearts(0).Tag Somewhere in the first part of the code? Where so? This is all my code so far; problem is which ever card is in the first slot (as in Image1(0)), but can be any card, when dropped over Hearts(0), it says, you're right and allows drop. If the real Image1(0).Picture, King Hearts is dropped over Hearts(0), it says you're wrong. I changed all my settings in design mode to put images on the left as Automatic and none for both OLE modes. I set images on the right to be Manual for drag and none for both Ole modes. Any problems on this? Here is all of my code so far: I appeciate your help.... 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) Dim Cardcount As Integer Dim Counter As Integer Do While Cardcount <= 51 arrDeck(Cardcount) = Cardcount Cardcount = Cardcount + 1 Loop Dim swap As Integer Dim posn1 As Integer Dim posn2 As Integer Randomize For swap = 0 To 100 posn1 = Int(52 * Rnd) posn2 = Int(52 * Rnd) If (posn1 <> posn2) Then KingH(0).Picture = Image1(posn1).Picture Image1(posn1).Picture = Image1(posn2).Picture Image1(posn2).Picture = KingH(0).Picture End If Next swap Counter = 0 For Counter = 0 To 51 Image1(Counter).Visible = True Next Counter End Sub Private Sub Hearts_DragOver(Index As Integer, Source As Control, _ X As Single, Y As Single, State As Integer) If Index <= 12 Then If State = 0 Then &n
ymilan wrote:
put images on the left as Automatic and
Then you cannot stop the drop - you can only do that if the mode is Manual and you have a Drag method which allows you to Cancel the drop.
ymilan wrote:
If State = 0 Then Hearts(Index).Picture = LoadPicture("C:\Program1\redbacking.gif") Else If State = 1 Then Hearts(Index).Picture = Hearts(Index).Picture Else
This won't work - when you DragDrop is triggered with State = 0 (entering) the Hearts(Index).Picture is changed to the gif. When it is triggered with state = 1 (leaving) it set back to itself i.e. to the gif it was set to when entering.
ymilan wrote:
Does this mean I would put: Image1(0).Tag = Hearts(0).Tag Somewhere in the first part of the code?
Have you set Hearts(x).Tags in Designer for all controls? If so and you want the Image(x).Tags to be the same as the Hearts(x) tags, you need to do so in the Form_Load event. But I'm not sure that's what you want. Is this the complete code? There seems to be something missing e.g. this is not right.
ymilan wrote:
Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
ymilan wrote:
put images on the left as Automatic and
Then you cannot stop the drop - you can only do that if the mode is Manual and you have a Drag method which allows you to Cancel the drop.
ymilan wrote:
If State = 0 Then Hearts(Index).Picture = LoadPicture("C:\Program1\redbacking.gif") Else If State = 1 Then Hearts(Index).Picture = Hearts(Index).Picture Else
This won't work - when you DragDrop is triggered with State = 0 (entering) the Hearts(Index).Picture is changed to the gif. When it is triggered with state = 1 (leaving) it set back to itself i.e. to the gif it was set to when entering.
ymilan wrote:
Does this mean I would put: Image1(0).Tag = Hearts(0).Tag Somewhere in the first part of the code?
Have you set Hearts(x).Tags in Designer for all controls? If so and you want the Image(x).Tags to be the same as the Hearts(x) tags, you need to do so in the Form_Load event. But I'm not sure that's what you want. Is this the complete code? There seems to be something missing e.g. this is not right.
ymilan wrote:
Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
ymilan wrote:
put images on the left as Automatic and
Then you cannot stop the drop - you can only do that if the mode is Manual and you have a Drag method which allows you to Cancel the drop.
ymilan wrote:
If State = 0 Then Hearts(Index).Picture = LoadPicture("C:\Program1\redbacking.gif") Else If State = 1 Then Hearts(Index).Picture = Hearts(Index).Picture Else
This won't work - when you DragDrop is triggered with State = 0 (entering) the Hearts(Index).Picture is changed to the gif. When it is triggered with state = 1 (leaving) it set back to itself i.e. to the gif it was set to when entering.
ymilan wrote:
Does this mean I would put: Image1(0).Tag = Hearts(0).Tag Somewhere in the first part of the code?
Have you set Hearts(x).Tags in Designer for all controls? If so and you want the Image(x).Tags to be the same as the Hearts(x) tags, you need to do so in the Form_Load event. But I'm not sure that's what you want. Is this the complete code? There seems to be something missing e.g. this is not right.
ymilan wrote:
Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
When I put the images on the left in design view as automatic, when they are in a random place, i.e. image1(0), King of Hearts, they do not move at all. When I put them in manual, they move. For some reason; and you said; but I don't understand the reason; when in State 0, I move the images, i.e. King of Hearts to the top of the hearts(0) image (a white backing gif, not King of Hearts. I did this so I can show a white backed card, so the player can see a white card instead of a black space. I can place the redbacking card no problem when the card enters the white backed card on the right. It works. However, if it is right, it doesn't drop the Image1(Index).Picture at all. It leaves it a redbacking gif. Now, when my images on the left are randomized, and I want to pic out the King of Hearts on the left, somewhere in the shuffle, it says you're wrong when I place it over the hearts(0) position on the right. It shows a red backing but, does not say You're right or drop the card. I have that code in my hearts dragdrop; you'll see above in my last code reply. However, when I place a random card from the Image1(0) POSITION on the left, it works and says you'r right, but that is the wrong card....???? Don't understand. It leaves a redbacked gif as well, when it is the wrong card, but say's your're right. You're helping me and I'm glad; Thank you.