Time for action – creating the GameBoard.cs class
As you did to create the
GamePiece
class, right-click on Flood Control in Solution Explorer and select Add | Class.... Name the new class fileGameBoard.vb.
Add the following declarations to the
GameBoard
class:Private rand As New Random() Public Const GameBoardWidth As Integer = 7 Public Const GameBoardHeight As Integer = 9 Private playingPieces As Texture2D Private emptyPiece As Rectangle Private boardSquares(GameBoardWidth, GameBoardHeight) As GamePiece Private waterTracker As New List(Of Vector2)()
What just happened?
We used the Random
class in SquareChase
to generate random numbers. Since we will need to randomly generate pieces to add to the game board, we need an instance of Random
in the GameBoard
class.
The Texture2D
(playingPieces
) and the Rectangle
(emptyPiece
) will be passed in when the class is created and hold the sprite sheet used to draw the board and the location of the sheet's empty piece square.
The two constants and the...