我正在做一个游戏,其中我需要计算机选择两张随机卡,出于某种原因,我总是得到一个“计算机点”匹配,随机卡片永远不会改变
Dim flipped As Boolean
Dim counter As Integer = 0
Dim rnd = New Random()
randomCard = cardList(rnd.Next(0, cardList.Count))
While counter < 2
'counter is 2 because the computer has to make two moves
flipped = randomCard.IsFlipped
If counter = 0 And flipped <> True Then
'First move
firstCard = randomCard
Dim nLabel As Integer = randomCard.PairType
counter += 1
ElseIf counter = 1 And flipped <> True Then
'Second move
secCard = randomCard
If firstCard.PairType = secCard.PairType And firstCard IsNot secCard Then
'If the two random cards are from the same type
MsgBox("Computer match. ONE POINT!")
cardList.Remove(firstCard)
cardList.Remove(secCard)
counter += 1
Else
MsgBox("Computer NO match!")
counter += 1
End If
End If
'Next random to keep loop going
rnd = New Random()
randomCard = cardList(rnd.Next(0, cardList.Count))
End While
答案 0 :(得分:1)
我无法测试您的代码,因为我没有您的卡片列表。但是请尝试取出 second “rnd = New Random()”。它可能是第二次使用相同的种子,导致重复。相反,只需调用rnd.Next即可获得下一个随机数。请参阅Random number generator only generating one random number。