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

Time for action – GamePiece class methods – part 2 – rotation

  1. Add the RotatePiece() method to the GamePiece class:
    Public Sub RotatePiece(clockwise As Boolean)
      Select Case _pieceType
        Case "Left,Right"
          _pieceType = "Top,Bottom"
        Case "Top,Bottom"
          _pieceType = "Left,Right"
        Case "Left,Top"
          If (clockwise) Then
            _pieceType = "Top,Right"
          Else
            _pieceType = "Bottom,Left"
          End If
        Case "Top,Right"
          If (clockwise) Then
            _pieceType = "Right,Bottom"
          Else
            _pieceType = "Left,Top"
          End If
        Case "Right,Bottom"
          If (clockwise) Then
            _pieceType = "Bottom,Left"
          Else
            _pieceType = "Top,Right"
          End If
        Case "Bottom,Left"
          If clockwise Then
            _pieceType = "Left,Top"
          Else
            _pieceType = "Right,Bottom"
          End If
      End Select
    End Sub

What just happened?

The only information the RotatePiece() method needs is a rotation direction. For straight pieces, rotation direction does not matter (a left/right piece will always become a top/bottom piece and vice-versa).

For angled pieces, the piece type is updated based on the rotation direction and the previous screenshot.

Tip

Why all the strings?

It would certainly be reasonable to create constants that represent the various piece positions, instead of fully spelling out things, such as Bottom,Left as strings. However, because the Flood Control game is not taxing on the system, the additional processing time required for string manipulation will not impact the game negatively and helps clarify how the logic works, especially when we get to determine which pipes are filled with water.

Pipe connectors

Our GamePiece class will need to be able to provide information about the connectors it contains (top, bottom, left, and right) to the rest of the game. Since we have represented the piece types as simple strings, a string comparison will determine what connectors the piece contains.

主站蜘蛛池模板: 晋中市| 天气| 江安县| 万荣县| 大方县| 紫金县| 灵武市| 铜梁县| 蒙阴县| 诏安县| 金坛市| 右玉县| 南投市| 陆河县| 诸暨市| 安康市| 通山县| 尖扎县| 湘潭县| 房山区| 云梦县| 比如县| 大田县| 宝鸡市| 阿拉善右旗| 顺义区| 阳泉市| 阿克陶县| 星座| 大余县| 镇平县| 昌都县| 绥阳县| 广河县| 镇宁| 乌恰县| 遵义市| 溆浦县| 尤溪县| 额尔古纳市| 固镇县|