Time for action – manipulating the game board
Add public methods to the GameBoard class to interact with
GamePiece
:public void RotatePiece(int x, int y, bool clockwise) { boardSquares[x, y].RotatePiece(clockwise); } public Rectangle GetSourceRect(int x, int y) { return boardSquares[x, y].GetSourceRect(); } public string GetSquare(int x, int y) { return boardSquares[x, y].PieceType; } public void SetSquare(int x, int y, string pieceName) { boardSquares[x, y].SetPiece(pieceName); } public bool HasConnector(int x, int y, string direction) { return boardSquares[x, y].HasConnector(direction); } public void RandomPiece(int x, int y) { boardSquares[x, y].SetPiece(GamePiece.PieceTypes[rand.Next(0, GamePiece.MaxPlayablePieceIndex+1)]); }
What just happened?
RotatePiece()
, GetSourceRect()
, GetSquare()
, SetSquare()
, and HasConnector()
methods simply locate the appropriate GamePiece
within the boardSquares
array and...