听起来你需要另一堂课Public Class Hand
......
它可以在内部包含一个卡片列表,但重点是它呈现的公共界面。操作卡片列表的方法(添加到手牌,从手牌中移除)和检查手牌“状态”的方法(可以返回已知状态的强类型枚举)。可能与此不同(我的 VB很生锈,所以这主要是伪代码):
Public Class Hand
Private cards As IList(Of card)
' A method to add a card to the hand, which should check if the hand can hold another card or not
' A method to remove a card from the hand, perhaps?
' Other methods representing actions that can be performed, such as folding the hand
Public Function GetHandStatus As HandStatus
If HandIsFlush() Then
Return HandStatus.Flush
Else If HandIsStraight() Then
Return HandStatus.Straight
End IF
End Function
Private Function HandIsFlush As Boolean
' loop through cards, return true if they are all the same suit
End Function
Private Function HandIsStraight As Boolean
' iterate through sorted-by-value cards, return false if more than 1 value separates any two
End Function
End Class
这样做是为了将此应用程序的业务逻辑的每个元素简化为一个单独的函数来处理该逻辑。如果类开始变大,您可以进一步重构它,也许HandStatus
从枚举变为抽象类,其中子类表示状态,并将逻辑移到那里。