主题:VB.NET 的發牌程序
各位大大好,最近小弟正在製作一個撲克遊戲,但是發牌程序有點問題,就是選過的牌會重複,下面是代碼,希望有任何高手能解答小弟的問題!!
=========================================
Dim card1 As Integer = -1
Dim card2 As Integer = -1
Dim card3 As Integer = -1
Dim card4 As Integer = -1
Dim card5 As Integer = -1
Dim card6 As Integer = -1
Dim card7 As Integer = -1
Dim card8 As Integer = -1
Dim card9 As Integer = -1
Dim card10 As Integer = -1
Dim card11 As Integer = -1
Dim card12 As Integer = -1
Dim card13 As Integer = -1
Dim com1 As Integer = -1
Dim com2 As Integer = -1
Dim com3 As Integer = -1
Dim com4 As Integer = -1
Dim com5 As Integer = -1
Dim com6 As Integer = -1
Dim com7 As Integer = -1
Dim com8 As Integer = -1
Dim com9 As Integer = -1
Dim com10 As Integer = -1
Dim com11 As Integer = -1
Dim com12 As Integer = -1
Dim com13 As Integer = -1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Shuffle and distribute cards
Randomize()
Do
card1 = CStr(Int(Rnd() * 52))
Loop While card1 = (card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card2 = CStr(Int(Rnd() * 52))
Loop While card2 = (card1 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card3 = CStr(Int(Rnd() * 52))
Loop While card3 = (card1 Or card2 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card4 = CStr(Int(Rnd() * 52))
Loop While card4 = (card1 Or card2 Or card3 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card5 = CStr(Int(Rnd() * 52))
Loop While card5 = (card1 Or card2 Or card3 Or card4 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card6 = CStr(Int(Rnd() * 52))
Loop While card6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card7 = CStr(Int(Rnd() * 52))
Loop While card6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card8 = CStr(Int(Rnd() * 52))
Loop While card8 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card9 = CStr(Int(Rnd() * 52))
Loop While card9 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card10 = CStr(Int(Rnd() * 52))
Loop While card10 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card11 = CStr(Int(Rnd() * 52))
Loop While card11 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card12 = CStr(Int(Rnd() * 52))
Loop While card12 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card13 = CStr(Int(Rnd() * 52))
Loop While card13 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com1 = CStr(Int(Rnd() * 52))
Loop While com1 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com2 = CStr(Int(Rnd() * 52))
Loop While com2 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com3 = CStr(Int(Rnd() * 52))
Loop While com3 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com4 = CStr(Int(Rnd() * 52))
Loop While com4 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com5 = CStr(Int(Rnd() * 52))
Loop While com5 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com6 = CStr(Int(Rnd() * 52))
Loop While com6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com7 = CStr(Int(Rnd() * 52))
Loop While com7 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com8 = CStr(Int(Rnd() * 52))
Loop While com8 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com9 = CStr(Int(Rnd() * 52))
Loop While com9 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com10 Or com11 Or com12 Or com13)
Do
com10 = CStr(Int(Rnd() * 52))
Loop While com10 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com11 Or com12 Or com13)
Do
com11 = CStr(Int(Rnd() * 52))
Loop While com11 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com12 Or com13)
Do
com12 = CStr(Int(Rnd() * 52))
Loop While com12 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com13)
Do
com13 = CStr(Int(Rnd() * 52))
Loop While com13 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12)
End Sub
===========================================
=========================================
Dim card1 As Integer = -1
Dim card2 As Integer = -1
Dim card3 As Integer = -1
Dim card4 As Integer = -1
Dim card5 As Integer = -1
Dim card6 As Integer = -1
Dim card7 As Integer = -1
Dim card8 As Integer = -1
Dim card9 As Integer = -1
Dim card10 As Integer = -1
Dim card11 As Integer = -1
Dim card12 As Integer = -1
Dim card13 As Integer = -1
Dim com1 As Integer = -1
Dim com2 As Integer = -1
Dim com3 As Integer = -1
Dim com4 As Integer = -1
Dim com5 As Integer = -1
Dim com6 As Integer = -1
Dim com7 As Integer = -1
Dim com8 As Integer = -1
Dim com9 As Integer = -1
Dim com10 As Integer = -1
Dim com11 As Integer = -1
Dim com12 As Integer = -1
Dim com13 As Integer = -1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Shuffle and distribute cards
Randomize()
Do
card1 = CStr(Int(Rnd() * 52))
Loop While card1 = (card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card2 = CStr(Int(Rnd() * 52))
Loop While card2 = (card1 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card3 = CStr(Int(Rnd() * 52))
Loop While card3 = (card1 Or card2 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card4 = CStr(Int(Rnd() * 52))
Loop While card4 = (card1 Or card2 Or card3 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card5 = CStr(Int(Rnd() * 52))
Loop While card5 = (card1 Or card2 Or card3 Or card4 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card6 = CStr(Int(Rnd() * 52))
Loop While card6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card7 = CStr(Int(Rnd() * 52))
Loop While card6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card8 = CStr(Int(Rnd() * 52))
Loop While card8 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card9 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card9 = CStr(Int(Rnd() * 52))
Loop While card9 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card10 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card10 = CStr(Int(Rnd() * 52))
Loop While card10 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card11 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card11 = CStr(Int(Rnd() * 52))
Loop While card11 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card12 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card12 = CStr(Int(Rnd() * 52))
Loop While card12 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card13 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
card13 = CStr(Int(Rnd() * 52))
Loop While card13 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or com1 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com1 = CStr(Int(Rnd() * 52))
Loop While com1 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com2 = CStr(Int(Rnd() * 52))
Loop While com2 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com3 = CStr(Int(Rnd() * 52))
Loop While com3 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com4 = CStr(Int(Rnd() * 52))
Loop While com4 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com5 = CStr(Int(Rnd() * 52))
Loop While com5 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com6 = CStr(Int(Rnd() * 52))
Loop While com6 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com7 = CStr(Int(Rnd() * 52))
Loop While com7 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com8 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com8 = CStr(Int(Rnd() * 52))
Loop While com8 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com9 Or com10 Or com11 Or com12 Or com13)
Do
com9 = CStr(Int(Rnd() * 52))
Loop While com9 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com10 Or com11 Or com12 Or com13)
Do
com10 = CStr(Int(Rnd() * 52))
Loop While com10 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com11 Or com12 Or com13)
Do
com11 = CStr(Int(Rnd() * 52))
Loop While com11 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com12 Or com13)
Do
com12 = CStr(Int(Rnd() * 52))
Loop While com12 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com13)
Do
com13 = CStr(Int(Rnd() * 52))
Loop While com13 = (card1 Or card2 Or card3 Or card4 Or card5 Or card6 Or card7 Or card8 Or card9 Or card10 Or card11 Or card12 Or card13 Or
com1 Or com2 Or com3 Or com4 Or com5 Or com6 Or com7 Or com8 Or com9 Or com10 Or com11 Or com12)
End Sub
===========================================