- As you did to create the GamePiece class, right-click on Flood Control in Solution Explorer and select Add | Class... Name the new class file GameBoard.cs.
- Add the
using
directive for the XNA framework at the top of the file:using Microsoft.Xna.Framework;
- Add the following declarations to the GameBoard class:
Random rand = new Random(); public const int GameBoardWidth = 8; public const int GameBoardHeight = 10; private GamePiece[,] boardSquares = new GamePiece[GameBoardWidth, GameBoardHeight]; private List<Vector2> WaterTracker = new List<Vector2>();
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 two constants and the boardSquares
array provide the storage mechanism for the GamePiece objects that make up the 8 by 10 piece board.
Finally, a List of Vector2
objects is declared that we will use to identify scoring pipe combinations. The List class is one of C#'s Generic Collection classes—classes that use the Generic templates (angle brackets) we first saw when loading a texture for SquareChase. Each of the Collection classes can be used to store multiple items of the same type, with different methods to access the entries in the collection. We will use several of the Collection classes in our projects. The List class is much like an array, except that we can add any number of values at runtime, and remove values in the List if necessary.
A Vector2
is a structure defined by the XNA Framework that holds two floating point values, X and Y. Together the two values represent a vector pointing in any direction from an imaginary origin (0, 0) point. We will use Vector2
structures to represent the locations on our game board in Flood Control, placing the origin in the upper left corner of the board.