Game Development Reference
sq.Height = sqsize
sq.Width = sqsize
sq.Parent = Me
'Four in every row.
sq.Top = 5 + sqsize * (i \ 4)
'Left: 5 for border, i mod 4 term steps through the 4 columns,
'and the mod 2 term for the offset in alternating rows.
sq.Left = 5 + (sqsize * 2) * (i Mod 4) + sqsize * (((i \ 4) + 1) Mod 2)
BoardSquares(i) = sq
'Just use the reset function from here to get a new game.
Call ResetButton_Click(Nothing, Nothing)
That provides us with the one-time initializations. We need to add the reset code
that we called in order to get a new game. Add the following to the class:
Private Sub ResetButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ResetButton.Click
'Start with a brand new one.
ThisGame = New GameState
'Clear the undo collection.
'Means we can't undo.
UndoButton.Enabled = False
'Have the current game imprint itself on the buttons.
We are now ready to fire up the game and see if we get the board we expect. Run
the code in the debugger, and you should get the board illustrated in Figure 6.2.
While the reset button works, we cannot tell because we cannot make any
changes to the game. This was a great deal of work for a static picture, so we
should let the player have some fun.
We will use drag and drop to let the player make moves. On the graphical side,
there are three parts to a drag-and-drop operation: the mouse button down
event, the drag over, and the drop. Since our game board is more than just
moveable squares, we also have to change the game state after we make our move.