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

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.

主站蜘蛛池模板: 惠来县| 桃园县| 财经| 徐水县| 万山特区| 邹城市| 交口县| 岐山县| 苏尼特左旗| 侯马市| 安阳市| 桂林市| 威信县| 呼玛县| 安溪县| 册亨县| 九龙城区| 应用必备| 密山市| 九江县| 奉贤区| 武安市| 汉沽区| 香格里拉县| 绥化市| 涞源县| 麻江县| 象山县| 堆龙德庆县| 曲沃县| 疏附县| 名山县| 金坛市| 宁南县| 深圳市| 乐清市| 宁远县| 金寨县| 会宁县| 雷州市| 三穗县|