Game Development Reference
In-Depth Information
11. Drag a button from the Toolbox and place it to the right of FoxButton.
Change the Name property of this new button to HoundsButton and its
Text property to Hounds.
12. Drag a final button from the Toolbox and place it to the right of
HoundsButton. Change the Name property to UndoButton and its
text property to Undo.
This completes the entirety of the graphical elements of the user interface. For
squares, we will create a class that inherits from the built-in Button class, but we
will not do anything graphical with them. We do need to implement our
checkerboard.
Implementing Moves and Neighbors
Right-click Fox And Hounds in the Solution Explorer window (or use the Project
menu) and choose Add?Module. Name it Moves.vb. Add the Public keyword
to the module definition so that the rest of the program can access what we put
here:
Public Module Moves
We will keep the three kinds of possible moves for each square in this module.
The number of moves from any given square will differ from square to square,
but we know in advance exactly how many squares we have to deal with. Arrays
are intuitive when we know how many things there are in advance, and collec-
tions are easy to use with a variable number of things, so we will use both. Add
the following code to the module:
'Three kinds of moves
Public MovesUp(31) As Collection
Public MovesDown(31) As Collection
Public Neighbors(31) As Collection
Reading this carefully, we see that MovesUp is an array with 32 elements, each of
which is a collection. In VB, arrays start with subscript 0 and go as high as the
number given. A range from 0 to 31 has 32 elements. So square 0 will have a
collection of moves going up, as will every square on the board. Examine
Figure 6.4, and you will notice square 0 has no upward moves. We handle this by
making sure that the collection has no moves in it. There will still be a collection
to look at; it will simply have no moves. Squares that are near any edge of the
 
 
Search Nedrilad ::




Custom Search