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

Time for action – GamePiece class methods – part 1 – updating

  1. Add the following methods to the GamePiece class:
    Public Sub SetPiece(type As String, suffix As String)
      _pieceType = type
      _pieceSuffix = suffix
    End Sub
    
    Public Sub SetPiece(type As String)
      SetPiece(type, "")
    End Sub
    
    Public Sub AddSuffix(suffix As String)
      If Not _pieceSuffix.Contains(suffix) Then
        _pieceSuffix &= suffix
      End If
    End Sub
    
    Public Sub RemoveSufix(suffix As String)
      _pieceSuffix = _pieceSuffix.Replace(suffix, "")
    End Sub

    The first two methods are overloads with the same name, but different parameter lists. In a manner similar to the GamePiece constructors, code that wishes to update a GamePiece can pass it a piece type and, optionally, a suffix.

    Additional methods have been added to modify suffixes without changing the pieceType associated with the piece. The AddSuffix() method first checks to see if the piece already contains the suffix. If it does, nothing happens. If it does not, the suffix value passed to the method is added to the _pieceSuffix member variable.

    The RemoveSuffix() method uses the Replace() method of the String class to remove the passed suffix from the _pieceSuffix variable.

Rotating pieces

The heart of the Flood Control play mechanic is the ability of the player to rotate pieces on the game board to form continuous pipes. In order to accomplish this, we can build a table that, given an existing piece type and a rotation direction, supplies the name of the piece type after rotation. We can then implement this code as a switch statement:

Rotating pieces
主站蜘蛛池模板: 通海县| 沈丘县| 长岭县| 沙坪坝区| 榆中县| 延长县| 平泉县| 商南县| 抚松县| 米林县| 连州市| 正镶白旗| 北流市| 东乌珠穆沁旗| 大名县| 石景山区| 遂昌县| 若羌县| 武宁县| 耒阳市| 甘谷县| 奉新县| 滨州市| 南雄市| 来宾市| 万山特区| 新营市| 富宁县| 德阳市| 临泽县| 兴业县| 平山县| 黄骅市| 绥阳县| 新源县| 台山市| 芦溪县| 阿坝| 海晏县| 云龙县| 嘉荫县|