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

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:
    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:
    AddFallingPiece(x, y, GetSquare(x, y),
        GamePiece.PieceHeight * GameBoardHeight);

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, determined by multiplying the GamePiece.PieceHeight value by the GameBoardHeight. This means they will always start above the playing area and fall into it.

Rotating pieces

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

主站蜘蛛池模板: 鄂托克前旗| 九寨沟县| 海林市| 思茅市| 郓城县| 普宁市| 临洮县| 庆安县| 延长县| 博客| 齐齐哈尔市| 新兴县| 潮州市| 贵阳市| 蓝山县| 昭苏县| 麦盖提县| 柳林县| 曲周县| 高州市| 濉溪县| 乌鲁木齐县| 清新县| 辽阳市| 盈江县| 高要市| 喀喇| 县级市| 安乡县| 正宁县| 庆云县| 麟游县| 西盟| 乌兰县| 弥渡县| 桦南县| 临安市| 正定县| 民乐县| 四川省| 濉溪县|