
-----------------------------------
Vincerz
Mon Jan 15, 2007 10:30 pm

Simple help with checking &quot;DragDrop&quot; event for a game
-----------------------------------
Im a student that is still new to VB and programming. Right now, im making a hangman game, using basic methods to make things work.
What im stuck on is getting my program to check when all the boxes to a question are solved (im doing drag and drop instead of using a simple text box)

I thought of two methods, both which i believe are good, but cant get to work exactly

This first one is just checking when all the boxes are filled, but i do not know what to check (go to italics for main parts)
Dim intValue As Integer 

Private Sub cmdStartEasy_Click() 
'Change position and disable buttons and labels 
lblHardInfo.Visible = False 
lblEasyInfo.Visible = False 
cmdStartEasy.Top = 5880 
cmdStartEasy.Left = 8400 
cmdStartEasy.Caption = "Next" 
cmdStartEasy.Enabled = False 
cmdStartHard.Enabled = False 
cmdStartHard.Visible = False 

' Randomizer, will select one of the 10 questions/hints 
intValue = (Int((2 - 1 + 1) * Rnd) + 1) 

'Questions 
If intValue = 1 Then 
lblQuestion.Caption = "The oppisite of small" 
'Set up matching boxes 
lblA.Visible = False 
Image2(12).Visible = True 
Image2(12).Enabled = True 
Image2(12).Top = 5160 
Image2(12).Left = 2400 
Image2(1).Visible = True 
Image2(1).Enabled = True 
Image2(1).Top = 5160 
Image2(1).Left = 3000 
Image2(18).Visible = True 
Image2(18).Enabled = True 
Image2(18).Top = 5160 
Image2(18).Left = 3600 
Image2(7).Visible = True 
Image2(7).Enabled = True 
Image2(7).Top = 5160 
Image2(7).Left = 4200 
Image2(5).Visible = True 
Image2(5).Enabled = True 
Image2(5).Top = 5160 
Image2(5).Left = 4800 
'Check when all boxes are filled and done 
If Image2.DoNotKnowWhatToCheckHere = (Do not know) Then 
MsgBox ("Correct Answer!")
 'Add scores and stuff (not yet worked on)
Else
End If 
Else 
If intValue = 2 Then 
lblQuestion.Caption = "What is 8x8?" 
'Set up matching boxes 
lblA.Visible = False 
Image2(19).Visible = True 
Image2(19).Enabled = True 
Image2(19).Top = 5160 
Image2(19).Left = 2400 
Image2(9).Visible = True 
Image2(9).Enabled = True 
Image2(9).Top = 5160 
Image2(9).Left = 3000 
Image2(24).Visible = True 
Image2(24).Enabled = True 
Image2(24).Top = 5160 
Image2(24).Left = 3600 
Image2(20).Visible = True 
Image2(20).Enabled = True 
Image2(20).Top = 5160 
Image2(20).Left = 4200 
Image2(25).Visible = True 
Image2(25).Enabled = True 
Image2(25).Top = 5160 
Image2(25).Left = 4800 
Image2(6).Visible = True 
Image2(6).Enabled = True 
Image2(6).Top = 5160 
Image2(6).Left = 6000 
Image2(15).Visible = True 
Image2(15).Enabled = True 
Image2(15).Top = 5160 
Image2(15).Left = 6600 
Image2(21).Visible = True 
Image2(21).Enabled = True 
Image2(21).Top = 5160 
Image2(21).Left = 7200 
Image2(18).Visible = True 
Image2(18).Enabled = True 
Image2(18).Top = 5160 
Image2(18).Left = 7800 
Else 
End If 
End If 



End Sub 

Private Sub cmdStartHard_Click() 
'Change position and disable buttons and labels 
lblHardInfo.Visible = False 
lblEasyInfo.Visible = False 
cmdStartHard.Top = 5880 
cmdStartHard.Left = 8400 
cmdStartHard.Caption = "Next" 
cmdStartHard.Enabled = False 
cmdStartEasy.Enabled = False 
cmdStartEasy.Visible = False 

' Randomizer, will select one of the 10 questions/hints 
intValue = (Int((1 - 1 + 1) * Rnd) + 1) 

