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

Time for action – generating falling pieces

  1. Modify the FillFromAbove() method of the GameBoard class by adding a call to generate falling pieces right before the rowLookup = -1 line (inside the If block):
    AddFallingPiece(x, y, GetSquare(x, y),
        GamePiece.PieceHeight * (y - rowLookup))
  2. Update the GenerateNewPieces() method by adding the following call, right after the RandomPiece(x,y) line as follows:
    AddFallingPiece(x, y, GetSquare(x, y),
        GamePiece.PieceHeight * (GameBoardHeight + 1))

What just happened?

When FillFromAbove() moves a piece downward, we now create an entry in the FallingPieces dictionary that is equivalent to the newly moved piece. The vertical offset is set to the height of a piece (40 pixels) times the number of board squares the piece was moved. For example, if the empty space was at location 5, 5 on the board, and the piece above it (5, 4) is being moved down one block, the animated piece is created at 5, 5 with an offset of 40 pixels (5-4 = 1, times 40).

When new pieces are generated for the board, they are added with an offset equal to the height (in pixels) of the game board (recall that we specified the height as one less than the real height, to account for the allocation of the extra element in the boardSquares array), determined by multiplying the GamePiece.PieceHeight value by GameBoardHeight +1. This means they will always start above the playing area and fall into it.

Rotating pieces

The last type of animated piece that we need to deal with adding during the play is the rotation piece. This piece type is added whenever the user clicks on a game piece.

主站蜘蛛池模板: 呈贡县| 石狮市| 高尔夫| 铜山县| 永新县| 宁强县| 瑞昌市| 安顺市| 永安市| 宝山区| 滨海县| 洪洞县| 电白县| 澄城县| 乌拉特后旗| 屯昌县| 天水市| 手游| 沙洋县| 秦安县| 潢川县| 肇庆市| 聊城市| 葫芦岛市| 宜良县| 凤山县| 麻城市| 新巴尔虎右旗| 封开县| 肥城市| 龙山县| 珲春市| 禄丰县| 宁阳县| 富平县| 胶州市| 宁河县| 偃师市| 中超| 廉江市| 罗平县|