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

Time for action – generating new pieces

  1. Add the GenerateNewPieces() method to the GameBoard class:
    Public Sub GenerateNewPieces(dropSquare As Boolean)
      Dim x, y As Integer
    
      If dropSquare Then
        For x = 0 To GameBoardWidth
          For y = GameBoardHeight To 0 Step -1
            If GetSquare(x, y) = "Empty" Then
              FillFromAbove(x, y)
            End If
          Next
        Next
      End If
    
      For y = 0 To GameBoardHeight
        For x = 0 To GameBoardWidth
          If GetSquare(x, y) = "Empty" Then
            RandomPiece(x, y)
          End If
        Next
      Next
    
    End Sub

What just happened?

When GenerateNewPieces() is called with true passed as dropSquares, the looping logic processes one column at a time from the bottom up. By using the step 1 in the for loop for the Y coordinate, we can make the loop run backwards instead of the default forward direction. When it finds an empty square, it calls FillFromAbove() to pull a filled square from above into that location.

The reason the processing order is important here is that by filling a lower square from a higher position, that higher position will become empty. It, in turn, will need to be filled from above.

After the holes are filled (or if dropSquares is set to false), GenerateNewPieces() examines each square in boardSquares and asks it to generate random pieces for each square that contains an empty piece.

Water-filled pipes

Whether or not a pipe is filled with water, it is managed separately from its orientation. Rotating a single pipe could change the water-filled status of any number of other pipes, without changing their rotation.

Instead of filling and emptying individual pipes, it is easier to empty all of the pipes and then re-fill the pipes that need to be marked as having water in them.

主站蜘蛛池模板: 永寿县| 偏关县| 呼伦贝尔市| 剑阁县| 定边县| 姜堰市| 明光市| 玉田县| 鄂托克旗| 南投市| 古田县| 巴彦淖尔市| 政和县| 定州市| 衢州市| 莱芜市| 岗巴县| 尚志市| 彰化市| 通海县| 中西区| 揭阳市| 曲沃县| 辽宁省| 西峡县| 通海县| 无极县| 廊坊市| 贵州省| 竹北市| 阳朔县| 昌江| 九龙坡区| 沾化县| 砚山县| 正镶白旗| 城固县| 永年县| 岫岩| 景洪市| 江阴市|