'Questions 
If intValue = 1 Then 
lblQuestion.Caption = "What goes around the world but stays in a corner?" 
'Set up matching boxes 
lblA.Visible = True 
Image2(19).Visible = True 
Image2(19).Enabled = True 
Image2(19).Top = 5160 
Image2(19).Left = 2400 
Image2(20).Visible = True 
Image2(20).Enabled = True 
Image2(20).Top = 5160 
Image2(20).Left = 3000 
Image2(1).Visible = True 
Image2(1).Enabled = True 
Image2(1).Top = 5160 
Image2(1).Left = 3600 
Image2(13).Visible = True 
Image2(13).Enabled = True 
Image2(13).Top = 5160 
Image2(13).Left = 4200 
Image2(16).Visible = True 
Image2(16).Enabled = True 
Image2(16).Top = 5160 
Image2(16).Left = 4800 
Else 
End If 

End Sub 

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single) 
Source.Visible = True 'Dropped at wrong place, so snap back 
End Sub 

Private Sub Form_Load() 
'Randomizer 
Randomize 

For Index = 1 To 26 
Image1(Index).DragIcon = Image1(Index).Picture 
Next Index 

'Hide Hangman 
Shape1.Visible = False 
Line8.Visible = False 
Line9.Visible = False 
Line10.Visible = False 
Line11.Visible = False 
Line12.Visible = False 

'Proper positions and hide or show objects 
cmdStartHard.Top = 4560 
cmdStartHard.Left = 4920 
cmdStartEasy.Top = 4560 
cmdStartEasy.Left = 3120 
lblA.Visible = False 
Image2(1).Visible = False 
Image2(1).Enabled = False 
Image2(2).Visible = False 
Image2(2).Enabled = False 
Image2(3).Visible = False 
Image2(3).Enabled = False 
Image2(4).Visible = False 
Image2(4).Enabled = False 
Image2(5).Visible = False 
Image2(5).Enabled = False 
Image2(6).Visible = False 
Image2(6).Enabled = False 
Image2(7).Visible = False 
Image2(7).Enabled = False 
Image2(8).Visible = False 
Image2(8).Enabled = False 
Image2(9).Visible = False 
Image2(9).Enabled = False 
Image2(10).Visible = False 
Image2(10).Enabled = False 
Image2(11).Visible = False 
Image2(11).Enabled = False 
Image2(12).Visible = False 
Image2(12).Enabled = False 
Image2(13).Visible = False 
Image2(13).Enabled = False 
Image2(14).Visible = False 
Image2(14).Enabled = False 
Image2(15).Visible = False 
Image2(15).Enabled = False 
Image2(16).Visible = False 
Image2(16).Enabled = False 
Image2(17).Visible = False 
Image2(17).Enabled = False 
Image2(18).Visible = False 
Image2(18).Enabled = False 
Image2(19).Visible = False 
Image2(19).Enabled = False 
Image2(20).Visible = False 
Image2(20).Enabled = False 
Image2(21).Visible = False 
Image2(21).Enabled = False 
Image2(22).Visible = False 
Image2(22).Enabled = False 
Image2(23).Visible = False 
Image2(23).Enabled = False 
Image2(24).Visible = False 
Image2(24).Enabled = False 
Image2(25).Visible = False 
Image2(25).Enabled = False 
Image2(26).Visible = False 
Image2(26).Enabled = False 
End Sub 

Private Sub Image1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer) 
Source.Visible = True 
End Sub 

Private Sub Image2_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 
If Source.Index = Index Then 'If drop at the correct spot, 
Image2(Index).Picture = Source.Picture 'We'll snap the Image in place. 
Else 
Source.Visible = True 'Otherwise snap back 
'Incorrect, so add hangman features 
MsgBox ("Wrong!") 
'Find the correct feature that needs to be added, and add 
If Shape1.Visible = False Then 
Shape1.Visible = True 
Else 
If Line8.Visible = False Then 
Line8.Visible = True 
Else 
If Line11.Visible = False Then 
Line11.Visible = True 
Else 
If Line12.Visible = False Then 
Line12.Visible = True 
Else 
If Line9.Visible = False Then 
Line9.Visible = True 
Else 
If Line10.Visible = False Then 
Line10.Visible = True 
End If 
End If 
End If 
End If 
End If 
End If 
End If 
End Sub 

Private Sub mnuQuit_Click() 
End 
End Sub

Second method, would be using a counter to count each time an item is dragdropped correctly, and when it matches label2.Caption (which will be the number of letters of the answer) the user wins
Dim intValue As Integer 

