Game Development Reference
In-Depth Information
'Default to no move allowed
e.Effect = DragDropEffects.None
'Only allow F&H buttons to drag over.
If Not (e.Data.GetDataPresent(GetType(FaHButton))) Then
Return
End If
'We will need the board's game state.
Dim MainForm As Board = CType(Me.Parent, Board)
Dim GS As GameState = MainForm.CurrentGame
'Can't drop on me if I am occupied.
If GS.HasChecker(MySubscript) Then
Return
End If
'We also need to know where this drop is coming from.
Dim Source As FaHButton = _
CType(e.Data.GetData(GetType(FaHButton)), FaHButton)
If Source.Subscript = GS.FoxAt Then
'Do the fox's neighbors include me?
Dim FoxsNeighbors As Collection = Moves.Neighbors(Source.Subscript)
If FoxsNeighbors.Contains(MySubscript.ToString) Then
'A valid move!
e.Effect = DragDropEffects.Move
End If
Else
'So it must therefore be a hound.
Dim HoundMoves As Collection = Moves.MovesDown(Source.Subscript)
If HoundMoves.Contains(MySubscript.ToString) Then
'A valid move!
e.Effect = DragDropEffects.Move
End If
End If
End Sub
Run this code in the debugger. Drag a hound around the board. Drag the fox
around the board. You should be able to tell valid moves by the feedback from
the system. What remains is to deal with the drop. Add this final routine to the
class:
Search Nedrilad ::




Custom Search