所以我的设计是有 26 个图片框(代码只显示到 10.. 你明白了)向用户展示他们的“手”。现在我如何检查那些图像框是否有双打,然后将这些双打移到清除的一堆?假设有 2 个 Jacks 和 3 个 Fives,那么 2 个 Jacks 被移除,只有 2 个 Fives 被移除。我不知道该怎么做。我在下面的代码中对它们进行了设置和命名,如下所示:
Dim faces() As String = {"Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
这是我的代码,这实际上只适用于玩家一,尽管也会有电脑玩家。
卡片组
Public Class DeckOfCards
Private Const NUMBER_OF_CARDS As Integer = 52 ' number of cards
Private deck(NUMBER_OF_CARDS - 1) As Card ' array of Card objects
Private currentCard As Integer ' index of next Card to be dealt
Private Shared randomNumbers As New Random() ' random number generator
' constructor fills deck of Cards
Public Sub New()
Dim faces() As String = {"Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
Dim suits() As String = {"Hearts", "Diamonds", "Clubs", "Spades"}
currentCard = 0 ' set currentCard so first Card dealt is deck(0)
' populate deck array with Card objects
For count = 0 To deck.GetUpperBound(0)
deck(count) = New Card(faces(count Mod 13), suits(count \ 13))
Next
End Sub ' New
' shuffle deck of Cards with simple one-pass algorithm
Public Sub Shuffle()
' after shuffling, dealing should start at deck(0) again
currentCard = 0 ' reinitialize currentCard
' for each Card, pick another random Card and swap them
For first = 0 To deck.GetUpperBound(0)
' select a random number between 0 and 51
Dim second As Integer = randomNumbers.Next(NUMBER_OF_CARDS)
' swap current Card with randomly selected Card
Dim temp As Card = deck(first) ' store copy of deck(first)
deck(first) = deck(second) ' move deck(second) to deck(first)
deck(second) = temp ' move original deck(first) to deck(second)
Next
End Sub ' Shuffle
' deal one Card
Public Function DealCard() As Card
' determine whether Cards remain to be dealt
If currentCard <= deck.GetUpperBound(0) Then
Dim lastCard As Integer = currentCard ' store current card number
currentCard += 1 ' increment current card number
Return deck(lastCard)
Else
Return Nothing ' no more cards to deal
End If
End Function ' DealCard
End Class