Private Sub cmdStartEasy_Click() 
'Change position and disable buttons and labels 
lblHardInfo.Visible = False 
lblEasyInfo.Visible = False 
cmdStartEasy.Top = 5880 
cmdStartEasy.Left = 8400 
cmdStartEasy.Caption = "Next" 
cmdStartEasy.Enabled = False 
cmdStartHard.Enabled = False 
cmdStartHard.Visible = False 

' Randomizer, will select one of the 10 questions/hints 
intValue = (Int((2 - 1 + 1) * Rnd) + 1) 

'Questions 
If intValue = 1 Then 
Label2.Caption = 5 '5 are the number of letters there are
lblQuestion.Caption = "The oppisite of small" 
'Set up matching boxes 
lblA.Visible = False 
Image2(12).Visible = True 
Image2(12).Enabled = True 
Image2(12).Top = 5160 
Image2(12).Left = 2400 
Image2(1).Visible = True 
Image2(1).Enabled = True 
Image2(1).Top = 5160 
Image2(1).Left = 3000 
Image2(18).Visible = True 
Image2(18).Enabled = True 
Image2(18).Top = 5160 
Image2(18).Left = 3600 
Image2(7).Visible = True 
Image2(7).Enabled = True 
Image2(7).Top = 5160 
Image2(7).Left = 4200 
Image2(5).Visible = True 
Image2(5).Enabled = True 
Image2(5).Top = 5160 
Image2(5).Left = 4800 
Else 
If intValue = 2 Then 
lblQuestion.Caption = "What is 8x8?" 
'Set up matching boxes 
lblA.Visible = False 
Image2(19).Visible = True 
Image2(19).Enabled = True 
Image2(19).Top = 5160 
Image2(19).Left = 2400 
Image2(9).Visible = True 
Image2(9).Enabled = True 
Image2(9).Top = 5160 
Image2(9).Left = 3000 
Image2(24).Visible = True 
Image2(24).Enabled = True 
Image2(24).Top = 5160 
Image2(24).Left = 3600 
Image2(20).Visible = True 
Image2(20).Enabled = True 
Image2(20).Top = 5160 
Image2(20).Left = 4200 
Image2(25).Visible = True 
Image2(25).Enabled = True 
Image2(25).Top = 5160 
Image2(25).Left = 4800 
Image2(6).Visible = True 
Image2(6).Enabled = True 
Image2(6).Top = 5160 
Image2(6).Left = 6000 
Image2(15).Visible = True 
Image2(15).Enabled = True 
Image2(15).Top = 5160 
Image2(15).Left = 6600 
Image2(21).Visible = True 
Image2(21).Enabled = True 
Image2(21).Top = 5160 
Image2(21).Left = 7200 
Image2(18).Visible = True 
Image2(18).Enabled = True 
Image2(18).Top = 5160 
Image2(18).Left = 7800 
Else 
End If 
End If 



End Sub 

Private Sub cmdStartHard_Click() 
'Change position and disable buttons and labels 
lblHardInfo.Visible = False 
lblEasyInfo.Visible = False 
cmdStartHard.Top = 5880 
cmdStartHard.Left = 8400 
cmdStartHard.Caption = "Next" 
cmdStartHard.Enabled = False 
cmdStartEasy.Enabled = False 
cmdStartEasy.Visible = False 

' Randomizer, will select one of the 10 questions/hints 
intValue = (Int((1 - 1 + 1) * Rnd) + 1) 

'Questions 
If intValue = 1 Then 
lblQuestion.Caption = "What goes around the world but stays in a corner?" 
'Set up matching boxes 
lblA.Visible = True 
Image2(19).Visible = True 
Image2(19).Enabled = True 
Image2(19).Top = 5160 
Image2(19).Left = 2400 
Image2(20).Visible = True 
Image2(20).Enabled = True 
Image2(20).Top = 5160 
Image2(20).Left = 3000 
Image2(1).Visible = True 
Image2(1).Enabled = True 
Image2(1).Top = 5160 
Image2(1).Left = 3600 
Image2(13).Visible = True 
Image2(13).Enabled = True 
Image2(13).Top = 5160 
Image2(13).Left = 4200 
Image2(16).Visible = True 
Image2(16).Enabled = True 
Image2(16).Top = 5160 
Image2(16).Left = 4800 
Else 
End If 

