官术网_书友最值得收藏!

Time for action – manipulating the GameBoard

  1. Add public methods to the GameBoard class to interact with GamePieces:
    Public Sub RotatePiece(x As Integer, y As Integer,
      clockwise As Boolean)
      boardSquares(x, y).RotatePiece(clockwise)
    End Sub
    
    Public Function GetSourceRect(
      x As Integer, y As Integer) As Rectangle
      Return boardSquares(x, y).GetSourceRectangle()
    End Function
    
    Public Function GetSquare(x As Integer, y As Integer) As String
      Return boardSquares(x, y).PieceType
    End Function
    
    Public Sub SetSquare(x As Integer, y As Integer, pieceType As String)
      boardSquares(x, y).SetPiece(pieceType)
    End Sub
    
    Public Function HasConnector(x As Integer, y As Integer, direction As String) As Boolean
      Return boardSquares(x, y).HasConnector(direction)
    End Function
    
    Public Sub RandomPiece(x As Integer, y As Integer)
      boardSquares(x, y).SetPiece(GamePiece.PieceTypes(
        rand.Next(0, GamePiece.MaxPlayablePieceIndex + 1)))
    End Sub

What just happened?

RotatePiece(), GetSourceRect(), GetSquare(), SetSquare(), and HasConnector() methods simply locate the appropriate GamePiece within the boardSquares array and pass on the function request to the piece.

The RandomPiece() method uses the rand object to get a random value from the PieceTypes array and assigns it to a GamePiece. It is important to remember that with the Random.Next() method overload used here, the second parameter is non-inclusive. In order to generate a random number from 0 through 5, the second parameter needs to be 6.

Tip

Subs, functions, and methods

Method is the generic term for a callable code block inside a class. Both Subs and Functions are methods. The difference between the two is that a Function returns a value, while a Sub does not.

Filling in the gaps

Whenever the player completes a scoring chain, the pieces in that chain are removed from the board. Any pieces above them fall down into the vacated spots and new pieces are generated.

主站蜘蛛池模板: 克什克腾旗| 百色市| 平武县| 肥乡县| 万山特区| 同德县| 百色市| 中西区| 南漳县| 富阳市| 合水县| 霞浦县| 汶上县| 前郭尔| 耒阳市| 久治县| 称多县| 镶黄旗| 图们市| 华亭县| 车致| 阿坝县| 信阳市| 镇平县| 永福县| 南川市| 盐源县| 体育| 于田县| 麻栗坡县| 鄂托克前旗| 杭锦后旗| 古浪县| 山阳县| 寻甸| 黔西| 台东县| 平邑县| 分宜县| 沽源县| 神木县|