したがって、私のデザインは、ユーザーに「手」を表示するために、26 個の画像ボックス (コードは 10 個までしか表示されません) を持つことです。これらの画像ボックスでダブルスをチェックし、それらのダブルスをクリアされたパイルに削除するにはどうすればよいですか? たとえば、2 つのジャックと 3 つの 5 がある場合、2 つのジャックが削除され、2 つの 5 のみが削除されます。これを行う方法がわかりません。次のように、以下のコードでそれらを設定して名前を付けています。
Dim faces() As String = {"Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}
これが私のコードです。これは実際にはプレーヤー 1 用ですが、コンピューター プレーヤーもあります。
デッキオブカード
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