End Sub 

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single) 
Source.Visible = True 'Dropped at wrong place, so snap back 
End Sub 

Private Sub Form_Load() 
'Randomizer 
Randomize 

For Index = 1 To 26 
Image1(Index).DragIcon = Image1(Index).Picture 
Next Index 

'Hide Hangman 
Shape1.Visible = False 
Line8.Visible = False 
Line9.Visible = False 
Line10.Visible = False 
Line11.Visible = False 
Line12.Visible = False 

'Proper positions and hide or show objects 
cmdStartHard.Top = 4560 
cmdStartHard.Left = 4920 
cmdStartEasy.Top = 4560 
cmdStartEasy.Left = 3120 
lblA.Visible = False 
Image2(1).Visible = False 
Image2(1).Enabled = False 
Image2(2).Visible = False 
Image2(2).Enabled = False 
Image2(3).Visible = False 
Image2(3).Enabled = False 
Image2(4).Visible = False 
Image2(4).Enabled = False 
Image2(5).Visible = False 
Image2(5).Enabled = False 
Image2(6).Visible = False 
Image2(6).Enabled = False 
Image2(7).Visible = False 
Image2(7).Enabled = False 
Image2(8).Visible = False 
Image2(8).Enabled = False 
Image2(9).Visible = False 
Image2(9).Enabled = False 
Image2(10).Visible = False 
Image2(10).Enabled = False 
Image2(11).Visible = False 
Image2(11).Enabled = False 
Image2(12).Visible = False 
Image2(12).Enabled = False 
Image2(13).Visible = False 
Image2(13).Enabled = False 
Image2(14).Visible = False 
Image2(14).Enabled = False 
Image2(15).Visible = False 
Image2(15).Enabled = False 
Image2(16).Visible = False 
Image2(16).Enabled = False 
Image2(17).Visible = False 
Image2(17).Enabled = False 
Image2(18).Visible = False 
Image2(18).Enabled = False 
Image2(19).Visible = False 
Image2(19).Enabled = False 
Image2(20).Visible = False 
Image2(20).Enabled = False 
Image2(21).Visible = False 
Image2(21).Enabled = False 
Image2(22).Visible = False 
Image2(22).Enabled = False 
Image2(23).Visible = False 
Image2(23).Enabled = False 
Image2(24).Visible = False 
Image2(24).Enabled = False 
Image2(25).Visible = False 
Image2(25).Enabled = False 
Image2(26).Visible = False 
Image2(26).Enabled = False 
End Sub 

Private Sub Image1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer) 
Source.Visible = True 
End Sub 

Private Sub Image2_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 
If Source.Index = Index Then 'If drop at the correct spot, 
  'One letter correct, so add one to check when all letters are done
   intValue2 = intValue2 + 1
   Label1.Caption = intValue2
          If Label1.Caption = Label2.Caption Then  'If a correct letter was dropped the number of times the number of letters there are in the answer
                 MsgBox ("Correct! Next Question")
                 'Add scores and stuff (not added yet)
           Else
           End If
Image2(Index).Picture = Source.Picture 'We'll snap the Image in place. 
Else 
Source.Visible = True 'Otherwise snap back 
'Incorrect, so add hangman features 
MsgBox ("Wrong!") 
'Find the correct feature that needs to be added, and add 
If Shape1.Visible = False Then 
Shape1.Visible = True 
Else 
If Line8.Visible = False Then 
Line8.Visible = True 
Else 
If Line11.Visible = False Then 
Line11.Visible = True 
Else 
If Line12.Visible = False Then 
Line12.Visible = True 
Else 
If Line9.Visible = False Then 
Line9.Visible = True 
Else 
If Line10.Visible = False Then 
Line10.Visible = True 
End If 
End If 
End If 
End If 
End If 
End If 
End If 
End Sub 

Private Sub mnuQuit_Click() 
End 
End Sub

 THANK YOU[/i]

-----------------------------------
Silent Avenger
Tue Jan 16, 2007 1:54 pm

Re: Simple help with checking &quot;DragDrop&quot; event for a game
-----------------------------------
Welcome to compsci.ca, when you do a drag drop event you can check if the item that was dragged is the right one and put a value into a variable to show if it's the right one or not and when doing the last drag drop check and see if all are correct.
