上QQ阅读APP看书,第一时间看更新
Time for action – water in the pipes
- Add a method to the
GameBoard
class to clear the water marker from all pieces:Public Sub ResetWater() Dim x, y As Integer For x = 0 To GameBoardWidth For y = 0 To GameBoardHeight boardSquares(x, y).RemoveSufix("W") Next Next End Sub
- Add a method to the
GameBoard
class to fill an individual piece with water:Public Sub FillPiece(x As Integer, y As Integer) boardSquares(x, y).AddSuffix("W") End Sub
What just happened?
The ResetWater()
method simply loops through each item in the boardSquares
array and removes the W
suffix from the GamePiece
. Similarly, to fill a piece with water, the FillPiece()
method adds the W
suffix to the GamePiece
. Recall that by having a W
suffix, the GetSourceRect()
method of GamePiece
shifts the source rectangle one tile to the right on the sprite sheet, returning the image for a pipe filled with water, instead of an empty pipe.