Game Development Reference
In addition, we have to prevent moves that break the rules of the game. We will
make additions to the code in three areas: the board, the button class, and the
The board has to hold the current game state for the game it is showing. Drag and
drop is going to happen to the buttons. The buttons will need to ask the board for
the current game state to validate potential moves. The buttons will need to tell
the board about the new game state after a valid move has been performed. The
buttons will need help from the GameState class to generate that new game state.
As before, the board will ask the GameState class to paint the new state onto
the array of buttons the board is holding.
UI Elements in the Board Class
The board code is the easiest to deal with. Add the following code to the Board
Public Property CurrentGame() As GameState
'There can be two parts to a property.
'Get is very simple for us:
'Set requires some work on our part.
Set(ByVal value As GameState)
'Did we have a prior game to save?
If ThisGame IsNot Nothing Then
'If one side couldn't move, the undo
'will need multiple clicks to make a visible change.
UndoButton.Enabled = True
'Store the new current game.
ThisGame = value
'Ask game state to paint itself.
The outside world calls Get to get the GameState object that represents the current
game shown on the board. The outside world calls Set to give the board a new