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

Time for action – filling in the gaps

  1. Add the FillFromAbove() method to the GameBoard class.
    Public Sub FillFromAbove(x As Integer, y As Integer)
      Dim rowLookup As Integer = y - 1
    
      Do While (rowLookup >= 0)
        If GetSquare(x, rowLookup) <> "Empty" Then
          SetSquare(x, y, GetSquare(x, rowLookup))
          SetSquare(x, rowLookup, "Empty")
          rowLookup = -1
        End If
        rowLookup -= 1
      Loop
    End Sub

What just happened?

Given a square to fill, FillFromAbove() looks at the piece directly above to see if it is marked as Empty. If it is, the method will subtract one from rowLookup and start over until it reaches the top of the board. If no non-empty pieces are found when the top of the board is reached, the method does nothing and exits.

When a non-empty piece is found, it is copied to the destination square, and the copied piece is changed to an empty piece. The rowLookup variable is set to -1 to ensure that the loop does not continue to run.

Generating new pieces

We can create a single method that will fill any empty spaces on the game board, use it when the game begins, and when pieces are removed from the board after scoring.

主站蜘蛛池模板: 凤阳县| 仁寿县| 漠河县| 新巴尔虎左旗| 辽阳县| 出国| 修水县| 都匀市| 收藏| 石林| 余姚市| 永福县| 阿拉善右旗| 长顺县| 咸阳市| 达日县| 红桥区| 潞城市| 淮北市| 崇义县| 罗江县| 六枝特区| 哈巴河县| 太保市| 贵溪市| 聊城市| 贵溪市| 平潭县| 临颍县| 北安市| 高台县| 益阳市| 梅河口市| 涞源县| 宜章县| 扎兰屯市| 左贡县| 富阳市| 柯坪县| 时尚| 建始县|