公平的警告,我将为玩家 1 发布我的整个代码,只是因为我不确定需要什么才能继续。我迫切需要帮助。有 49 张牌,玩家 1 将得到 16 张牌。当我发牌时,有 16 张牌显示给用户。
我的问题是:我如何检查这 16 张牌的双倍,然后取出这些牌并将它们放入弃牌堆?
Public Class DeckOfCardsTest
Dim playercards As Integer = 16
Dim playermatches As Integer
Dim comp1cards As Integer = 16
Dim comp1matches As Integer
Dim comp2cards As Integer = 17
Dim comp2matches As Integer
Private deck As New DeckOfCards() ' create the deck of cards
Public Class DeckOfCards
Private Const NUMBER_OF_CARDS As Integer = 49 ' 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 ' DeckOfCards
如何让这个 List(Of Card) 在我的代码中工作?
Dim Cards As List(Of Card) 'Players hand
If Cards.Select(Function(x) x.Value).Distinct.Count < Cards.Count Then
'there are some duplicates in the list
Dim duplicates = Cards.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(g) g.Key).ToList
For Each i In duplicates
Debug.WriteLine("Card value " + i.ToString + " is a match")
Next
End If
以下是错误:
Error 1 Overload resolution failed because no accessible 'Select' can be called with these arguments: Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of Card, Integer, TResult)'.
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error. Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': 'Value' is not a member of 'DeckOfCardsTest.Card'. Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of Card, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Error 2 Data type(s) of the type parameter(s) in extension method 'Public Function GroupBy(Of TKey)(keySelector As System.Func(Of Card, TKey)) As System.Collections.Generic.IEnumerable(Of System.Linq.IGrouping(Of TKey, Card))' defined in 'System.Linq.Enumerable' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Error 3 'Value' is not a member of 'DeckOfCardsTest.Card'.
Error 4 Option Strict On disallows implicit conversions from 'Object' to 'System.Collections.Generic.IEnumerable(Of DeckOfCardsTest.Card)'.
Error 5 Option Strict On disallows late binding.