Time for action – GamePiece class methods – part 3 – connection methods
Add the
GetOtherEnds()
method to theGamePiece
class:Public Function GetOtherEnds(startingEnd As String) As String() Dim Opposites As List(Of String) = New List(Of String)() For Each pipeEnd As String In _pieceType.Split(CChar(",")) If pipeEnd <> startingEnd Then Opposites.Add(pipeEnd) End If Next Return Opposites.ToArray() End Function
Add the
HasConnector()
method to theGamePiece
class:Public Function HasConnector(direction As String) As Boolean Return _pieceType.Contains(direction) End Function
What just happened?
The GetOtherEnds()
method creates an empty List
object for holding the ends we want to return to the calling code. It then uses the Split()
method of the String
class to get each end listed in the _pieceType
. For example, the Top,Bottom
piece will return an array with two elements. The first element will contain Top
, and the second will contain Bottom
. The comma delimiter...